2 lines
44 KiB
JavaScript
2 lines
44 KiB
JavaScript
var Ge=Object.create;var te=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Ke=(e,t,r)=>t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ye=(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 fe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ze=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ve.call(e,o)&&o!==r&&te(e,o,{get:()=>t[o],enumerable:!(n=He(t,o))||n.enumerable});return e};var ue=(e,t,r)=>(r=e!=null?Ge(qe(e)):{},Ze(t||!e||!e.__esModule?te(r,"default",{value:e,enumerable:!0}):r,e));var k=(e,t,r)=>Ke(e,typeof t!="symbol"?t+"":t,r);var Se=fe((sr,ne)=>{"use strict";var N=typeof Reflect=="object"?Reflect:null,ye=N&&typeof N.apply=="function"?N.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},V;N&&typeof N.ownKeys=="function"?V=N.ownKeys:Object.getOwnPropertySymbols?V=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:V=function(t){return Object.getOwnPropertyNames(t)};function it(e){console&&console.warn&&console.warn(e)}var ve=Number.isNaN||function(t){return t!==t};function y(){y.init.call(this)}ne.exports=y;ne.exports.once=ft;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var ge=10;function K(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return ge},set:function(e){if(typeof e!="number"||e<0||ve(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ge=e}});y.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};y.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ve(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?y.defaultMaxListeners:e._maxListeners}y.prototype.getMaxListeners=function(){return we(this)};y.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")ye(f,this,r);else for(var u=f.length,l=Oe(f,u),n=0;n<u;++n)ye(l[n],this,r);return!0};function Ee(e,t,r,n){var o,i,s;if(K(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 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,it(a)}return e}y.prototype.addListener=function(t,r){return Ee(this,t,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(t,r){return Ee(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 Ae(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}y.prototype.once=function(t,r){return K(r),this.on(t,Ae(this,t,r)),this};y.prototype.prependOnceListener=function(t,r){return K(r),this.prependListener(t,Ae(this,t,r)),this};y.prototype.removeListener=function(t,r){var n,o,i,s,a;if(K(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():ct(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 Le(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?at(o):Oe(o,o.length)}y.prototype.listeners=function(t){return Le(this,t,!0)};y.prototype.rawListeners=function(t){return Le(this,t,!1)};y.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):xe.call(e,t)};y.prototype.listenerCount=xe;function xe(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}y.prototype.eventNames=function(){return this._eventsCount>0?V(this._events):[]};function Oe(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 at(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}function ft(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))}De(e,t,i,{once:!0}),t!=="error"&&ut(e,o,{once:!0})})}function ut(e,t,r){typeof e.on=="function"&&De(e,"error",t,r)}function De(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 Te=fe((xr,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 Pe(this,e,0)},decrypt:function(e){return Pe(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,p;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]]],p=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]=p=p<<24^p>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Pe(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,p=4,d=[0,0,0,0];a=e.s[r],e=a[0];var m=a[1],b=a[2],I=a[3],T=a[4];for(h=0;h<l;h++)a=e[o>>>24]^m[i>>16&255]^b[s>>8&255]^I[t&255]^n[p],f=e[i>>>24]^m[s>>16&255]^b[t>>8&255]^I[o&255]^n[p+1],u=e[s>>>24]^m[t>>16&255]^b[o>>8&255]^I[i&255]^n[p+2],t=e[t>>>24]^m[o>>16&255]^b[i>>8&255]^I[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)d[r?3&-h:h]=T[o>>>24]<<24^T[i>>16&255]<<16^T[s>>8&255]<<8^T[t&255]^n[p++],a=o,o=i,i=s,s=t,t=a;return d}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)ie(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)ie(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;)ie(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 ie(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],p=i[5],d=i[6],m=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+m+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(d^h&(p^d))+s[r],m=d,d=p,p=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]+p|0,i[6]=i[6]+d|0,i[7]=i[7]+m|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,p=[];for(n=n||[],o=o||64,s=0;s+4<t.length;s+=4)h=t.slice(s,s+4),l=u(l,h),p=p.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))),p.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,p,d=c.bitArray.bitLength(t)-o,m=[];for(n=n||[],r=0;r+4<d/32;r+=4)h=f(l,e.decrypt(f(l,t.slice(r,r+4)))),u=f(u,h),m=m.concat(h),l=s(l);if(p=d-32*r,h=e.encrypt(f(l,[0,0,0,p])),h=f(h,a.clamp(t.slice(r),p).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,d)))throw new c.exception.corrupt("ocb: tag doesn't match");return m.concat(a.clamp(h,p))},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,p,d,m=c.bitArray;for(h=r.length,p=m.bitLength(r),d=m.bitLength(n),a=m.bitLength(o),s=t.encrypt([0,0,0,0]),a===96?(o=o.slice(0),o=m.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=m.clamp(r,p),e&&(n=c.mode.gcm.j(s,a,r)),e=[Math.floor(d/4294967296),d&4294967295,Math.floor(p/4294967296),p&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:m.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&&Ie(this),o=se(this),r.push(o[0],o[1],o[2],o[3]);return Ie(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&&Me("seeded",Math.max(this.o,this.f)),Me("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:H(this,this.ma),mouseCollector:H(this,this.oa),keyboardCollector:H(this,this.la),accelerometerCollector:H(this,this.ea),touchCollector:H(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(){G(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"),G(this,0)},qa:function(e){e=e.touches[0]||e.changedTouches[0],this.addEntropy([e.pageX||e.clientX,e.pageY||e.clientY],1,"touch"),G(this,0)},ma:function(){G(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"),G(this,0)}};function Me(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 G(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 Ie(e){e.b=se(e).concat(se(e)),e.L=new c.cipher.aes(e.b)}function se(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 H(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Z=typeof J<"u"&&J.exports){try{Q=Ye("crypto")}catch{Q=null}Z=Y=Q}if(Z&&Y.randomBytes)$=Y.randomBytes(128),$=new Uint32Array(new Uint8Array($).buffer),c.random.addEntropy($,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(q=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(q);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(q);else break e;c.random.addEntropy(q,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 $,Y,q,Z,Q;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 Qe={withStackTrace:!1},de=(e,t,r=Qe)=>{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 U(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,t||[])).next())})}function he(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 O(e){return this instanceof O?(this.v=e,this):new O(e)}function le(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),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(m){return Promise.resolve(m).then(d,h)}}function a(d,m){n[d]&&(o[d]=function(b){return new Promise(function(I,T){i.push([d,b,I,T])>1||f(d,b)})},m&&(o[d]=m(o[d])))}function f(d,m){try{u(n[d](m))}catch(b){p(i[0][3],b)}}function u(d){d.value instanceof O?Promise.resolve(d.value.v).then(l,h):p(i[0][2],d)}function l(d){f("next",d)}function h(d){f("throw",d)}function p(d,m){d(m),i.shift(),i.length&&f(i[0][0],i[0][1])}}function et(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:O(e[o](s)),done:!1}:i?i(s):s}:i}}function tt(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 he=="function"?he(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 E=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 x(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(U(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new x(r?r(o):o)}}))}static combine(t){return rt(t)}static combineWithAllErrors(t){return nt(t)}map(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new x(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);let n=yield t(r.value);return n.isErr()?new x(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new x(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new x(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>U(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 le(this,arguments,function*(){return yield O(yield O(yield*et(tt(yield O(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return le(this,arguments,function*(){let r=yield O(this._promise);return r.isErr()&&(yield yield O(w(r.error))),yield O(r.value)})}},D=e=>new E(Promise.resolve(new L(e))),w=e=>new E(Promise.resolve(new x(e))),Mt=E.fromPromise,It=E.fromSafePromise,Tt=E.fromThrowable,pe=e=>{let t=P([]);for(let r of e)if(r.isErr()){t=_(r.error);break}else t.map(n=>n.push(r.value));return t},rt=e=>E.fromSafePromise(Promise.all(e)).andThen(pe),me=e=>{let t=P([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=_([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},nt=e=>E.fromSafePromise(Promise.all(e)).andThen(me),re;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return P(a)}catch(a){return _(i?i(a):a)}}}e.fromThrowable=t;function r(o){return pe(o)}e.combine=r;function n(o){return me(o)}e.combineWithAllErrors=n})(re||(re={}));var P=e=>new L(e);function _(e){return new x(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return P(t(this.value))}mapErr(t){return P(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 P(this.value)}orElse(t){return P(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return E.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 de("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},x=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return _(this.error)}mapErr(t){return _(t(this.error))}andThrough(t){return _(this.error)}andTee(t){return _(this.error)}andThen(t){return _(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return w(this.error)}asyncAndThrough(t){return w(this.error)}asyncMap(t){return w(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield _(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw de("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Ut=re.fromThrowable;var C=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});k(this,"context");this.name=this.constructor.name,this.context=i}};var S=class extends C{};var X=class extends S{constructor(){super(...arguments);k(this,"message","An error occured while trying to connect to WebSocket")}};var M=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 ot=()=>typeof Deno<"u";var B=e=>ot()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var _e=ue(Se());var g=new _e.default,v,be=!1;self.onmessage=e=>{lt(e),be||(be=!0,g.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var j=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var lt=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)v.postMessage(e.data);else{switch(r){case 2:v=new Worker(B("cancel"),{type:"module"}),v.postMessage(e.data);break;case 3:v=new Worker(B("download"),{type:"module"}),v.postMessage(e.data);break;case 4:v=new Worker(B("infos"),{type:"module"}),v.postMessage(e.data);break;case 7:v=v||new Worker(B("remove"),{type:"module"}),v.postMessage(e.data);break;case 9:v=v||new Worker(B("upload"),{type:"module"}),v.postMessage(e.data);break;default:console.error("Action not found")}v.onmessage=n=>{t&&t(n),self.postMessage(n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},Ce=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var W=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 dt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function z(e){return dt.Decode(e)}var pt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function oe(e){return pt.Decode(e)}var Be=ue(Te());var R=class extends C{};var F=class extends R{constructor(){super(...arguments);k(this,"message","Unable to decrypt the provided data")}};var Ne=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return D(z(Be.default.decrypt(e,r)))}catch(r){return w(new F(void 0,{cause:M(r)}))}};var je=(e,t)=>gt(e).andThen(r=>E.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,z(t.data)),n=>new F(void 0,{cause:M(n)})));var gt=e=>E.fromPromise(crypto.subtle.importKey("raw",oe(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new R("Unable to import cryptography key",{cause:M(t)}));var We=(e,t)=>t.algo===void 0||t.algo===0?Ne(e,t):je(e,t);var A={},Je=5,Et=e=>(g.emit("UPLOAD_CANCELLED",e.success),D(void 0)),At=(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))),We(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(j(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}),g.emit("DOWNLOAD_STARTED")):j(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Dt(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),D(void 0))):D(void 0)})}else{let s=new S("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),w(s)}}else{let i=new S(o.msg);return g.emit("OPERATION_FAILED",i),w(i)}}else{let o=new S("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),w(o)}},Lt=(e,t)=>{if(e.success)return e.j===0&&(j(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),j(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(j(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),D(void 0);{let r=new S(e.msg);return g.emit("OPERATION_FAILED",r),w(r)}},xt=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new S(r.msg);return g.emit("OPERATION_FAILED",o),w(o)}else"delay"in r?n=Lt(r,t):n=Et(r);else n=At(e.data,t);return n},Ot=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ce=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var Fe=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},ae(ee(e),e,JSON.stringify(r))},Dt=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ae(ee(e),e,JSON.stringify(t))};var ae=(e,t,r)=>ce(e)?(A[e].onmessage=n=>xt(n,t),A[e].send(r),D(void 0)):Xe(e).andThen(()=>ae(e,t,r)),Xe=(e,t=0)=>(!ce(e)&&!Ot(e)&&(A[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{g.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}`),Xe(e,t)):(g.emit("SOCKET_ONERROR"),w(new X(`Unable to connect to WebSocket ${e}.`)))),St(e).andThen(()=>D(e)).orElse(r=>w(r))),St=e=>E.fromPromise(new Promise((t,r)=>{ce(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new X)}))}),t=>M(t));var bt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ee=e=>bt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var kt=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 ze=!1;self.onmessage=e=>{ze||(Ce(),ze=!0),g.on("DOWNLOAD_STARTED",()=>{A[ee(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),Rt(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Rt=e=>Fe(e.args.lufiFile,0);
|