2 lines
44 KiB
JavaScript
2 lines
44 KiB
JavaScript
var Et=Object.create;var De=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Dt=(e,t,r)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var bt=(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 Ue=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var kt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!xt.call(e,o)&&o!==r&&De(e,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return e};var Ie=(e,t,r)=>(r=e!=null?Et(Ot(e)):{},kt(t||!e||!e.__esModule?De(r,"default",{value:e,enumerable:!0}):r,e));var T=(e,t,r)=>Dt(e,typeof t!="symbol"?t+"":t,r);var $e=Ue((lr,be)=>{"use strict";var G=typeof Reflect=="object"?Reflect:null,je=G&&typeof G.apply=="function"?G.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ye;G&&typeof G.ownKeys=="function"?ye=G.ownKeys:Object.getOwnPropertySymbols?ye=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ye=function(t){return Object.getOwnPropertyNames(t)};function _t(e){console&&console.warn&&console.warn(e)}var Be=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}be.exports=p;be.exports.once=Pt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var Ne=10;function ve(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 Ne},set:function(e){if(typeof e!="number"||e<0||Be(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ne=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||Be(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 We(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return We(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 c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")je(u,this,r);else for(var f=u.length,h=Xe(u,f),n=0;n<f;++n)je(h[n],this,r);return!0};function Fe(e,t,r,n){var o,i,s;if(ve(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=We(e),o>0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,_t(c)}return e}p.prototype.addListener=function(t,r){return Fe(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return Fe(this,t,r,!0)};function St(){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 Je(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=St.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return ve(r),this.on(t,Je(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return ve(r),this.prependListener(t,Je(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,c;if(ve(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){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ct(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||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 ze(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?Rt(o):Xe(o,o.length)}p.prototype.listeners=function(t){return ze(this,t,!0)};p.prototype.rawListeners=function(t){return ze(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):He.call(e,t)};p.prototype.listenerCount=He;function He(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?ye(this._events):[]};function Xe(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function Ct(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Rt(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function Pt(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))}Ge(e,t,i,{once:!0}),t!=="error"&&Mt(e,o,{once:!0})})}function Mt(e,t,r){typeof e.on=="function"&&Ge(e,"error",t,r)}function Ge(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 at=Ue((tn,q)=>{"use strict";var a={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}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.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^c<<24,c=c<<1^283*(c>>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]]};a.cipher.aes.prototype={encrypt:function(e){return ot(this,e,0)},decrypt:function(e){return ot(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,h,l,y;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[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=c[o=c[f=c[i]]],y=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)e[o][i]=h=h<<24^h>>>8,t[o][l]=y=y<<24^y>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function ot(e,t,r){if(t.length!==4)throw new a.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 c,u,f,h=n.length/4-2,l,y=4,d=[0,0,0,0];c=e.w[r],e=c[0];var g=c[1],k=c[2],C=c[3],N=c[4];for(l=0;l<h;l++)c=e[o>>>24]^g[i>>16&255]^k[s>>8&255]^C[t&255]^n[y],u=e[i>>>24]^g[s>>16&255]^k[t>>8&255]^C[o&255]^n[y+1],f=e[s>>>24]^g[t>>16&255]^k[o>>8&255]^C[i&255]^n[y+2],t=e[t>>>24]^g[o>>16&255]^k[i>>8&255]^C[s&255]^n[y+3],y+=4,o=c,i=u,s=f;for(l=0;4>l;l++)d[r?3&-l:l]=N[o>>>24]<<24^N[i>>16&255]<<16^N[s>>8&255]<<8^N[t&255]^n[y++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.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=a.bitArray.getPartial(r);return n===32?e.concat(t):a.bitArray.Y(t,n,r|0,e.slice(0,e.length-1))},bitLength:function(e){var t=e.length;return t===0?0:32*(t-1)+a.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]=a.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(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n<e.length;n++)r|=e[n]^t[n];return r===0},Y: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=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32<t+e?r:n.pop(),1)),n},P: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}};a.codec.utf8String={fromBits:function(e){var t="",r=a.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(a.bitArray.partial(8*(r&3),n)),t}};a.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,a.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 a.bitArray.clamp(r,4*n)}};a.codec.base64={S:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(e,t,r){var n="",o=0,i=a.codec.base64.S,s=0,c=a.bitArray.bitLength(e);for(r&&(i=i.substr(0,62)+"-_"),r=0;6*n.length<c;)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=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;n<e.length;n++){if(c=i.indexOf(e.charAt(n)),0>c)throw new a.exception.invalid("this isn't base64!");26<o?(o-=26,r.push(s^c>>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991<e)throw new a.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)this.l(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)this.l(r.splice(0,16));return this},finalize:function(){var e,r=this.f,t=this.g,r=a.bitArray.concat(r,[a.bitArray.partial(1,1)]);for(e=r.length+2;e&15;e++)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(),t},o:[],b:[],C: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.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],y=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(l^y))+i[t],d=y,y=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+y|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991<e)throw new a.exception.invalid("Cannot hash more than 2^53 - 1 bits");if(typeof Uint32Array<"u"){var n=new Uint32Array(r),o=0;for(t=1024+t-(1024+t&1023);t<=e;t+=1024)this.l(n.subarray(32*o,32*(o+1))),o+=1;r.splice(0,32*o)}else for(t=1024+t-(1024+t&1023);t<=e;t+=1024)this.l(r.splice(0,32));return this},finalize:function(){var e,r=this.f,t=this.g,r=a.bitArray.concat(r,[a.bitArray.partial(1,1)]);for(e=r.length+4;e&31;e++)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(),t},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 e(s){return 4294967296*(s-Math.floor(s))|0}function t(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]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],y=n[7],d=n[8],g=n[9],k=n[10],C=n[11],N=n[12],le=n[13],Pe=n[14],de=n[15],L;if(typeof Uint32Array<"u"){L=Array(160);for(var E=0;32>E;E++)L[E]=e[E]}else L=e;var E=i,x=s,Z=c,H=u,ee=f,X=h,Ae=l,te=y,R=d,D=g,pe=k,re=C,me=N,ne=le,Le=Pe,oe=de;for(e=0;80>e;e++){if(16>e)t=L[2*e],r=L[2*e+1];else{r=L[2*(e-15)];var v=L[2*(e-15)+1];t=(v<<31|r>>>1)^(v<<24|r>>>8)^r>>>7;var P=(r<<31|v>>>1)^(r<<24|v>>>8)^(r<<25|v>>>7);r=L[2*(e-2)];var M=L[2*(e-2)+1],v=(M<<13|r>>>19)^(r<<3|M>>>29)^r>>>6,M=(r<<13|M>>>19)^(M<<3|r>>>29)^(r<<26|M>>>6),Oe=L[2*(e-7)],xe=L[2*(e-16)],ie=L[2*(e-16)+1];r=P+L[2*(e-7)+1],t=t+Oe+(r>>>0<P>>>0?1:0),r+=M,t+=v+(r>>>0<M>>>0?1:0),r+=ie,t+=xe+(r>>>0<ie>>>0?1:0)}L[2*e]=t|=0,L[2*e+1]=r|=0;var Oe=R&pe^~R&me,Me=D&re^~D&ne,M=E&Z^E&ee^Z&ee,gt=x&H^x&X^H&X,xe=(x<<4|E>>>28)^(E<<30|x>>>2)^(E<<25|x>>>7),ie=(E<<4|x>>>28)^(x<<30|E>>>2)^(x<<25|E>>>7),wt=o[2*e],Te=o[2*e+1],v=oe+((R<<18|D>>>14)^(R<<14|D>>>18)^(D<<23|R>>>9)),P=Le+((D<<18|R>>>14)^(D<<14|R>>>18)^(R<<23|D>>>9))+(v>>>0<oe>>>0?1:0),v=v+Me,P=P+(Oe+(v>>>0<Me>>>0?1:0)),v=v+Te,P=P+(wt+(v>>>0<Te>>>0?1:0)),v=v+r|0,P=P+(t+(v>>>0<r>>>0?1:0));r=ie+gt,t=xe+M+(r>>>0<ie>>>0?1:0),Le=me,oe=ne,me=pe,ne=re,pe=R,re=D,D=te+v|0,R=Ae+P+(D>>>0<te>>>0?1:0)|0,Ae=ee,te=X,ee=Z,X=H,Z=E,H=x,x=v+r|0,E=P+t+(x>>>0<v>>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+E+(s>>>0<x>>>0?1:0)|0,u=n[3]=u+H|0,n[2]=c+Z+(u>>>0<H>>>0?1:0)|0,h=n[5]=h+X|0,n[4]=f+ee+(h>>>0<X>>>0?1:0)|0,y=n[7]=y+te|0,n[6]=l+Ae+(y>>>0<te>>>0?1:0)|0,g=n[9]=g+D|0,n[8]=d+R+(g>>>0<D>>>0?1:0)|0,C=n[11]=C+re|0,n[10]=k+pe+(C>>>0<re>>>0?1:0)|0,le=n[13]=le+ne|0,n[12]=N+me+(le>>>0<ne>>>0?1:0)|0,de=n[15]=de+oe|0,n[14]=Pe+Le+(de>>>0<oe>>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1<e&&a.mode.ccm.F.splice(e,1)},da:function(e){var t=a.mode.ccm.F.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),c=a.bitArray,u=c.bitLength(r)/8,f=c.bitLength(s)/8;if(o=o||64,n=n||[],7>u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;t<s.length;t+=4)n=e.encrypt(u(n,s.slice(t,t+4).concat([0,0,0])));return n},U:function(e,t,r,n,o,i){var s=a.bitArray,c=s.P;if(o/=8,o%2||4>o||16<o)throw new a.exception.invalid("ccm: invalid tag length");if(4294967295<n.length||4294967295<t.length)throw new a.exception.bug("ccm: can't deal with 4GiB or more data");for(r=a.mode.ccm.ma(e,n,r,o,s.bitLength(t)/8,i),n=0;n<t.length;n+=4)r=e.encrypt(c(r,t.slice(n,n+4).concat([0,0,0])));return s.clamp(r,8*o)},V:function(e,t,r,n,o,i){var s,c=a.bitArray;s=c.P;var u=t.length,f=c.bitLength(t),h=u/50,l=h;if(r=c.concat([c.partial(8,i-1)],r).concat([0,0,0]).slice(0,4),n=c.bitSlice(s(n,e.encrypt(r)),0,o),!u)return{tag:n,data:[]};for(s=0;s<u;s+=4)s>h&&(a.mode.ccm.da(s/u),h+=l),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:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[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.B[0].update(r[0]),this.B[1].update(r[1]),this.O=new t(this.B[0])};a.misc.hmac.prototype.encrypt=a.misc.hmac.prototype.mac=function(e){if(this.Z)throw new a.exception.invalid("encrypt on already updated hmac called!");return this.update(e),this.digest(e)};a.misc.hmac.prototype.reset=function(){this.O=new this.W(this.B[0]),this.Z=!1};a.misc.hmac.prototype.update=function(e){this.Z=!0,this.O.update(e)};a.misc.hmac.prototype.digest=function(){var e=this.O.finalize(),e=new this.W(this.B[1]).update(e).finalize();return this.reset(),e};a.misc.pbkdf2=function(e,t,r,n,o){if(r=r||1e4,0>n||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(h.concat(t,[u])),s=1;s<r;s++)for(i=e.encrypt(i),c=0;c<i.length;c++)o[c]^=i[c];f=f.concat(o)}return n&&(f=h.clamp(f,n)),f};a.prng=function(e){this.h=[new a.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=e,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};a.prng.prototype={randomWords:function(e,t){var r=[],n;n=this.isReady(t);var o;if(n===this.A)throw new a.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 a.hash.sha256),this.s.push(0)),this.i-=i,i>this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n<e;n+=4)(n+1)%this.aa===0&&st(this),o=Se(this),r.push(o[0],o[1],o[2],o[3]);return st(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 a.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this.L=e},addEntropy:function(e,t,r){r=r||"user";var n,o,i=new Date().valueOf(),s=this.G[r],c=this.isReady(),u=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 e){case"number":t===void 0&&(t=1),this.h[s].update([n,this.M++,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]"&&(u=1),r=0;r<e.length&&!u;r++)typeof e[r]!="number"&&(u=1);if(!u){if(t===void 0)for(r=t=0;r<e.length;r++)for(o=e[r];0<o;)t++,o=o>>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&it("seeded",Math.max(this.u,this.i)),it("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ue(this,this.la),mouseCollector:ue(this,this.na),keyboardCollector:ue(this,this.ja),accelerometerCollector:ue(this,this.ca),touchCollector:ue(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 a.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.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[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]},ja:function(){ce(this,1)},na: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"),ce(this,0)},pa:function(e){e=e.touches[0]||e.changedTouches[0],this.addEntropy([e.pageX||e.clientX,e.pageY||e.clientY],1,"touch"),ce(this,0)},la:function(){ce(this,2)},ca: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"),ce(this,0)}};function it(e,t){var r,n=a.random.J[e],o=[];for(r in n)n.hasOwnProperty(r)&&o.push(n[r]);for(r=0;r<o.length;r++)o[r](t)}function ce(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 st(e){e.b=Se(e).concat(Se(e)),e.K=new a.cipher.aes(e.b)}function Se(e){for(var t=0;4>t&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ue(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(we=typeof q<"u"&&q.exports){try{Ee=bt("crypto")}catch{Ee=null}we=ge=Ee}if(we&&ge.randomBytes)fe=ge.randomBytes(128),fe=new Uint32Array(new Uint8Array(fe).buffer),a.random.addEntropy(fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(he=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(he);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(he);else break e;a.random.addEntropy(he,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 fe,ge,he,we,Ee;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.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 a.exception.invalid("json encrypt: invalid parameters");return typeof e=="string"?(s=a.misc.cachedPbkdf2(e,i),e=s.key.slice(0,i.ks/32),i.salt=s.salt):a.ecc&&e instanceof a.ecc.elGamal.publicKey&&(s=e.kem(),i.kemtag=s.tag,e=s.key.slice(0,i.ks/32)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof r=="string"&&(i.adata=r=a.codec.utf8String.toBits(r)),s=new a.cipher[i.cipher](e),o.j(n,i),n.key=e,i.ct=i.mode==="ccm"&&a.arrayBuffer&&a.arrayBuffer.ccm&&t instanceof ArrayBuffer?a.arrayBuffer.ccm.encrypt(s,t,i.iv,r,i.ts):a.mode[i.mode].encrypt(s,t,i.iv,r,i.ts),i},encrypt:function(e,t,r,n){var o=a.json,i=o.ha.apply(o,arguments);return o.encode(i)},ga:function(e,t,r,n){r=r||{},n=n||{};var o=a.json;t=o.j(o.j(o.j({},o.defaults),t),r,!0);var i,s;if(i=t.adata,typeof t.salt=="string"&&(t.salt=a.codec.base64.toBits(t.salt)),typeof t.iv=="string"&&(t.iv=a.codec.base64.toBits(t.iv)),!a.mode[t.mode]||!a.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 a.exception.invalid("json decrypt: invalid parameters");return typeof e=="string"?(s=a.misc.cachedPbkdf2(e,t),e=s.key.slice(0,t.ks/32),t.salt=s.salt):a.ecc&&e instanceof a.ecc.elGamal.secretKey&&(e=e.unkem(a.codec.base64.toBits(t.kemtag)).slice(0,t.ks/32)),typeof i=="string"&&(i=a.codec.utf8String.toBits(i)),s=new a.cipher[t.cipher](e),i=t.mode==="ccm"&&a.arrayBuffer&&a.arrayBuffer.ccm&&t.ct instanceof ArrayBuffer?a.arrayBuffer.ccm.decrypt(s,t.ct,t.iv,t.tag,i,t.ts):a.mode[t.mode].decrypt(s,t.ct,t.iv,i,t.ts),o.j(n,t),n.key=e,r.raw===1?i:a.codec.utf8String.fromBits(i)},decrypt:function(e,t,r,n){var o=a.json;return o.ga(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 a.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+='"'+a.codec.base64.fromBits(e[t],0)+'"';break;default:throw new a.exception.bug("json encode: unsupported type")}}return r+"}"},decode:function(e){if(e=e.replace(/\s/g,""),!e.match(/^\{.*\}$/))throw new a.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 a.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)$/)?a.codec.base64.toBits(n[4]):unescape(n[4]):n[5]!=null&&(t[n[2]]=n[5]==="true")}return t},j: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 a.exception.invalid("required parameter overridden");e[n]=t[n]}return e},ra:function(e,t){var r={},n;for(n in e)e.hasOwnProperty(n)&&e[n]!==t[n]&&(r[n]=e[n]);return r},qa: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}};a.encrypt=a.json.encrypt;a.decrypt=a.json.decrypt;a.misc.oa={};a.misc.cachedPbkdf2=function(e,t){var r=a.misc.oa,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):a.random.randomWords(2,0)},r=t.salt===void 0?n.firstSalt:t.salt,n[r]=n[r]||a.misc.pbkdf2(e,r,t.iter),{key:n[r].slice(0),salt:r.slice(0)}};typeof q<"u"&&q.exports&&(q.exports=a);typeof define=="function"&&define([],function(){return a})});var tt=Ie($e());var Tt={withStackTrace:!1},Ke=(e,t,r=Tt)=>{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 $(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 c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ve(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 U(e){return this instanceof U?(this.v=e,this):new U(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(g){return Promise.resolve(g).then(d,l)}}function c(d,g){n[d]&&(o[d]=function(k){return new Promise(function(C,N){i.push([d,k,C,N])>1||u(d,k)})},g&&(o[d]=g(o[d])))}function u(d,g){try{f(n[d](g))}catch(k){y(i[0][3],k)}}function f(d){d.value instanceof U?Promise.resolve(d.value.v).then(h,l):y(i[0][2],d)}function h(d){u("next",d)}function l(d){u("throw",d)}function y(d,g){d(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ut(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:U(e[o](s)),done:!1}: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 Ve=="function"?Ve(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(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var A=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new _(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new _(o)).catch(o=>new S(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e($(this,void 0,void 0,function*(){try{return new _(yield t(...n))}catch(o){return new S(r?r(o):o)}}))}static combine(t){return jt(t)}static combineWithAllErrors(t){return Nt(t)}map(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?new S(r.error):new _(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);let n=yield t(r.value);return n.isErr()?new S(n.error):new _(r.value)})))}andTee(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);try{yield t(r.value)}catch{}return new _(r.value)})))}mapErr(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isOk()?new _(r.value):new S(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new S(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new _(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 Ye(this,arguments,function*(){return yield U(yield U(yield*Ut(It(yield U(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Ye(this,arguments,function*(){let r=yield U(this._promise);return r.isErr()&&(yield yield U(O(r.error))),yield U(r.value)})}},I=e=>new A(Promise.resolve(new _(e))),O=e=>new A(Promise.resolve(new S(e))),mr=A.fromPromise,yr=A.fromSafePromise,vr=A.fromThrowable,qe=e=>{let t=J([]);for(let r of e)if(r.isErr()){t=B(r.error);break}else t.map(n=>n.push(r.value));return t},jt=e=>A.fromSafePromise(Promise.all(e)).andThen(qe),Qe=e=>{let t=J([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=B([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Nt=e=>A.fromSafePromise(Promise.all(e)).andThen(Qe),ke;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return J(c)}catch(c){return B(i?i(c):c)}}}e.fromThrowable=t;function r(o){return qe(o)}e.combine=r;function n(o){return Qe(o)}e.combineWithAllErrors=n})(ke||(ke={}));var J=e=>new _(e);function B(e){return new S(e)}var _=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return J(t(this.value))}mapErr(t){return J(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 J(this.value)}orElse(t){return J(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return A.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 Ke("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},S=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return B(this.error)}mapErr(t){return B(t(this.error))}andThrough(t){return B(this.error)}andTee(t){return B(this.error)}andThen(t){return B(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return O(this.error)}asyncAndThrough(t){return O(this.error)}asyncMap(t){return O(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield B(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ke("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},gr=ke.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var z=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 Bt=()=>typeof Deno<"u";var V=e=>Bt()?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 tt.default,w,Ze=!1;self.onmessage=e=>{Ft(e),Ze||(Ze=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var Y=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var Ft=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)w.postMessage(e.data,e.data);else{switch(r){case 2:w=new Worker(V("cancel"),{type:"module"}),w.postMessage(e.data,e.data);break;case 3:w=new Worker(V("download"),{type:"module"}),w.postMessage(e.data,e.data);break;case 4:w=new Worker(V("infos"),{type:"module"}),w.postMessage(e.data,e.data);break;case 7:w=w||new Worker(V("remove"),{type:"module"}),w.postMessage(e.data,e.data);break;case 9:w=w||new Worker(V("upload"),{type:"module"}),w.postMessage(e.data,e.data);break;default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data,n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}}},rt=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var j=class extends F{};var se=class extends j{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var K=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,c,u=0,f=0;for(;u<t.length*.75;)o=this._charset.indexOf(t.charAt(f++)),i=this._charset.indexOf(t.charAt(f++)),s=this._charset.indexOf(t.charAt(f++)),c=this._charset.indexOf(t.charAt(f++)),n[u++]=o<<2|i>>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Jt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ae(e){return Jt.Decode(e)}var zt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function _e(e){return zt.Decode(e)}var ut=Ie(at());var W=class extends F{};var Q=class extends W{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var ft=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return I(ae(ut.default.decrypt(e,r)))}catch(r){return O(new Q(void 0,{cause:z(r)}))}};var ht=(e,t)=>Vt(e).andThen(r=>A.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ae(t.data)),n=>new Q(void 0,{cause:z(n)})));var Vt=e=>A.fromPromise(crypto.subtle.importKey("raw",_e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new W("Unable to import cryptography key",{cause:z(t)}));var lt=(e,t)=>t.algo===void 0||t.algo===0?ft(e,t):ht(e,t);var b={},dt=5,qt=e=>(m.emit("UPLOAD_CANCELLED",e.success),I(void 0)),Qt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(ar(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),lt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(Y(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")):Y(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?rr(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),I(void 0))):I(void 0)})}else{let s=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),O(s)}}else{let i=new j(o.msg);return m.emit("OPERATION_FAILED",i),O(i)}}else{let o=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),O(o)}},Zt=(e,t)=>{if(e.success)return e.j===0&&(Y(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),Y(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Y(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),I(void 0);{let r=new j(e.msg);return m.emit("OPERATION_FAILED",r),O(r)}},er=(e,t)=>{let r=sr(e.data),n;if(r)if(!r.action&&r.msg){let o=new j(r.msg);return m.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Zt(r,t):n=qt(r);else n=Qt(e.data,t);return n},tr=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.CONNECTING,Ce=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.OPEN,pt=e=>Re(ir(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var rr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Re(or(e),e,JSON.stringify(t))};var Re=(e,t,r)=>Ce(e)?(b[e].onmessage=n=>er(n,t),b[e].send(r),I(void 0)):mt(e).andThen(()=>Re(e,t,r)),mt=(e,t=0)=>(!Ce(e)&&!tr(e)&&(b[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[e].onopen=()=>{m.emit("SOCKET_OPENED")},b[e].onclose=()=>{},b[e].onerror=()=>++t<=dt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${dt}`),mt(e,t)):(m.emit("SOCKET_ONERROR"),O(new se(`Unable to connect to WebSocket ${e}.`)))),nr(e).andThen(()=>I(e)).orElse(r=>O(r))),nr=e=>A.fromPromise(new Promise((t,r)=>{Ce(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new se)}))}),t=>z(t));var yt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},or=e=>yt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),ir=e=>yt(new URL(e.serverUrl),"upload").toString(),sr=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},ar=e=>typeof e=="object"&&e!==null&&!("msg"in e);var vt=!1;self.onmessage=e=>{vt||(rt(),vt=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),ur(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var ur=e=>pt(e.args.lufiFile);
|