lufi/themes/default/public/js/worker/cancel.js

2 lines
43 KiB
JavaScript

var Xe=Object.create;var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&se(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var ae=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?se(r,"default",{value:e,enumerable:!0}):r,e));var we=ce((Mt,Q)=>{"use strict";var M=typeof Reflect=="object"?Reflect:null,fe=M&&typeof M.apply=="function"?M.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;M&&typeof M.ownKeys=="function"?q=M.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function Ye(e){console&&console.warn&&console.warn(e)}var he=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Q.exports=p;Q.exports.once=et;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var ue=10;function H(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return ue},set:function(e){if(typeof e!="number"||e<0||he(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ue=e}});p.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};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||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};function le(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return le(this)};p.prototype.emit=function(t){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var o=t==="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[t];if(f===void 0)return!1;if(typeof f=="function")fe(f,this,r);else for(var u=f.length,l=ge(f,u),n=0;n<u;++n)fe(l[n],this,r);return!0};function de(e,t,r,n){var o,i,s;if(H(r),i=e._events,i===void 0?(i=e._events=Object.create(null),e._eventsCount=0):(i.newListener!==void 0&&(e.emit("newListener",t,r.listener?r.listener:r),i=e._events),s=i[t]),s===void 0)s=i[t]=r,++e._eventsCount;else if(typeof s=="function"?s=i[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),o=le(e),o>0&&s.length>o&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,Ye(a)}return e}p.prototype.addListener=function(t,r){return de(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return de(this,t,r,!0)};function Ve(){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 pe(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ve.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,pe(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,pe(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,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():Ze(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){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[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),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[t],typeof r=="function")this.removeListener(t,r);else if(r!==void 0)for(o=r.length-1;o>=0;o--)this.removeListener(t,r[o]);return this};function me(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Qe(o):ge(o,o.length)}p.prototype.listeners=function(t){return me(this,t,!0)};p.prototype.rawListeners=function(t){return me(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ye.call(e,t)};p.prototype.listenerCount=ye;function ye(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}p.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function ge(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Ze(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Qe(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function et(e,t){return new Promise(function(r,n){function o(s){e.removeListener(t,i),n(s)}function i(){typeof e.removeListener=="function"&&e.removeListener("error",o),r([].slice.call(arguments))}ve(e,t,i,{once:!0}),t!=="error"&&tt(e,o,{once:!0})})}function tt(e,t,r){typeof e.on=="function"&&ve(e,"error",t,r)}function ve(e,t,r,n){if(typeof e.on=="function")n.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,function o(i){n.once&&e.removeEventListener(t,o),r(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}});var Pe=ce((vr,j)=>{"use strict";var c={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?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(e){return Se(this,e,0)},decrypt:function(e){return Se(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,d;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Se(e,t,r){if(t.length!==4)throw new c.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var a,f,u,l=n.length/4-2,h,d=4,y=[0,0,0,0];a=e.s[r],e=a[0];var g=a[1],P=a[2],$=a[3],K=a[4];for(h=0;h<l;h++)a=e[o>>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[i>>8&255]^$[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)y[r?3&-h:h]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[t&255]^n[d++],a=o,o=i,i=s,s=t,t=a;return y}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<<r)-1},concat:function(e,t){if(e.length===0||t.length===0)return e.concat(t);var r=e[e.length-1],n=c.bitArray.getPartial(r);return n===32?e.concat(t):c.bitArray.$(t,n,r|0,e.slice(0,e.length-1))},bitLength:function(e){var t=e.length;return t===0?0:32*(t-1)+c.bitArray.getPartial(e[t-1])},clamp:function(e,t){if(32*e.length<t)return e;e=e.slice(0,Math.ceil(t/32));var r=e.length;return t=t&31,0<r&&t&&(e[r-1]=c.bitArray.partial(t,e[r-1]&2147483648>>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(c.bitArray.bitLength(e)!==c.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n<e.length;n++)r|=e[n]^t[n];return r===0},$:function(e,t,r,n){var o;for(o=0,n===void 0&&(n=[]);32<=t;t-=32)n.push(r),r=0;if(t===0)return n.concat(e);for(o=0;o<e.length;o++)n.push(r|e[o]>>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32<t+e?r:n.pop(),1)),n},i:function(e,t){return[e[0]^t[0],e[1]^t[1],e[2]^t[2],e[3]^t[3]]},byteswapM:function(e){var t,r;for(t=0;t<e.length;++t)r=e[t],e[t]=r>>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.bitArray.bitLength(e),n,o;for(n=0;n<r/8;n++)!(n&3)&&(o=e[n/4]),t+=String.fromCharCode(o>>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r<e.length;r++)n=n<<8|e.charCodeAt(r),(r&3)===3&&(t.push(n),n=0);return r&3&&t.push(c.bitArray.partial(8*(r&3),n)),t}};c.codec.hex={fromBits:function(e){var t="",r;for(r=0;r<e.length;r++)t+=((e[r]|0)+0xf00000000000).toString(16).substr(4);return t.substr(0,c.bitArray.bitLength(e)/4)},toBits:function(e){var t,r=[],n;for(e=e.replace(/\s|0x/g,""),n=e.length,e=e+"00000000",t=0;t<e.length;t+=8)r.push(parseInt(e.substr(t,8),16)^0);return c.bitArray.clamp(r,4*n)}};c.codec.base32={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",X:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(e,t,r){var n=c.codec.base32.BASE,o=c.codec.base32.REMAINING,i="",s=0,a=c.codec.base32.B,f=0,u=c.bitArray.bitLength(e);for(r&&(a=c.codec.base32.X),r=0;i.length*n<u;)i+=a.charAt((f^e[r]>>>s)>>>o),s<n?(f=e[r]<<n-s,s+=o,r++):(f<<=n,s-=n);for(;i.length&7&&!t;)i+="=";return i},toBits:function(e,t){e=e.replace(/\s|=/g,"").toUpperCase();var r=c.codec.base32.BITS,n=c.codec.base32.BASE,o=c.codec.base32.REMAINING,i=[],s,a=0,f=c.codec.base32.B,u=0,l,h="base32";for(t&&(f=c.codec.base32.X,h="base32hex"),s=0;s<e.length;s++){if(l=f.indexOf(e.charAt(s)),0>l){if(!t)try{return c.codec.base32hex.toBits(e)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<<r-a):(a+=n,u^=l<<r-a)}return a&56&&i.push(c.bitArray.partial(a&56,u,1)),i}};c.codec.base32hex={fromBits:function(e,t){return c.codec.base32.fromBits(e,t,1)},toBits:function(e){return c.codec.base32.toBits(e,1)}};c.codec.base64={B:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(e,t,r){var n="",o=0,i=c.codec.base64.B,s=0,a=c.bitArray.bitLength(e);for(r&&(i=i.substr(0,62)+"-_"),r=0;6*n.length<a;)n+=i.charAt((s^e[r]>>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.B,s=0,a;for(t&&(i=i.substr(0,62)+"-_"),n=0;n<e.length;n++){if(a=i.indexOf(e.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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.bitArray.bitLength(e),9007199254740991<e)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(t=512+t-(512+t&511);t<=e;t+=512)re(this,n.subarray(16*o,16*(o+1))),o+=1;r.splice(0,16*o)}else for(t=512+t-(512+t&511);t<=e;t+=512)re(this,r.splice(0,16));return this},finalize:function(){var e,r=this.A,t=this.F,r=c.bitArray.concat(r,[c.bitArray.partial(1,1)]);for(e=r.length+2;e&15;e++)r.push(0);for(r.push(Math.floor(this.l/4294967296)),r.push(this.l|0);r.length;)re(this,r.splice(0,16));return this.reset(),t},Y:[],b:[],O:function(){function e(i){return 4294967296*(i-Math.floor(i))|0}for(var t=0,r=2,n,o;64>t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function re(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],y=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(d^y))+s[r],g=y,y=d,d=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+y|0,i[7]=i[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-1<e&&c.mode.ccm.G.splice(e,1)},fa:function(e){var t=c.mode.ccm.G.slice(),r;for(r=0;r<t.length;r+=1)t[r](e)},encrypt:function(e,t,r,n,o){var i,s=t.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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;t<s.length;t+=4)n=e.encrypt(f(n,s.slice(t,t+4).concat([0,0,0])));return n},V:function(e,t,r,n,o,i){var s=c.bitArray,a=s.i;if(o/=8,o%2||4>o||16<o)throw new c.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<t.length)throw new c.exception.bug("ccm: can't deal with 4GiB or more data");for(r=c.mode.ccm.na(e,n,r,o,s.bitLength(t)/8,i),n=0;n<t.length;n+=4)r=e.encrypt(a(r,t.slice(n,n+4).concat([0,0,0])));return s.clamp(r,8*o)},C:function(e,t,r,n,o,i){var s,a=c.bitArray;s=a.i;var f=t.length,u=a.bitLength(t),l=f/50,h=l;if(r=a.concat([a.partial(8,i-1)],r).concat([0,0,0]).slice(0,4),n=a.bitSlice(s(n,e.encrypt(r)),0,o),!f)return{tag:n,data:[]};for(s=0;s<f;s+=4)s>l&&(c.mode.ccm.fa(s/f),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(e.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4<t.length;s+=4)h=t.slice(s,s+4),l=u(l,h),d=d.concat(u(r,e.encrypt(u(r,h)))),r=a(r);return h=t.slice(s),t=f.bitLength(h),s=e.encrypt(u(r,[0,0,0,t])),h=f.clamp(u(h.concat([0,0,0]),s),t),l=u(l,u(h.concat([0,0,0]),s)),l=e.encrypt(u(l,u(r,a(r)))),n.length&&(l=u(l,i?n:c.mode.ocb2.pmac(e,n))),d.concat(f.concat(h,f.clamp(l,o)))},decrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");o=o||64;var s=c.mode.ocb2.S,a=c.bitArray,f=a.i,u=[0,0,0,0],l=s(e.encrypt(r)),h,d,y=c.bitArray.bitLength(t)-o,g=[];for(n=n||[],r=0;r+4<y/32;r+=4)h=f(l,e.decrypt(f(l,t.slice(r,r+4)))),u=f(u,h),g=g.concat(h),l=s(l);if(d=y-32*r,h=e.encrypt(f(l,[0,0,0,d])),h=f(h,a.clamp(t.slice(r),d).concat([0,0,0])),u=f(u,h),u=e.encrypt(f(u,f(l,s(l)))),n.length&&(u=f(u,i?n:c.mode.ocb2.pmac(e,n))),!a.equal(a.clamp(u,o),a.bitSlice(t,y)))throw new c.exception.corrupt("ocb: tag doesn't match");return g.concat(a.clamp(h,d))},pmac:function(e,t){var r,n=c.mode.ocb2.S,o=c.bitArray,i=o.i,s=[0,0,0,0],a=e.encrypt([0,0,0,0]),a=i(a,n(n(a)));for(r=0;r+4<t.length;r+=4)a=n(a),s=i(s,e.encrypt(i(a,t.slice(r,r+4))));return r=t.slice(r),128>o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0<n;n--)i[n]=i[n]>>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;n<o;n+=4)t[0]^=4294967295&r[n],t[1]^=4294967295&r[n+1],t[2]^=4294967295&r[n+2],t[3]^=4294967295&r[n+3],t=c.mode.gcm.ka(t,e);return t},C:function(e,t,r,n,o,i){var s,a,f,u,l,h,d,y,g=c.bitArray;for(h=r.length,d=g.bitLength(r),y=g.bitLength(n),a=g.bitLength(o),s=t.encrypt([0,0,0,0]),a===96?(o=o.slice(0),o=g.concat(o,[1])):(o=c.mode.gcm.j(s,[0,0,0,0],o),o=c.mode.gcm.j(s,o,[0,0,Math.floor(a/4294967296),a&4294967295])),a=c.mode.gcm.j(s,[0,0,0,0],n),l=o.slice(0),n=a.slice(0),e||(n=c.mode.gcm.j(s,a,r)),u=0;u<h;u+=4)l[3]++,f=t.encrypt(l),r[u]^=f[0],r[u+1]^=f[1],r[u+2]^=f[2],r[u+3]^=f[3];return r=g.clamp(r,d),e&&(n=c.mode.gcm.j(s,a,r)),e=[Math.floor(y/4294967296),y&4294967295,Math.floor(d/4294967296),d&4294967295],n=c.mode.gcm.j(s,n,e),f=t.encrypt(o),n[0]^=f[0],n[1]^=f[1],n[2]^=f[2],n[3]^=f[3],{tag:g.bitSlice(n,0,i),data:r}}};c.misc.hmac=function(e,t){this.W=t=t||c.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.w=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;n<o;n++)r[0][n]=e[n]^909522486,r[1][n]=e[n]^1549556828;this.w[0].update(r[0]),this.w[1].update(r[1]),this.R=new t(this.w[0])};c.misc.hmac.prototype.encrypt=c.misc.hmac.prototype.mac=function(e){if(this.aa)throw new c.exception.invalid("encrypt on already updated hmac called!");return this.update(e),this.digest(e)};c.misc.hmac.prototype.reset=function(){this.R=new this.W(this.w[0]),this.aa=!1};c.misc.hmac.prototype.update=function(e){this.aa=!0,this.R.update(e)};c.misc.hmac.prototype.digest=function(){var e=this.R.finalize(),e=new this.W(this.w[1]).update(e).finalize();return this.reset(),e};c.misc.pbkdf2=function(e,t,r,n,o){if(r=r||1e4,0>n||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[f])),s=1;s<r;s++)for(i=e.encrypt(i),a=0;a<i.length;a++)o[a]^=i[a];u=u.concat(o)}return n&&(u=l.clamp(u,n)),u};c.prng=function(e){this.c=[new c.hash.sha256],this.m=[0],this.P=0,this.H={},this.N=0,this.U={},this.Z=this.f=this.o=this.ha=0,this.b=[0,0,0,0,0,0,0,0],this.h=[0,0,0,0],this.L=void 0,this.M=e,this.D=!1,this.K={progress:{},seeded:{}},this.u=this.ga=0,this.I=1,this.J=2,this.ca=65536,this.T=[0,48,64,96,128,192,256,384,512,768,1024],this.da=3e4,this.ba=80};c.prng.prototype={randomWords:function(e,t){var r=[],n;n=this.isReady(t);var o;if(n===this.u)throw new c.exception.notReady("generator isn't seeded");if(n&this.J){n=!(n&this.I),o=[];var i=0,s;for(this.Z=o[0]=new Date().valueOf()+this.da,s=0;16>s;s++)o.push(4294967296*Math.random()|0);for(s=0;s<this.c.length&&(o=o.concat(this.c[s].finalize()),i+=this.m[s],this.m[s]=0,n||!(this.P&1<<s));s++);for(this.P>=1<<this.c.length&&(this.c.push(new c.hash.sha256),this.m.push(0)),this.f-=i,i>this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n<e;n+=4)(n+1)%this.ca===0&&Re(this),o=ne(this),r.push(o[0],o[1],o[2],o[3]);return Re(this),r.slice(0,e)},setDefaultParanoia:function(e,t){if(e===0&&t!=="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.M=e},addEntropy:function(e,t,r){r=r||"user";var n,o,i=new Date().valueOf(),s=this.H[r],a=this.isReady(),f=0;switch(n=this.U[r],n===void 0&&(n=this.U[r]=this.ha++),s===void 0&&(s=this.H[r]=0),this.H[r]=(this.H[r]+1)%this.c.length,typeof e){case"number":t===void 0&&(t=1),this.c[s].update([n,this.N++,1,t,i,1,e|0]);break;case"object":if(r=Object.prototype.toString.call(e),r==="[object Uint32Array]"){for(o=[],r=0;r<e.length;r++)o.push(e[r]);e=o}else for(r!=="[object Array]"&&(f=1),r=0;r<e.length&&!f;r++)typeof e[r]!="number"&&(f=1);if(!f){if(t===void 0)for(r=t=0;r<e.length;r++)for(o=e[r];0<o;)t++,o=o>>>1;this.c[s].update([n,this.N++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Ce("seeded",Math.max(this.o,this.f)),Ce("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(this,this.qa)},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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;r<i.length;r++)n=i[r],delete o[n]},la:function(){F(this,1)},oa:function(e){var t,r;try{t=e.x||e.clientX||e.offsetX||0,r=e.y||e.clientY||e.offsetY||0}catch{r=t=0}t!=0&&r!=0&&this.addEntropy([t,r],2,"mouse"),F(this,0)},qa:function(e){e=e.touches[0]||e.changedTouches[0],this.addEntropy([e.pageX||e.clientX,e.pageY||e.clientY],1,"touch"),F(this,0)},ma:function(){F(this,2)},ea:function(e){if(e=e.accelerationIncludingGravity.x||e.accelerationIncludingGravity.y||e.accelerationIncludingGravity.z,window.orientation){var t=window.orientation;typeof t=="number"&&this.addEntropy(t,1,"accelerometer")}e&&this.addEntropy(e,2,"accelerometer"),F(this,0)}};function Ce(e,t){var r,n=c.random.K[e],o=[];for(r in n)n.hasOwnProperty(r)&&o.push(n[r]);for(r=0;r<o.length;r++)o[r](t)}function F(e,t){typeof window<"u"&&window.performance&&typeof window.performance.now=="function"?e.addEntropy(window.performance.now(),t,"loadtime"):e.addEntropy(new Date().valueOf(),t,"loadtime")}function Re(e){e.b=ne(e).concat(ne(e)),e.L=new c.cipher.aes(e.b)}function ne(e){for(var t=0;4>t&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(V=typeof j<"u"&&j.exports){try{Z=qe("crypto")}catch{Z=null}V=Y=Z}if(V&&Y.randomBytes)z=Y.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var z,Y,G,V,Z;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 e=="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 e=="string"?(s=c.misc.cachedPbkdf2(e,i),e=s.key.slice(0,i.ks/32),i.salt=s.salt):c.ecc&&e instanceof c.ecc.elGamal.publicKey&&(s=e.kem(),i.kemtag=s.tag,e=s.key.slice(0,i.ks/32)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof r=="string"&&(i.adata=r=c.codec.utf8String.toBits(r)),s=new c.cipher[i.cipher](e),o.g(n,i),n.key=e,i.ct=i.mode==="ccm"&&c.arrayBuffer&&c.arrayBuffer.ccm&&t instanceof ArrayBuffer?c.arrayBuffer.ccm.encrypt(s,t,i.iv,r,i.ts):c.mode[i.mode].encrypt(s,t,i.iv,r,i.ts),i},encrypt:function(e,t,r,n){var o=c.json,i=o.ja.apply(o,arguments);return o.encode(i)},ia:function(e,t,r,n){r=r||{},n=n||{};var o=c.json;t=o.g(o.g(o.g({},o.defaults),t),r,!0);var i,s;if(i=t.adata,typeof t.salt=="string"&&(t.salt=c.codec.base64.toBits(t.salt)),typeof t.iv=="string"&&(t.iv=c.codec.base64.toBits(t.iv)),!c.mode[t.mode]||!c.cipher[t.cipher]||typeof e=="string"&&100>=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4<t.iv.length)throw new c.exception.invalid("json decrypt: invalid parameters");return typeof e=="string"?(s=c.misc.cachedPbkdf2(e,t),e=s.key.slice(0,t.ks/32),t.salt=s.salt):c.ecc&&e instanceof c.ecc.elGamal.secretKey&&(e=e.unkem(c.codec.base64.toBits(t.kemtag)).slice(0,t.ks/32)),typeof i=="string"&&(i=c.codec.utf8String.toBits(i)),s=new c.cipher[t.cipher](e),i=t.mode==="ccm"&&c.arrayBuffer&&c.arrayBuffer.ccm&&t.ct instanceof ArrayBuffer?c.arrayBuffer.ccm.decrypt(s,t.ct,t.iv,t.tag,i,t.ts):c.mode[t.mode].decrypt(s,t.ct,t.iv,i,t.ts),o.g(n,t),n.key=e,r.raw===1?i:c.codec.utf8String.fromBits(i)},decrypt:function(e,t,r,n){var o=c.json;return o.ia(e,o.decode(t),r,n)},encode:function(e){var t,r="{",n="";for(t in e)if(e.hasOwnProperty(t)){if(!t.match(/^[a-z0-9]+$/i))throw new c.exception.invalid("json encode: invalid property name");switch(r+=n+'"'+t+'":',n=",",typeof e[t]){case"number":case"boolean":r+=e[t];break;case"string":r+='"'+escape(e[t])+'"';break;case"object":r+='"'+c.codec.base64.fromBits(e[t],0)+'"';break;default:throw new c.exception.bug("json encode: unsupported type")}}return r+"}"},decode:function(e){if(e=e.replace(/\s/g,""),!e.match(/^\{.*\}$/))throw new c.exception.invalid("json decode: this isn't json!");e=e.replace(/^\{|\}$/g,"").split(/,/);var t={},r,n;for(r=0;r<e.length;r++){if(!(n=e[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?t[n[2]]=parseInt(n[3],10):n[4]!=null?t[n[2]]=n[2].match(/^(ct|adata|salt|iv)$/)?c.codec.base64.toBits(n[4]):unescape(n[4]):n[5]!=null&&(t[n[2]]=n[5]==="true")}return t},g:function(e,t,r){if(e===void 0&&(e={}),t===void 0)return e;for(var n in t)if(t.hasOwnProperty(n)){if(r&&e[n]!==void 0&&e[n]!==t[n])throw new c.exception.invalid("required parameter overridden");e[n]=t[n]}return e},sa:function(e,t){var r={},n;for(n in e)e.hasOwnProperty(n)&&e[n]!==t[n]&&(r[n]=e[n]);return r},ra:function(e,t){var r={},n;for(n=0;n<t.length;n++)e[t[n]]!==void 0&&(r[t[n]]=e[t[n]]);return r}};c.encrypt=c.json.encrypt;c.decrypt=c.json.decrypt;c.misc.pa={};c.misc.cachedPbkdf2=function(e,t){var r=c.misc.pa,n;return t=t||{},n=t.iter||1e3,r=r[e]=r[e]||{},n=r[n]=r[n]||{firstSalt:t.salt&&t.salt.length?t.salt.slice(0):c.random.randomWords(2,0)},r=t.salt===void 0?n.firstSalt:t.salt,n[r]=n[r]||c.misc.pbkdf2(e,r,t.iter),{key:n[r].slice(0),salt:r.slice(0)}};typeof j<"u"&&j.exports&&(j.exports=c);typeof define=="function"&&define([],function(){return c})});var ke=ae(we());var rt={withStackTrace:!1},Ae=(e,t,r=rt)=>{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function T(e,t,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(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(e,[])).next())})}function Ee(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function C(e){return this instanceof C?(this.v=e,this):new C(e)}function nt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(y){return new Promise(function(g,P){i.push([d,y,g,P])>1||a(d,y)})})}function a(d,y){try{f(n[d](y))}catch(g){h(i[0][3],g)}}function f(d){d.value instanceof C?Promise.resolve(d.value.v).then(u,l):h(i[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,y){d(y),i.shift(),i.length&&a(i[0][0],i[0][1])}}function ot(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function it(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ee=="function"?Ee(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(a,f){s=e[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 v=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new O(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(T(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new O(r?r(o):o)}}))}static combine(t){return st(t)}static combineWithAllErrors(t){return ct(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);let n=yield t(r.value);return n.isErr()?new O(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return nt(this,arguments,function*(){return yield C(yield C(yield*ot(it(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Nt=v.fromPromise,Ut=v.fromSafePromise,jt=v.fromThrowable,Le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},st=e=>v.fromSafePromise(Promise.all(e)).andThen(Le),Oe=e=>{let t=S([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=k([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},ct=e=>v.fromSafePromise(Promise.all(e)).andThen(Oe),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return Le(o)}e.combine=r;function n(o){return Oe(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function k(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ae("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return k(this.error)}mapErr(t){return k(t(this.error))}andThrough(t){return k(this.error)}andTee(t){return k(this.error)}andThen(t){return k(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return E(this.error)}asyncAndThrough(t){return E(this.error)}asyncMap(t){return E(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ae("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Bt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var R=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var at=()=>typeof Deno<"u",I=e=>at()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var m=new ke.default,w,xe=!1;self.onmessage=e=>{ut(e),xe||(xe=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(I("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(I("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(I("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(I("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(I("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},De=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var U=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),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(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,a,f=0,u=0;for(;f<t.length*.75;)o=this._charset.indexOf(t.charAt(u++)),i=this._charset.indexOf(t.charAt(u++)),s=this._charset.indexOf(t.charAt(u++)),a=this._charset.indexOf(t.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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function J(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function te(e){return lt.Decode(e)}var Te=ae(Pe());var _=class extends D{};var B=class extends _{message="Unable to decrypt the provided data"};var Ie=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(J(Te.default.decrypt(e,r)))}catch(r){return E(new B(void 0,{cause:R(r)}))}};var Ne=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,J(t.data)),n=>new B(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",te(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var Ue=(e,t)=>t.algo===void 0||t.algo===0?Ie(e,t):Ne(e,t);var A={},je=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(_t(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Ue(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=Dt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,oe=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,Be=e=>ie(kt(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ie(bt(e),e,JSON.stringify(t))};var ie=(e,t,r)=>oe(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):We(e).andThen(()=>ie(e,t,r)),We=(e,t=0)=>(!oe(e)&&!Lt(e)&&(A[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{m.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=je?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${je}`),We(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{oe(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var Je=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},bt=e=>Je(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),kt=e=>Je(new URL(e.serverUrl),"upload").toString(),Dt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},_t=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Fe=!1;self.onmessage=e=>{Fe||(De(),Fe=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),Ct(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Ct=e=>Be(e.args.lufiFile);