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