iosignal 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ import t,{Transform as e}from"stream";import r from"net";import n from"zlib";import i,{readFileSync as s}from"fs";import o from"path";import a from"os";import h from"buffer";import f from"crypto";import c from"events";import u from"https";import l from"http";import p from"tls";import d from"url";import{memoryUsage as g}from"process";for(var y="2.2.0",m={},_={byteLength:function(t){var e=S(t),r=e[0],n=e[1];return 3*(r+n)/4-n},toByteArray:function(t){var e,r,n=S(t),i=n[0],s=n[1],o=new E(function(t,e,r){return 3*(e+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)e=w[t.charCodeAt(r)]<<18|w[t.charCodeAt(r+1)]<<12|w[t.charCodeAt(r+2)]<<6|w[t.charCodeAt(r+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=w[t.charCodeAt(r)]<<2|w[t.charCodeAt(r+1)]>>4,o[a++]=255&e),1===s&&(e=w[t.charCodeAt(r)]<<10|w[t.charCodeAt(r+1)]<<4|w[t.charCodeAt(r+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o},fromByteArray:function(t){for(var e,r=t.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(A(t,o,o+s>a?a:o+s));return 1===n?(e=t[r-1],i.push(b[e>>2]+b[e<<4&63]+"==")):2===n&&(e=(t[r-2]<<8)+t[r-1],i.push(b[e>>10]+b[e>>4&63]+b[e<<2&63]+"=")),i.join("")}},b=[],w=[],E="undefined"!=typeof Uint8Array?Uint8Array:Array,B="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",v=0;v<64;++v)b[v]=B[v],w[B.charCodeAt(v)]=v;function S(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function A(t,e,r){for(var n,i,s=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),s.push(b[(i=n)>>18&63]+b[i>>12&63]+b[i>>6&63]+b[63&i]);return s.join("")}w["-".charCodeAt(0)]=62,w["_".charCodeAt(0)]=63;var k={
2
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3
+ read:function(t,e,r,n,i){var s,o,a=8*i-n-1,h=(1<<a)-1,f=h>>1,c=-7,u=r?i-1:0,l=r?-1:1,p=t[e+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+t[e+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+t[e+u],u+=l,c-=8);if(0===s)s=1-f;else{if(s===h)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),s-=f}return(p?-1:1)*o*Math.pow(2,s-n)},write:function(t,e,r,n,i,s){var o,a,h,f=8*s-i-1,c=(1<<f)-1,u=c>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=c):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),(e+=o+u>=1?l/h:l*Math.pow(2,1-u))*h>=2&&(o++,h/=2),o+u>=c?(a=0,o=c):o+u>=1?(a=(e*h-1)*Math.pow(2,i),o+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;t[r+p]=255&o,p+=d,o/=256,f-=8);t[r+p-d]|=128*g}};
4
+ /*!
5
+ * The buffer module from node.js, for the browser.
6
+ *
7
+ * @author Feross Aboukhadijeh <https://feross.org>
8
+ * @license MIT
9
+ */!function(t){const e=_,r=k,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(t){return+t!=t&&(t=0),o.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function s(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,o.prototype),e}function o(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return f(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=s(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(Q(t,Uint8Array)){const e=new Uint8Array(t);return u(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(Q(t,ArrayBuffer)||t&&Q(t.buffer,ArrayBuffer))return u(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(Q(t,SharedArrayBuffer)||t&&Q(t.buffer,SharedArrayBuffer)))return u(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return o.from(n,e,r);const i=function(t){if(o.isBuffer(t)){const e=0|l(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?s(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return o.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function f(t){return h(t),s(t<0?0:0|l(t))}function c(t){const e=t.length<0?0:0|l(t.length),r=s(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function u(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,o.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(o.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||Q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(t).length;default:if(i)return n?-1:V(t).length;e=(""+e).toLowerCase(),i=!0}}function d(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return A(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=o.from(e,n)),o.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let s,o=1,a=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(t,s)===f(e,-1===n?0:s-n)){if(-1===n&&(n=s),s-n+1===h)return n*o}else-1!==n&&(s-=s-n),n=-1}else for(r+h>a&&(r=a-h),s=r;s>=0;s--){let r=!0;for(let n=0;n<h;n++)if(f(t,s+n)!==f(e,n)){r=!1;break}if(r)return s}return-1}function b(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=e.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(e.substr(2*o,2),16);if(J(n))return o;t[r+o]=n}return o}function w(t,e,r,n){return Y(V(e,t.length-r),t,r,n)}function E(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function B(t,e,r,n){return Y(q(e),t,r,n)}function v(t,e,r,n){return Y(function(t,e){let r,n,i;const s=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(e,t.length-r),t,r,n)}function S(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function A(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let s=null,o=e>239?4:e>223?3:e>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:e<128&&(s=e);break;case 2:r=t[i+1],128==(192&r)&&(h=(31&e)<<6|63&r,h>127&&(s=h));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(h=(15&e)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,h>65535&&h<1114112&&(s=h))}}null===s?(s=65533,o=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=o}return function(t){const e=t.length;if(e<=L)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=L));return r}(n)}t.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(t,e,r){return function(t,e,r){return h(t),t<=0?s(t):void 0!==e?"string"==typeof r?s(t).fill(e,r):s(t).fill(e):s(t)}(t,e,r)},o.allocUnsafe=function(t){return f(t)},o.allocUnsafeSlow=function(t){return f(t)},o.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==o.prototype},o.compare=function(t,e){if(Q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),Q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return o.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=o.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(Q(e,Uint8Array))i+e.length>n.length?(o.isBuffer(e)||(e=o.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!o.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},o.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},o.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},o.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?A(this,0,t):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===o.compare(this,t)},o.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(t,e,r,n,i){if(Q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<h;++t)if(f[t]!==c[t]){s=f[t],a=c[t];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},o.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},o.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},o.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return w(this,t,e,r);case"ascii":case"latin1":case"binary":return E(this,t,e,r);case"base64":return B(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const L=4096;function I(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function T(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function U(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=X[t[n]];return i}function x(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function O(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function C(t,e,r,n,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function R(t,e,r,n,i){j(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,r}function N(t,e,r,n,i){j(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s>>=8,t[r+6]=s,s>>=8,t[r+5]=s,s>>=8,t[r+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=o,o>>=8,t[r+2]=o,o>>=8,t[r+1]=o,o>>=8,t[r]=o,r+8}function M(t,e,r,n,i,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(t,e,n,i,s){return e=+e,n>>>=0,s||M(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function D(t,e,n,i,s){return e=+e,n>>>=0,s||M(t,0,n,8),r.write(t,e,n,i,52,8),n+8}o.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,e){return t>>>=0,e||O(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readBigUInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},o.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||O(t,e,this.length);let n=e,i=1,s=this[t+--n];for(;n>0&&(i*=256);)s+=this[t+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*e)),s},o.prototype.readInt8=function(t,e){return t>>>=0,e||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){t>>>=0,e||O(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(t,e){t>>>=0,e||O(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return t>>>=0,e||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readBigInt64LE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),o.prototype.readBigInt64BE=K((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||G(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),o.prototype.readFloatLE=function(t,e){return t>>>=0,e||O(t,4,this.length),r.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return t>>>=0,e||O(t,4,this.length),r.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return t>>>=0,e||O(t,8,this.length),r.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return t>>>=0,e||O(t,8,this.length),r.read(this,t,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||C(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[e]=255&t;++s<r&&(i*=256);)this[e+s]=t/i&255;return e+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||C(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,1,255,0),this[e]=255&t,e+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigUInt64LE=K((function(t,e=0){return R(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=K((function(t,e=0){return N(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,t,e,r,n-1,-n)}let i=0,s=1,o=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===o&&0!==this[e+i-1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,t,e,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===o&&0!==this[e+i+1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},o.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||C(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigInt64LE=K((function(t,e=0){return R(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=K((function(t,e=0){return N(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(t,e,r){return P(this,t,e,!0,r)},o.prototype.writeFloatBE=function(t,e,r){return P(this,t,e,!1,r)},o.prototype.writeDoubleLE=function(t,e,r){return D(this,t,e,!0,r)},o.prototype.writeDoubleBE=function(t,e,r){return D(this,t,e,!1,r)},o.prototype.copy=function(t,e,r,n){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},o.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const s=o.isBuffer(t)?t:o.from(t,n),a=s.length;if(0===a)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};const $={};function F(t,e,r){$[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function H(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,i,s){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(s+1)}${r}`:`>= -(2${r} ** ${8*(s+1)-1}${r}) and < 2 ** ${8*(s+1)-1}${r}`,new $.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||G(e,t.length-(r+1))}(n,i,s)}function z(t,e){if("number"!=typeof t)throw new $.ERR_INVALID_ARG_TYPE(e,"number",t)}function G(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new $.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new $.ERR_BUFFER_OUT_OF_BOUNDS;throw new $.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}F("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),F("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),F("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=H(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=H(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const W=/[^+/0-9A-Za-z-_]/g;function V(t,e){let r;e=e||1/0;const n=t.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=t.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function q(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(W,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function Q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const X=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function K(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}}(m);const L=new TextEncoder,I=new TextDecoder,T=U;function U(t,e=0){let r;if(void 0===t||"string"!=typeof t||"number"!=typeof e)throw TypeError("invlaid init variablie type name. ");return(t=t.toUpperCase()).includes("8")?(r=m.Buffer.alloc(1),t.includes("I")?r.writeInt8(e):r.writeUint8(e)):t.includes("16")?(r=m.Buffer.alloc(2),t.includes("I")?t.includes("L")?r.writeInt16LE(e):r.writeInt16BE(e):t.includes("L")?r.writeUint16LE(e):r.writeUint16BE(e)):t.includes("32")?(r=m.Buffer.alloc(4),t.includes("I")?t.includes("L")?r.writeInt32LE(e):r.writeInt32BE(e):t.includes("L")?r.writeUint32LE(e):r.writeUint32BE(e)):t.includes("F")?(r=m.Buffer.alloc(4),t.includes("L")?r.writeFloatLE(e):r.writeFloatBE(e)):t.includes("N")?r=m.Buffer.from(String(e)):console.log(`invalid type: ${t} or initvalue: ${e}`),r}const x=O;function O(t,e,r){let n,i="B";if("number"==typeof e)"number"==typeof r?(n=m.Buffer.alloc(e),0!==r&&n.fill(r),i="B"):(n=m.Buffer.from(String(e)),i="N");else if("string"==typeof e&&"number"==typeof r)i=e.toUpperCase(),n=U(e,r);else if("string"==typeof e&&void 0===r)n=m.Buffer.from(e),i="S";else if(e instanceof Uint8Array&&void 0===r)n=e instanceof m.Buffer?e:m.Buffer.from(e);else if(e instanceof ArrayBuffer&&void 0===r)n=m.Buffer.from(e);else if(ArrayBuffer.isView(e))n=m.Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if("object"==typeof e&&void 0===r)n=m.Buffer.from(JSON.stringify(e)),i="O";else{if("boolean"!=typeof e||void 0!==r)throw TypeError("invalid meta buffer type");{const t=e?1:0;n=m.Buffer.from([t]),i="!"}}return"string"==typeof t&&t.includes("#")&&(t=""),[t,i,n]}const C=R;function R(...t){let e=0;return t.map((t=>{const r=e++;return"number"==typeof t?x(r,"N",t):x(r,t)}))}function N(t){if((t=t.toUpperCase()).includes("8"))return t.includes("I")?"int8":"uint8";if(t.includes("16"))return t.includes("I")?t.includes("L")?"int16_le":"int16_be":t.includes("L")?"uint16_le":"uint16_be";if(t.includes("32"))return t.includes("I")?t.includes("L")?"int32_le":"int32_be":t.includes("L")?"uint32_le":"uint32_be";if(t.includes("F"))return t.includes("L")?"float_le":"float_be";if("B"===t)return"buffer";if("S"===t)return"string";if("N"===t)return"number";if("O"===t)return"object";if("!"===t)return"boolean";throw TypeError("invalid data type")}function M(t,e,r,n){try{const i=N(t);if("int8"==i)return e.readInt8(r);if("uint8"===i)return e.readUint8(r);if("int16_le"===i)return e.readInt16LE(r);if("int16_be"===i)return e.readInt16BE(r);if("uint16_le"===i)return e.readUint16LE(r);if("uint16_be"===i)return e.readUint16BE(r);if("int32_le"===i)return e.readInt32LE(r);if("int32_be"===i)return e.readInt32BE(r);if("uint32_le"===i)return e.readUint32LE(r);if("uint32_be"===i)return e.readUint32BE(r);if("float_le"===i)return e.readFloatLE(r);if("float_be"===i)return e.readFloatBE(r);if("buffer"===i)return e.subarray(r,r+n);if("string"===i){const t=e.subarray(r,r+n);return I.decode(t)}if("number"===i){const t=e.subarray(r,r+n);return Number(I.decode(t))}if("object"===i){const t=e.subarray(r,r+n);return JSON.parse(I.decode(t))}return"boolean"===i?1===e.readInt8(r):void 0}catch(t){}}function P(...t){const e=function(t){let e=[];return t.filter((t=>{if(!Array.isArray(t[0]))return t;e=e.concat(t)})).concat(e)}(t);let r=0;const n=[];let i,s,o=0;if(e.forEach((t=>{const[e,i,s]=t;r+=s.byteLength,("number"==typeof e||e.length>0)&&n.push([e,i,o,s.byteLength]),o=r})),n.length>0){let t=JSON.stringify(n);i=L.encode(t),s=i.byteLength,r=r+s+2}const a=m.Buffer.alloc(r);if(o=0,e.forEach((t=>{const e=t[2];a.set(e,o),o+=e.byteLength})),n.length>0){a.set(i,o);const t=T("16",s);return a.set(t,o+s),a}return a}const D=$;function $(t,e=!1){if(void 0===t)throw TypeError("Invalid data type: Undefined");if("string"==typeof t)return L.encode(t);if("number"==typeof t)return Uint8Array.from([t]);if(t instanceof ArrayBuffer){if(e)return new Uint8Array(t);{const e=new Uint8Array(t),r=new Uint8Array(t.byteLength);return r.set(e),r}}if(ArrayBuffer.isView(t)){if(e)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=new Uint8Array(t.byteLength);return r.set(e),r}}return L.encode(JSON.stringify(t))}const F=H;function H(t,e=!1){const r=$(t,e);return e?m.Buffer.from(r.buffer,r.byteOffset,r.byteLength):m.Buffer.from(r)}const j=z;function z(...t){const e=t.map((t=>H(t)));return m.Buffer.concat(e)}const G=W;function W(...t){try{let e=0,r=0;const n=t.map((t=>$(t)));n.forEach((t=>{e+=t.byteLength}));const i=new Uint8Array(e);return n.forEach((t=>{i.set(t,r),r+=t.byteLength})),i}catch(t){console.log(t)}}function V(t){return 0===J(t)?t.byteLength:t.byteLength-J(t)-Y}function q(t,e){try{const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=r.byteLength-e-2,i=r.subarray(n,r.byteLength-2),s=I.decode(i),o=JSON.parse(s);if(!Array.isArray(o)||!Array.isArray(o[0]))return;let a=o[0];if(!a)return;if(a.length<3)return;const[h,f,c]=a;if("string"!=typeof f||"number"!=typeof c)return;return o}catch(t){}}const Y=2;function Q(t){return t instanceof ArrayBuffer&&(t=m.Buffer.from(t)),t instanceof Uint8Array?t.byteLength<=Y?0:new DataView(t.buffer,t.byteOffset,t.byteLength).getUint16(t.byteLength-Y):0}function J(t){if(t instanceof ArrayBuffer&&(t=m.Buffer.from(t)),t instanceof Uint8Array){const e=t.byteLength;if(e<=Y)return 0;const r=Q(t);return 0===r||r>e?0:q(t,r)?r:0}return 0}function X(t){const e=V(t);return t.subarray(0,e)}function K(t,e=!1){t instanceof ArrayBuffer&&(t=m.Buffer.from(t));const r=Q(t);if(0===r)return;let n=q(t,r);return n?e?(n.forEach((t=>{null==t[3]&&(t[1].includes("8")?t[3]=1:t[1].includes("16")?t[3]=2:t[1].includes("32")||t[1].includes("F")?t[3]=4:t[1].includes("!")&&(t[3]=1)),t[4]=N(t[1])})),n):n:void 0}var Z=Object.freeze({__proto__:null,B8:F,B8pack:j,Buffer:m.Buffer,MB:x,MBA:C,NB:T,TAIL_LEN:Y,U8:D,U8pack:G,equal:function(t,e){if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},getBuffer:X,getBufferSize:V,getMeta:K,getMetaDetail:function(t){return K(t,!0)},getMetaSize:J,hex:function(t){return Array.prototype.map.call(new Uint8Array(t),(t=>("00"+t.toString(16)).slice(-2))).join("")},meta:function(...t){return K(P(...t))},metaBuffer:O,metaBufferArguments:R,metaDetail:function(...t){return K(P(...t),!0)},numberBuffer:U,pack:P,parseBuffer:H,parseBufferThenConcat:z,parseMetaInfo:q,parseTypeName:N,parseUint8Array:$,parseUint8ThenConcat:W,rawPack:function(...t){return X(P(...t))},readTail:Q,readTypedBuffer:M,unpack:function(t,e){const r=e||K(t);if(!r)return;const n=m.Buffer.from(t),i={};let s=0;if(r.forEach((t=>{const[e,r,o,a]=t;let h=M(r,n,o,a);null!=h&&(i[e]=h,a&&(s+=a))})),e&&n.byteLength!==s){let t=n.byteLength-s,e=M("b",n,s,t);if(null==e)return;i.$OTHERS=e}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});function tt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var et,rt={exports:{}};var nt=(et||(et=1,function(t){var e=Object.prototype.hasOwnProperty,r="~";function n(){}function i(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function s(t,e,n,s,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,s||t,o),h=r?r+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,i=[];if(0===this._eventsCount)return i;for(n in t=this._events)e.call(t,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,i,s,o){var a=r?r+t:t;if(!this._events[a])return!1;var h,f,c=this._events[a],u=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,i),!0;case 5:return c.fn.call(c.context,e,n,i,s),!0;case 6:return c.fn.call(c.context,e,n,i,s,o),!0}for(f=1,h=new Array(u-1);f<u;f++)h[f-1]=arguments[f];c.fn.apply(c.context,h)}else{var l,p=c.length;for(f=0;f<p;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,i);break;default:if(!h)for(l=1,h=new Array(u-1);l<u;l++)h[l-1]=arguments[l];c[f].fn.apply(c[f].context,h)}}return!0},a.prototype.on=function(t,e,r){return s(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return s(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,i){var s=r?r+t:t;if(!this._events[s])return this;if(!e)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==e||i&&!a.once||n&&a.context!==n||o(this,s);else{for(var h=0,f=[],c=a.length;h<c;h++)(a[h].fn!==e||i&&!a[h].once||n&&a[h].context!==n)&&f.push(a[h]);f.length?this._events[s]=1===f.length?f[0]:f:o(this,s)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&o(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a}(rt)),rt.exports),it=tt(nt);const st={OPENING:0,OPEN:1,CLOSING:2,CLOSED:3,SERVER_READY:4,AUTH_FAIL:5,AUTH_READY:6,READY:7,REDIRECTING:8};for(let t in st)st[st[t]]=t;const ot={INIT:0,SENT_SERVER_READY:1,RECV_AUTH_REQ:2,SENT_SERVER_NONCE:3,RECV_AUTH_HMAC:4,AUTH_FAIL:5,AUTH_READY:6,CID_READY:7};for(let t in ot)ot[ot[t]]=t;let at={NO:0,YES:1,AUTO:2};for(let t in at)at[at[t]]=t;const ht={TAG_LEN1:255,TAG_LEN2:65535,CONNECTION_CHECKER_PERIOD:3e3,PROMISE_TIMEOUT:5e3,DID:8,CID:12};let ft={EMPTY:0,TEXT:1,BINARY:2,OBJECT:3,MJSON:4,MBA:5};for(let t in ft)ft[ft[t]]=t;let ct={SERVER_READY:192,CID_REQ:193,CID_RES:194,QUOTA_LEVEL:195,SERVER_CLEAR_AUTH:196,SERVER_REDIRECT:197,LOOP:203,ECHO:204,PING:205,PONG:206,CLOSE:207,SIGNAL:208,SIGNAL_REQ:209,SIGNAL_E2E:210,SUBSCRIBE:211,SUBSCRIBE_REQ:212,UNSUBSCRIBE:213,SERVER_SIGNAL:214,IAM:217,IAM_RES:218,SET:219,RESPONSE_CODE:220,RESPONSE_MBP:221,REQUEST:222,RESPONSE:223,FLOW_MODE:240,WAIT:241,RESUME:242,TIME_OUT:253,OVER_SIZE:254,OVER_FLOW:255};for(let t in ct)ct[ct[t]]=t;const ut={REQUEST_RESPONSE:"requet_response",ONE_WAY:"one_way"},lt={OK:0,ERROR:255};let pt={0:{signalSize:1500,publishCounter:10,trafficRate:1e4},1:{signalSize:255,publishCounter:10,trafficRate:1e5},2:{signalSize:65535,publishCounter:10,trafficRate:1048576},3:{signalSize:1048576,publishCounter:10,trafficRate:20971520},10:{signalSize:1500,publishCounter:5,trafficRate:20971520},11:{signalSize:65535,publishCounter:10,trafficRate:20971520},12:{signalSize:1048576,publishCounter:100,trafficRate:20971520},200:{signalSize:20971520,publishCounter:1e4,trafficRate:104857600},255:{signalSize:20971520,publishCounter:1e4,trafficRate:104857600}};const dt=new TextEncoder;function gt(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r,n=dt.encode(t),i=yt(e);if(i.type==ft.EMPTY)r=Z.pack(Z.MB("#MsgType","8",ct.SIGNAL),Z.MB("#tagLen","8",n.byteLength),Z.MB("#tag",n),Z.MB("#payloadType","8",i.type));else if(i.type==ft.MBA){let t=Z.pack(Z.MBA(...e));r=Z.pack(Z.MB("#MsgType","8",ct.SIGNAL),Z.MB("#tagLen","8",n.byteLength),Z.MB("#tag",n),Z.MB("#payloadType","8",i.type),Z.MB("#mbaBuffer",t))}else r=Z.pack(Z.MB("#MsgType","8",ct.SIGNAL),Z.MB("#tagLen","8",n.byteLength),Z.MB("#tag",n),Z.MB("#payloadType","8",i.type),Z.MB("#payload",i.buffer));return r}function yt(t){let e,r;if(0==t.length)e=ft.EMPTY,r=null;else if(1==t.length)if("string"==typeof t[0]||"number"==typeof t[0])e=ft.TEXT,r=dt.encode(t[0]+"."),r[r.byteLength-1]=0;else if(ArrayBuffer.isView(t[0])||t[0]instanceof ArrayBuffer)e=ft.BINARY,r=Z.B8(t[0]);else{if("object"!=typeof t[0])throw new Error("unknown payload arguments");e=ft.OBJECT,r=dt.encode(JSON.stringify(t[0]))}else{let n=!1;t.forEach((t=>{(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)&&(n=!0)})),n?e=ft.MBA:(e=ft.MJSON,r=dt.encode(JSON.stringify(t)))}return{type:e,buffer:r}}function mt(t){let e=t.readUint8(1);return t.subarray(3+e)}const _t=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function bt(t,e,r,n,i){let s,o,a,h,f,c,u,l,p,d,g,y,m;for(;i>=64;){for(s=e[0],o=e[1],a=e[2],h=e[3],f=e[4],c=e[5],u=e[6],l=e[7],d=0;d<16;d++)g=n+4*d,t[d]=(255&r[g])<<24|(255&r[g+1])<<16|(255&r[g+2])<<8|255&r[g+3];for(d=16;d<64;d++)p=t[d-2],y=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,p=t[d-15],m=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,t[d]=(y+t[d-7]|0)+(m+t[d-16]|0);for(d=0;d<64;d++)y=(((f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7))+(f&c^~f&u)|0)+(l+(_t[d]+t[d]|0)|0)|0,m=((s>>>2|s<<30)^(s>>>13|s<<19)^(s>>>22|s<<10))+(s&o^s&a^o&a)|0,l=u,u=c,c=f,f=h+y|0,h=a,a=o,o=s,s=y+m|0;e[0]+=s,e[1]+=o,e[2]+=a,e[3]+=h,e[4]+=f,e[5]+=c,e[6]+=u,e[7]+=l,n+=64,i-=64}return n}const wt=function(){function t(){this.digestLength=32,this.blockSize=64,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return t.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},t.prototype.clean=function(){for(var t=0;t<this.buffer.length;t++)this.buffer[t]=0;for(t=0;t<this.temp.length;t++)this.temp[t]=0;this.reset()},t.prototype.update=function(t,e){if(void 0===e&&(e=t.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");let r=0;if(this.bytesHashed+=e,this.bufferLength>0){for(;this.bufferLength<64&&e>0;)this.buffer[this.bufferLength++]=t[r++],e--;64===this.bufferLength&&(bt(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(e>=64&&(r=bt(this.temp,this.state,t,r,e),e%=64);e>0;)this.buffer[this.bufferLength++]=t[r++],e--;return this},t.prototype.finish=function(t){if(!this.finished){const t=this.bytesHashed,r=this.bufferLength,n=t/536870912|0,i=t<<3,s=t%64<56?64:128;this.buffer[r]=128;for(var e=r+1;e<s-8;e++)this.buffer[e]=0;this.buffer[s-8]=n>>>24&255,this.buffer[s-7]=n>>>16&255,this.buffer[s-6]=n>>>8&255,this.buffer[s-5]=n>>>0&255,this.buffer[s-4]=i>>>24&255,this.buffer[s-3]=i>>>16&255,this.buffer[s-2]=i>>>8&255,this.buffer[s-1]=i>>>0&255,bt(this.temp,this.state,this.buffer,0,s),this.finished=!0}for(e=0;e<8;e++)t[4*e+0]=this.state[e]>>>24&255,t[4*e+1]=this.state[e]>>>16&255,t[4*e+2]=this.state[e]>>>8&255,t[4*e+3]=this.state[e]>>>0&255;return this},t.prototype.digest=function(){const t=new Uint8Array(this.digestLength);return this.finish(t),t},t.prototype._saveState=function(t){for(let e=0;e<this.state.length;e++)t[e]=this.state[e]},t.prototype._restoreState=function(t,e){for(let e=0;e<this.state.length;e++)this.state[e]=t[e];this.bytesHashed=e,this.finished=!1,this.bufferLength=0},t}(),Et=function(){function t(t){this.inner=new wt,this.outer=new wt,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;const e=new Uint8Array(this.blockSize);if(t.length>this.blockSize)(new wt).update(t).finish(e).clean();else for(var r=0;r<t.length;r++)e[r]=t[r];for(r=0;r<e.length;r++)e[r]^=54;for(this.inner.update(e),r=0;r<e.length;r++)e[r]^=106;for(this.outer.update(e),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate),r=0;r<e.length;r++)e[r]=0}return t.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},t.prototype.clean=function(){for(let t=0;t<this.istate.length;t++)this.ostate[t]=this.istate[t]=0;this.inner.clean(),this.outer.clean()},t.prototype.update=function(t){return this.inner.update(t),this},t.prototype.finish=function(t){return this.outer.finished?this.outer.finish(t):(this.inner.finish(t),this.outer.update(t,this.digestLength).finish(t)),this},t.prototype.digest=function(){const t=new Uint8Array(this.digestLength);return this.finish(t),t},t}();function Bt(t){const e=(new wt).update(t),r=e.digest();return e.clean(),r}for(var vt={},St={byteLength:function(t){var e=Ut(t),r=e[0],n=e[1];return 3*(r+n)/4-n},toByteArray:function(t){var e,r,n=Ut(t),i=n[0],s=n[1],o=new Lt(function(t,e,r){return 3*(e+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)e=kt[t.charCodeAt(r)]<<18|kt[t.charCodeAt(r+1)]<<12|kt[t.charCodeAt(r+2)]<<6|kt[t.charCodeAt(r+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=kt[t.charCodeAt(r)]<<2|kt[t.charCodeAt(r+1)]>>4,o[a++]=255&e),1===s&&(e=kt[t.charCodeAt(r)]<<10|kt[t.charCodeAt(r+1)]<<4|kt[t.charCodeAt(r+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o},fromByteArray:function(t){for(var e,r=t.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(xt(t,o,o+s>a?a:o+s));return 1===n?(e=t[r-1],i.push(At[e>>2]+At[e<<4&63]+"==")):2===n&&(e=(t[r-2]<<8)+t[r-1],i.push(At[e>>10]+At[e>>4&63]+At[e<<2&63]+"=")),i.join("")}},At=[],kt=[],Lt="undefined"!=typeof Uint8Array?Uint8Array:Array,It="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Tt=0;Tt<64;++Tt)At[Tt]=It[Tt],kt[It.charCodeAt(Tt)]=Tt;function Ut(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function xt(t,e,r){for(var n,i,s=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),s.push(At[(i=n)>>18&63]+At[i>>12&63]+At[i>>6&63]+At[63&i]);return s.join("")}kt["-".charCodeAt(0)]=62,kt["_".charCodeAt(0)]=63;var Ot={
10
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
11
+ read:function(t,e,r,n,i){var s,o,a=8*i-n-1,h=(1<<a)-1,f=h>>1,c=-7,u=r?i-1:0,l=r?-1:1,p=t[e+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+t[e+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+t[e+u],u+=l,c-=8);if(0===s)s=1-f;else{if(s===h)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),s-=f}return(p?-1:1)*o*Math.pow(2,s-n)},write:function(t,e,r,n,i,s){var o,a,h,f=8*s-i-1,c=(1<<f)-1,u=c>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=c):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),(e+=o+u>=1?l/h:l*Math.pow(2,1-u))*h>=2&&(o++,h/=2),o+u>=c?(a=0,o=c):o+u>=1?(a=(e*h-1)*Math.pow(2,i),o+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;t[r+p]=255&o,p+=d,o/=256,f-=8);t[r+p-d]|=128*g}};
12
+ /*!
13
+ * The buffer module from node.js, for the browser.
14
+ *
15
+ * @author Feross Aboukhadijeh <https://feross.org>
16
+ * @license MIT
17
+ */!function(t){const e=St,r=Ot,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(t){return+t!=t&&(t=0),o.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function s(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,o.prototype),e}function o(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return f(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=s(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return u(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return u(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return u(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return o.from(n,e,r);const i=function(t){if(o.isBuffer(t)){const e=0|l(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||Y(t.length)?s(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return o.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function f(t){return h(t),s(t<0?0:0|l(t))}function c(t){const e=t.length<0?0:0|l(t.length),r=s(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function u(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,o.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(o.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function d(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return L(this,e,r);case"base64":return v(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Y(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=o.from(e,n)),o.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let s,o=1,a=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(t,s)===f(e,-1===n?0:s-n)){if(-1===n&&(n=s),s-n+1===h)return n*o}else-1!==n&&(s-=s-n),n=-1}else for(r+h>a&&(r=a-h),s=r;s>=0;s--){let r=!0;for(let n=0;n<h;n++)if(f(t,s+n)!==f(e,n)){r=!1;break}if(r)return s}return-1}function _(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=e.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(e.substr(2*o,2),16);if(Y(n))return o;t[r+o]=n}return o}function b(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function w(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function E(t,e,r,n){return V(W(e),t,r,n)}function B(t,e,r,n){return V(function(t,e){let r,n,i;const s=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(e,t.length-r),t,r,n)}function v(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function S(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let s=null,o=e>239?4:e>223?3:e>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:e<128&&(s=e);break;case 2:r=t[i+1],128==(192&r)&&(h=(31&e)<<6|63&r,h>127&&(s=h));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(h=(15&e)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,h>65535&&h<1114112&&(s=h))}}null===s?(s=65533,o=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=o}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=A));return r}(n)}t.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(t,e,r){return function(t,e,r){return h(t),t<=0?s(t):void 0!==e?"string"==typeof r?s(t).fill(e,r):s(t).fill(e):s(t)}(t,e,r)},o.allocUnsafe=function(t){return f(t)},o.allocUnsafeSlow=function(t){return f(t)},o.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==o.prototype},o.compare=function(t,e){if(q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return o.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=o.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(o.isBuffer(e)||(e=o.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!o.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},o.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},o.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},o.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?S(this,0,t):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===o.compare(this,t)},o.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<h;++t)if(f[t]!==c[t]){s=f[t],a=c[t];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},o.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},o.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},o.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":case"latin1":case"binary":return w(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function k(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function I(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function T(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function U(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function x(t,e,r,n,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function O(t,e,r,n,i){F(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,r}function C(t,e,r,n,i){F(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s>>=8,t[r+6]=s,s>>=8,t[r+5]=s,s>>=8,t[r+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=o,o>>=8,t[r+2]=o,o>>=8,t[r+1]=o,o>>=8,t[r]=o,r+8}function R(t,e,r,n,i,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(t,e,n,i,s){return e=+e,n>>>=0,s||R(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function M(t,e,n,i,s){return e=+e,n>>>=0,s||R(t,0,n,8),r.write(t,e,n,i,52,8),n+8}o.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readBigUInt64LE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},o.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=e,i=1,s=this[t+--n];for(;n>0&&(i*=256);)s+=this[t+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*e)),s},o.prototype.readInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readBigInt64LE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),o.prototype.readBigInt64BE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),o.prototype.readFloatLE=function(t,e){return t>>>=0,e||U(t,4,this.length),r.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return t>>>=0,e||U(t,4,this.length),r.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return t>>>=0,e||U(t,8,this.length),r.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return t>>>=0,e||U(t,8,this.length),r.read(this,t,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||x(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[e]=255&t;++s<r&&(i*=256);)this[e+s]=t/i&255;return e+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||x(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,1,255,0),this[e]=255&t,e+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigUInt64LE=J((function(t,e=0){return O(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,t,e,r,n-1,-n)}let i=0,s=1,o=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===o&&0!==this[e+i-1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,t,e,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===o&&0!==this[e+i+1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},o.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigInt64LE=J((function(t,e=0){return O(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(t,e,r){return N(this,t,e,!0,r)},o.prototype.writeFloatBE=function(t,e,r){return N(this,t,e,!1,r)},o.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},o.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},o.prototype.copy=function(t,e,r,n){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},o.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const s=o.isBuffer(t)?t:o.from(t,n),a=s.length;if(0===a)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,n,i,s){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(s+1)}${r}`:`>= -(2${r} ** ${8*(s+1)-1}${r}) and < 2 ** ${8*(s+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){H(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||j(e,t.length-(r+1))}(n,i,s)}function H(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function j(t,e,r){if(Math.floor(t)!==t)throw H(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=t.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function W(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function Y(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function J(t){return"undefined"==typeof BigInt?X:t}function X(){throw new Error("BigInt not supported")}}(vt);const Ct=new TextEncoder,Rt=new TextDecoder,Nt=Mt;function Mt(t,e=0){let r;if(void 0===t||"string"!=typeof t||"number"!=typeof e)throw TypeError("invlaid init variablie type name. ");return(t=t.toUpperCase()).includes("8")?(r=vt.Buffer.alloc(1),t.includes("I")?r.writeInt8(e):r.writeUint8(e)):t.includes("16")?(r=vt.Buffer.alloc(2),t.includes("I")?t.includes("L")?r.writeInt16LE(e):r.writeInt16BE(e):t.includes("L")?r.writeUint16LE(e):r.writeUint16BE(e)):t.includes("32")?(r=vt.Buffer.alloc(4),t.includes("I")?t.includes("L")?r.writeInt32LE(e):r.writeInt32BE(e):t.includes("L")?r.writeUint32LE(e):r.writeUint32BE(e)):t.includes("F")?(r=vt.Buffer.alloc(4),t.includes("L")?r.writeFloatLE(e):r.writeFloatBE(e)):t.includes("N")?r=vt.Buffer.from(String(e)):console.log(`invalid type: ${t} or initvalue: ${e}`),r}const Pt=Dt;function Dt(t,e,r){let n,i="B";if("number"==typeof e)"number"==typeof r?(n=vt.Buffer.alloc(e),0!==r&&n.fill(r),i="B"):(n=vt.Buffer.from(String(e)),i="N");else if("string"==typeof e&&"number"==typeof r)i=e.toUpperCase(),n=Mt(e,r);else if("string"==typeof e&&void 0===r)n=vt.Buffer.from(e),i="S";else if(e instanceof Uint8Array&&void 0===r)n=e instanceof vt.Buffer?e:vt.Buffer.from(e);else if(e instanceof ArrayBuffer&&void 0===r)n=vt.Buffer.from(e);else if(ArrayBuffer.isView(e))n=vt.Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if("object"==typeof e&&void 0===r)n=vt.Buffer.from(JSON.stringify(e)),i="O";else{if("boolean"!=typeof e||void 0!==r)throw TypeError("invalid meta buffer type");{const t=e?1:0;n=vt.Buffer.from([t]),i="!"}}return"string"==typeof t&&t.includes("#")&&(t=""),[t,i,n]}const $t=Ft;function Ft(...t){let e=0;return t.map((t=>{const r=e++;return"number"==typeof t?Pt(r,"N",t):Pt(r,t)}))}function Ht(t){if((t=t.toUpperCase()).includes("8"))return t.includes("I")?"int8":"uint8";if(t.includes("16"))return t.includes("I")?t.includes("L")?"int16_le":"int16_be":t.includes("L")?"uint16_le":"uint16_be";if(t.includes("32"))return t.includes("I")?t.includes("L")?"int32_le":"int32_be":t.includes("L")?"uint32_le":"uint32_be";if(t.includes("F"))return t.includes("L")?"float_le":"float_be";if("B"===t)return"buffer";if("S"===t)return"string";if("N"===t)return"number";if("O"===t)return"object";if("!"===t)return"boolean";throw TypeError("invalid data type")}function jt(t,e,r,n){try{const i=Ht(t);if("int8"==i)return e.readInt8(r);if("uint8"===i)return e.readUint8(r);if("int16_le"===i)return e.readInt16LE(r);if("int16_be"===i)return e.readInt16BE(r);if("uint16_le"===i)return e.readUint16LE(r);if("uint16_be"===i)return e.readUint16BE(r);if("int32_le"===i)return e.readInt32LE(r);if("int32_be"===i)return e.readInt32BE(r);if("uint32_le"===i)return e.readUint32LE(r);if("uint32_be"===i)return e.readUint32BE(r);if("float_le"===i)return e.readFloatLE(r);if("float_be"===i)return e.readFloatBE(r);if("buffer"===i)return e.subarray(r,r+n);if("string"===i){const t=e.subarray(r,r+n);return Rt.decode(t)}if("number"===i){const t=e.subarray(r,r+n);return Number(Rt.decode(t))}if("object"===i){const t=e.subarray(r,r+n);return JSON.parse(Rt.decode(t))}return"boolean"===i?1===e.readInt8(r):void 0}catch(t){}}function zt(...t){const e=function(t){let e=[];return t.filter((t=>{if(!Array.isArray(t[0]))return t;e=e.concat(t)})).concat(e)}(t);let r=0;const n=[];let i,s,o=0;if(e.forEach((t=>{const[e,i,s]=t;r+=s.byteLength,("number"==typeof e||e.length>0)&&n.push([e,i,o,s.byteLength]),o=r})),n.length>0){let t=JSON.stringify(n);i=Ct.encode(t),s=i.byteLength,r=r+s+2}const a=vt.Buffer.alloc(r);if(o=0,e.forEach((t=>{const e=t[2];a.set(e,o),o+=e.byteLength})),n.length>0){a.set(i,o);const t=Nt("16",s);return a.set(t,o+s),a}return a}const Gt=Wt;function Wt(t,e=!1){if(void 0===t)throw TypeError("Invalid data type: Undefined");if("string"==typeof t)return Ct.encode(t);if("number"==typeof t)return Uint8Array.from([t]);if(t instanceof ArrayBuffer){if(e)return new Uint8Array(t);{const e=new Uint8Array(t),r=new Uint8Array(t.byteLength);return r.set(e),r}}if(ArrayBuffer.isView(t)){if(e)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=new Uint8Array(t.byteLength);return r.set(e),r}}return Ct.encode(JSON.stringify(t))}const Vt=qt;function qt(t,e=!1){const r=Wt(t,e);return e?vt.Buffer.from(r.buffer,r.byteOffset,r.byteLength):vt.Buffer.from(r)}const Yt=Qt;function Qt(...t){const e=t.map((t=>qt(t)));return vt.Buffer.concat(e)}const Jt=Xt;function Xt(...t){try{let e=0,r=0;const n=t.map((t=>Wt(t)));n.forEach((t=>{e+=t.byteLength}));const i=new Uint8Array(e);return n.forEach((t=>{i.set(t,r),r+=t.byteLength})),i}catch(t){console.log(t)}}function Kt(t){return 0===re(t)?t.byteLength:t.byteLength-re(t)-te}function Zt(t,e){try{const r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=r.byteLength-e-2,i=r.subarray(n,r.byteLength-2),s=Rt.decode(i),o=JSON.parse(s);if(!Array.isArray(o)||!Array.isArray(o[0]))return;let a=o[0];if(!a)return;if(a.length<3)return;const[h,f,c]=a;if("string"!=typeof f||"number"!=typeof c)return;return o}catch(t){}}const te=2;function ee(t){return t instanceof ArrayBuffer&&(t=vt.Buffer.from(t)),t instanceof Uint8Array?t.byteLength<=te?0:new DataView(t.buffer,t.byteOffset,t.byteLength).getUint16(t.byteLength-te):0}function re(t){if(t instanceof ArrayBuffer&&(t=vt.Buffer.from(t)),t instanceof Uint8Array){const e=t.byteLength;if(e<=te)return 0;const r=ee(t);return 0===r||r>e?0:Zt(t,r)?r:0}return 0}function ne(t){const e=Kt(t);return t.subarray(0,e)}function ie(t,e=!1){t instanceof ArrayBuffer&&(t=vt.Buffer.from(t));const r=ee(t);if(0===r)return;let n=Zt(t,r);return n?e?(n.forEach((t=>{null==t[3]&&(t[1].includes("8")?t[3]=1:t[1].includes("16")?t[3]=2:t[1].includes("32")||t[1].includes("F")?t[3]=4:t[1].includes("!")&&(t[3]=1)),t[4]=Ht(t[1])})),n):n:void 0}var se=Object.freeze({__proto__:null,B8:Vt,B8pack:Yt,Buffer:vt.Buffer,MB:Pt,MBA:$t,NB:Nt,TAIL_LEN:te,U8:Gt,U8pack:Jt,equal:function(t,e){if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},getBuffer:ne,getBufferSize:Kt,getMeta:ie,getMetaDetail:function(t){return ie(t,!0)},getMetaSize:re,hex:function(t){return Array.prototype.map.call(new Uint8Array(t),(t=>("00"+t.toString(16)).slice(-2))).join("")},meta:function(...t){return ie(zt(...t))},metaBuffer:Dt,metaBufferArguments:Ft,metaDetail:function(...t){return ie(zt(...t),!0)},numberBuffer:Mt,pack:zt,parseBuffer:qt,parseBufferThenConcat:Qt,parseMetaInfo:Zt,parseTypeName:Ht,parseUint8Array:Wt,parseUint8ThenConcat:Xt,rawPack:function(...t){return ne(zt(...t))},readTail:ee,readTypedBuffer:jt,unpack:function(t,e){const r=e||ie(t);if(!r)return;const n=vt.Buffer.from(t),i={};let s=0;if(r.forEach((t=>{const[e,r,o,a]=t;let h=jt(r,n,o,a);null!=h&&(i[e]=h,a&&(s+=a))})),e&&n.byteLength!==s){let t=n.byteLength-s,e=jt("b",n,s,t);if(null==e)return;i.$OTHERS=e}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});const oe={hash:function(t){return Bt(se.U8(t))},hex:function(t){return se.B8(Bt(se.U8(t))).toString("hex")},base64:function(t){return se.B8(Bt(se.U8(t))).toString("base64")},hmac:function(t,e){return function(t,e){const r=new Et(t).update(e),n=r.digest();return r.clean(),n}(se.U8(t),se.U8(e))}};for(var ae={},he={byteLength:function(t){var e=de(t),r=e[0],n=e[1];return 3*(r+n)/4-n},toByteArray:function(t){var e,r,n=de(t),i=n[0],s=n[1],o=new ue(function(t,e,r){return 3*(e+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)e=ce[t.charCodeAt(r)]<<18|ce[t.charCodeAt(r+1)]<<12|ce[t.charCodeAt(r+2)]<<6|ce[t.charCodeAt(r+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=255&e;return 2===s&&(e=ce[t.charCodeAt(r)]<<2|ce[t.charCodeAt(r+1)]>>4,o[a++]=255&e),1===s&&(e=ce[t.charCodeAt(r)]<<10|ce[t.charCodeAt(r+1)]<<4|ce[t.charCodeAt(r+2)]>>2,o[a++]=e>>8&255,o[a++]=255&e),o},fromByteArray:function(t){for(var e,r=t.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(ge(t,o,o+s>a?a:o+s));return 1===n?(e=t[r-1],i.push(fe[e>>2]+fe[e<<4&63]+"==")):2===n&&(e=(t[r-2]<<8)+t[r-1],i.push(fe[e>>10]+fe[e>>4&63]+fe[e<<2&63]+"=")),i.join("")}},fe=[],ce=[],ue="undefined"!=typeof Uint8Array?Uint8Array:Array,le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",pe=0;pe<64;++pe)fe[pe]=le[pe],ce[le.charCodeAt(pe)]=pe;function de(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function ge(t,e,r){for(var n,i,s=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),s.push(fe[(i=n)>>18&63]+fe[i>>12&63]+fe[i>>6&63]+fe[63&i]);return s.join("")}ce["-".charCodeAt(0)]=62,ce["_".charCodeAt(0)]=63;var ye={
18
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
19
+ read:function(t,e,r,n,i){var s,o,a=8*i-n-1,h=(1<<a)-1,f=h>>1,c=-7,u=r?i-1:0,l=r?-1:1,p=t[e+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+t[e+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+t[e+u],u+=l,c-=8);if(0===s)s=1-f;else{if(s===h)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),s-=f}return(p?-1:1)*o*Math.pow(2,s-n)},write:function(t,e,r,n,i,s){var o,a,h,f=8*s-i-1,c=(1<<f)-1,u=c>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=c):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),(e+=o+u>=1?l/h:l*Math.pow(2,1-u))*h>=2&&(o++,h/=2),o+u>=c?(a=0,o=c):o+u>=1?(a=(e*h-1)*Math.pow(2,i),o+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;t[r+p]=255&o,p+=d,o/=256,f-=8);t[r+p-d]|=128*g}};
20
+ /*!
21
+ * The buffer module from node.js, for the browser.
22
+ *
23
+ * @author Feross Aboukhadijeh <https://feross.org>
24
+ * @license MIT
25
+ */!function(t){const e=he,r=ye,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(t){return+t!=t&&(t=0),o.alloc(+t)},t.INSPECT_MAX_BYTES=50;const i=2147483647;function s(t){if(t>i)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,o.prototype),e}function o(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return f(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|p(t,e);let n=s(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(q(t,Uint8Array)){const e=new Uint8Array(t);return u(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(q(t,ArrayBuffer)||t&&q(t.buffer,ArrayBuffer))return u(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(q(t,SharedArrayBuffer)||t&&q(t.buffer,SharedArrayBuffer)))return u(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return o.from(n,e,r);const i=function(t){if(o.isBuffer(t)){const e=0|l(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||Y(t.length)?s(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return o.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function f(t){return h(t),s(t<0?0:0|l(t))}function c(t){const e=t.length<0?0:0|l(t.length),r=s(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function u(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,o.prototype),n}function l(t){if(t>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|t}function p(t,e){if(o.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||q(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(i)return n?-1:G(t).length;e=(""+e).toLowerCase(),i=!0}}function d(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return I(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return L(this,e,r);case"base64":return v(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Y(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=o.from(e,n)),o.isBuffer(e))return 0===e.length?-1:m(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):m(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,r,n,i){let s,o=1,a=t.length,h=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(t,s)===f(e,-1===n?0:s-n)){if(-1===n&&(n=s),s-n+1===h)return n*o}else-1!==n&&(s-=s-n),n=-1}else for(r+h>a&&(r=a-h),s=r;s>=0;s--){let r=!0;for(let n=0;n<h;n++)if(f(t,s+n)!==f(e,n)){r=!1;break}if(r)return s}return-1}function _(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=e.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(e.substr(2*o,2),16);if(Y(n))return o;t[r+o]=n}return o}function b(t,e,r,n){return V(G(e,t.length-r),t,r,n)}function w(t,e,r,n){return V(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function E(t,e,r,n){return V(W(e),t,r,n)}function B(t,e,r,n){return V(function(t,e){let r,n,i;const s=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(e,t.length-r),t,r,n)}function v(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function S(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let s=null,o=e>239?4:e>223?3:e>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:e<128&&(s=e);break;case 2:r=t[i+1],128==(192&r)&&(h=(31&e)<<6|63&r,h>127&&(s=h));break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(h=(15&e)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=t[i+1],n=t[i+2],a=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,h>65535&&h<1114112&&(s=h))}}null===s?(s=65533,o=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=o}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=A));return r}(n)}t.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(t,e,r){return function(t,e,r){return h(t),t<=0?s(t):void 0!==e?"string"==typeof r?s(t).fill(e,r):s(t).fill(e):s(t)}(t,e,r)},o.allocUnsafe=function(t){return f(t)},o.allocUnsafeSlow=function(t){return f(t)},o.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==o.prototype},o.compare=function(t,e){if(q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return o.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=o.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(q(e,Uint8Array))i+e.length>n.length?(o.isBuffer(e)||(e=o.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!o.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},o.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},o.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},o.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?S(this,0,t):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===o.compare(this,t)},o.prototype.inspect=function(){let e="";const r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(t,e,r,n,i){if(q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=t.slice(e,r);for(let t=0;t<h;++t)if(f[t]!==c[t]){s=f[t],a=c[t];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},o.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},o.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},o.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":case"latin1":case"binary":return w(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function k(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function L(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function I(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=e;n<r;++n)i+=Q[t[n]];return i}function T(t,e,r){const n=t.slice(e,r);let i="";for(let t=0;t<n.length-1;t+=2)i+=String.fromCharCode(n[t]+256*n[t+1]);return i}function U(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function x(t,e,r,n,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function O(t,e,r,n,i){F(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,r}function C(t,e,r,n,i){F(e,n,i,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s>>=8,t[r+6]=s,s>>=8,t[r+5]=s,s>>=8,t[r+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=o,o>>=8,t[r+2]=o,o>>=8,t[r+1]=o,o>>=8,t[r]=o,r+8}function R(t,e,r,n,i,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(t,e,n,i,s){return e=+e,n>>>=0,s||R(t,0,n,4),r.write(t,e,n,i,23,4),n+4}function M(t,e,n,i,s){return e=+e,n>>>=0,s||R(t,0,n,8),r.write(t,e,n,i,52,8),n+8}o.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readBigUInt64LE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=this[t],i=1,s=0;for(;++s<e&&(i*=256);)n+=this[t+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*e)),n},o.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let n=e,i=1,s=this[t+--n];for(;n>0&&(i*=256);)s+=this[t+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*e)),s},o.prototype.readInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readBigInt64LE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),o.prototype.readBigInt64BE=J((function(t){H(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||j(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),o.prototype.readFloatLE=function(t,e){return t>>>=0,e||U(t,4,this.length),r.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return t>>>=0,e||U(t,4,this.length),r.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return t>>>=0,e||U(t,8,this.length),r.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return t>>>=0,e||U(t,8,this.length),r.read(this,t,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||x(this,t,e,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[e]=255&t;++s<r&&(i*=256);)this[e+s]=t/i&255;return e+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||x(this,t,e,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,1,255,0),this[e]=255&t,e+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigUInt64LE=J((function(t,e=0){return O(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,t,e,r,n-1,-n)}let i=0,s=1,o=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===o&&0!==this[e+i-1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,t,e,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===o&&0!==this[e+i+1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+r},o.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},o.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigInt64LE=J((function(t,e=0){return O(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(t,e,r){return N(this,t,e,!0,r)},o.prototype.writeFloatBE=function(t,e,r){return N(this,t,e,!1,r)},o.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},o.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},o.prototype.copy=function(t,e,r,n){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},o.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const s=o.isBuffer(t)?t:o.from(t,n),a=s.length;if(0===a)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=s[i%a]}return this};const P={};function D(t,e,r){P[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function $(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,n,i,s){if(t>r||t<e){const r="bigint"==typeof e?"n":"";let n;throw n=0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(s+1)}${r}`:`>= -(2${r} ** ${8*(s+1)-1}${r}) and < 2 ** ${8*(s+1)-1}${r}`,new P.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){H(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||j(e,t.length-(r+1))}(n,i,s)}function H(t,e){if("number"!=typeof t)throw new P.ERR_INVALID_ARG_TYPE(e,"number",t)}function j(t,e,r){if(Math.floor(t)!==t)throw H(t,r),new P.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=$(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function G(t,e){let r;e=e||1/0;const n=t.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=t.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function W(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function q(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function Y(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)e[n+i]=t[r]+t[i]}return e}();function J(t){return"undefined"==typeof BigInt?X:t}function X(){throw new Error("BigInt not supported")}}(ae);let me={AUTH_REQ:176,AUTH_NONCE:177,AUTH_HMAC:178,AUTH_ACK:179,AUTH_FAIL:180,AUTH_EXT:181,ENC_PACK:182,ENC_E2E:183,ENC_488:184};for(let t in me)me[me[t]]=t;const _e={AUTH_REQ:se.meta(se.MB("header","8",0),se.MB("reserved","8",0)),AUTH_NONCE:se.meta(se.MB("header","8",0),se.MB("unixTime","32L",0),se.MB("milTime","32L",0),se.MB("nonce",ae.Buffer.alloc(4))),AUTH_HMAC:se.meta(se.MB("header","8",0),se.MB("id8",ae.Buffer.alloc(8)),se.MB("nonce",ae.Buffer.alloc(4)),se.MB("hmac32",ae.Buffer.alloc(32))),AUTH_ACK:se.meta(se.MB("header","8",0),se.MB("hmac32",ae.Buffer.alloc(32))),ENC_PACK:se.meta(se.MB("type","8",0),se.MB("len","32L",0),se.MB("salt12",ae.Buffer.alloc(12)),se.MB("hmac",8,0)),ENC_488:se.meta(se.MB("type","8",0),se.MB("len","32L",0),se.MB("otpSrc8",ae.Buffer.alloc(8)),se.MB("hmac8",ae.Buffer.alloc(8)))};function be(t){let e=t[t.length-1];return e[2]+e[3]}const we={AUTH_REQ:be(_e.AUTH_REQ),AUTH_NONCE:be(_e.AUTH_NONCE),AUTH_HMAC:be(_e.AUTH_HMAC),AUTH_ACK:be(_e.AUTH_ACK),ENC_PACK:be(_e.ENC_PACK),ENC_488:be(_e.ENC_488)};function Ee(t){return globalThis.crypto.getRandomValues(ae.Buffer.alloc(t))}class Be{constructor(){this._id8=ae.Buffer.alloc(8),this._otpSrc44=ae.Buffer.alloc(44),this._otp36=ae.Buffer.alloc(36),this._hmac=ae.Buffer.alloc(32),this.auth_salt12=ae.Buffer.alloc(12),this.localNonce=ae.Buffer.alloc(4),this.remoteNonce=ae.Buffer.alloc(4),this.isAuthorized=!1}clearAuth(){this._id8.fill(0),this._otpSrc44.fill(0),this._otp36.fill(0),this._hmac.fill(0),this.auth_salt12.fill(0),this.localNonce.fill(0),this.remoteNonce.fill(0),this.isAuthorized=!1}set_hash_id8(t){se.B8(oe.hash(t)).copy(this._id8,0,0,8)}set_id8(t){let e=se.B8(t);this._id8.fill(0),e.copy(this._id8,0,0,8)}set_key(t){se.B8(oe.hash(t)).copy(this._otpSrc44,0,0,32)}set_id_key(t){let e=t.indexOf(".");if(-1==e)return;let r=t.substring(0,e),n=t.substring(e+1);this.set_id8(r),this.set_key(n)}copy_id8(t){t.copy(this._id8,0,0,8)}copy_key(t){t.copy(this._otpSrc44,0,0,32)}sha256_n(t,e){let r=oe.hash(t);for(let t=0;t<e;t++)r=oe.hash(r);return r}set_clock_rand(){let t=Date.now(),e=parseInt(t/1e3);t%=4294967295,ae.Buffer.concat([se.NB("32L",e),se.NB("32L",t),Ee(4)]).copy(this._otpSrc44,32)}set_clock_nonce(t){let e=Date.now(),r=parseInt(e/1e3);e%=4294967295,ae.Buffer.concat([se.NB("32L",r),se.NB("32L",e),t]).copy(this._otpSrc44,32)}set_salt12(t){t.copy(this._otpSrc44,32)}resetOTP(){se.B8(oe.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(t){return this._otp36.writeUInt32LE(t,32),oe.hash(this._otp36)}generateHMAC(t){let e=ae.Buffer.concat([this._otpSrc44,t]);this._hmac=se.B8(oe.hash(e))}getHMAC8(t){let e=ae.Buffer.concat([this._otpSrc44,t]);return this._hmac=se.B8(oe.hash(e)),this._hmac.subarray(0,8)}xotp(t,e=0,r=!1){let n=(t=se.B8(t,r)).byteLength,i=e,s=0,o=0;for(;n>0;){o=n<32?n:32;let e=this.getIndexOTP(++i);for(let r=0;r<o;r++)t[s++]^=e[r];n-=32}return t}auth_req(){return se.pack(se.MB("#type","8",me.AUTH_REQ),se.MB("#reserved","8",0))}auth_nonce(){let t=Date.now(),e=Math.floor(t/1e3),r=t%1e3;return this.localNonce=Ee(4),this.auth_salt12=ae.Buffer.concat([se.NB("32L",e),se.NB("32L",r),this.localNonce]),ae.Buffer.concat([se.NB("8",me.AUTH_NONCE),this.auth_salt12])}auth_hmac(t){let e=se.unpack(t,_e.AUTH_NONCE);if(e){let t=ae.Buffer.concat([se.NB("32L",e.unixTime),se.NB("32L",e.milTime),e.nonce]);return this.set_salt12(t),this.localNonce=Ee(4),this.generateHMAC(this.localNonce),this.remoteNonce=e.nonce,se.pack(se.MB("#header","8",me.AUTH_HMAC),se.MB("#id8",this._id8),se.MB("#nonce",this.localNonce),se.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(t){let e;if(t instanceof Uint8Array){if(e=se.unpack(t,_e.AUTH_HMAC),!e)return}else e=t;this.set_salt12(this.auth_salt12),this.generateHMAC(e.nonce);let r=this._hmac;if(se.equal(e.hmac32,r)){this.remoteNonce=e.nonce;let t=ae.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(t),this.generateHMAC(e.nonce);let r=this._hmac,n=se.rawPack(se.MB("header","8",me.AUTH_ACK),se.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(t){let e=se.unpack(t,_e.AUTH_ACK);if(e){let t=ae.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(t),this.generateHMAC(this.localNonce);let r=this._hmac;if(se.equal(r,e.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(t){if(!this.isAuthorized)return;t=se.B8(t),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return se.pack(se.MB("#type","8",me.ENC_488),se.MB("#len","32L",t.byteLength),se.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),se.MB("#hmac8",e),se.MB("#xdata",r))}decrypt_488(t){t=se.B8(t);let e=se.unpack(t,_e.ENC_488);if(e){let t=ae.Buffer.concat([e.otpSrc8,this.localNonce]);this.set_salt12(t),this.resetOTP();let r=e.$OTHERS.subarray(0,e.len),n=this.xotp(r),i=this.getHMAC8(n);if(se.equal(i,e.hmac8))return n}}encryptPack(t){t=se.B8(t),this.set_clock_rand(),this.resetOTP();let e=this.getHMAC8(t),r=this.xotp(t);return se.pack(se.MB("#type","8",me.ENC_PACK),se.MB("#len","32L",t.byteLength),se.MB("#salt12",this._otpSrc44.subarray(32)),se.MB("#hmac8",e),se.MB("#xdata",r))}decryptPack(t){if(t[0]===me.ENC_PACK&&t.readUint32LE(1)==t.byteLength-we.ENC_PACK)try{let e=se.unpack(t,_e.ENC_PACK);if(!e)return;this.set_salt12(e.salt12),this.resetOTP();let r=e.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(se.equal(e.hmac,i))return e.data=n,e}catch(t){}}encrypt_e2e(t,e){let r=ae.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.encryptPack(t);return this._otpSrc44.set(r),n}decrypt_e2e(t,e){let r=ae.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(e);let n=this.decryptPack(t);return this._otpSrc44.set(r),n}}Be.RAND=Ee,Be.BohoMsg=me,Be.Meta=_e,Be.MetaSize=we,Be.sha256=oe,Be.MBP=se,Be.Buffer=ae.Buffer;const ve=Z.Buffer,Se=new TextEncoder,Ae=new TextDecoder;class ke extends it{constructor(t){super(),this.cid="",this.ip="",this.socket=null,this.url=t,this.state=st.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=ht.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new Be,this.TLS=!1,this.encMode=at.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=ht.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=pt[this.level],this.serverSet={},this.linkMap=new Map,this.on("open",this.onOpen.bind(this)),this.on("close",this.onClose.bind(this)),this.on("socket_data",this.onData.bind(this))}redirect(t){this.close(),this.stateChange("redirecting"),this.createConnection(t)}open(t){if(t||this.url){if(t)if(this.url){if(t!==this.url&&(this.url=t,this.socket))return void this.close()}else this.url=t;this.createConnection(this.url),this.connectionCheckerIntervalID||(this.connectionCheckerIntervalID=setInterval(this.keepAlive.bind(this),this.connectionCheckerPeriod))}}onOpen(){this.url.includes("wss://")?this.TLS=!0:this.TLS=!1,this.stateChange("open")}onClose(){this.boho.isAuthorized=!1,this.cid="",this.stateChange("closed")}login(t,e){if(!t&&!e)return void console.log("no id and key.");if(console.log("manual login: ",t),!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return void console.log("no id or key.");this.boho.set_id8(t),this.boho.set_key(e)}this.useAuth=!0;let r=this.boho.auth_req();this.send(r)}auth(t,e){if(t||e){if(!e&&t.includes("."))this.boho.set_id_key(t);else{if(!t||!e)return void console.log("no id or key.");this.boho.set_id8(t),this.boho.set_key(e)}this.useAuth=!0}else console.log("no id and key.")}onData(t){let e,r=t[0];if(r===Be.BohoMsg.ENC_488)e=this.boho.decrypt_488(t),e&&(r=e[0],t=e);else if(r===Be.BohoMsg.ENC_E2E)try{if(e=this.boho.decrypt_488(t),!e)return;r=e[0],t.set(e,Be.MetaSize.ENC_488),t=t.subarray(Be.MetaSize.ENC_488)}catch(t){return}let n=ct[r];switch(n||(n=Be.BohoMsg[r]),r){case ct.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case ct.PING:this.pong();break;case ct.PONG:break;case ct.IAM_RES:try{let e=Ae.decode(t.subarray(1)),r=JSON.parse(e);r.ip&&(this.ip=r.ip),console.log("<IAM_RES>",JSON.stringify(r))}catch(t){}break;case ct.CID_RES:let r=Ae.decode(t.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case ct.QUOTA_LEVEL:let n=t[1];this.level=n,this.quota=pt[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case ct.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case ct.SERVER_REDIRECT:let i,s,o;7==t.byteLength?(i=function(t){if(6!=t.byteLength)return;return t[0].toString()+"."+t[1].toString()+"."+t[2].toString()+"."+t[3].toString()+":"+((t[4]<<8)+t[5]).toString()}(t.subarray(1)),o="cong://"):(i=Ae.decode(t.subarray(1)),o=""),s=o+i,this.redirect(s);break;case ct.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(ve.from([ct.CID_REQ]));break;case ct.SERVER_SIGNAL:try{let e=Ae.decode(t.subarray(1)),r=JSON.parse(e);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(t){}break;case ct.SET:try{let e=Z.unpack(t);e&&this.emit(e.topic,...e.args)}catch(t){}break;case ct.SIGNAL_E2E:case ct.SIGNAL:try{let e=t.readUint8(1),r=t.subarray(2,2+e),n=Ae.decode(r),i=t.readUint8(2+e),s=t.subarray(3+e);switch(i){case ft.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case ft.TEXT:let t=s.subarray(0,s.byteLength-1),e=Ae.decode(t);0===n.indexOf("@")&&this.emit("@",e,n),"@"!==n&&this.emit(n,e,n);break;case ft.BINARY:0===n.indexOf("@")&&this.emit("@",s,n),"@"!==n&&this.emit(n,s,n);break;case ft.OBJECT:let r=Ae.decode(s),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case ft.MJSON:let o=Ae.decode(s),a=JSON.parse(o);0===n.indexOf("@")&&this.emit("@",...a,n),"@"!==n&&this.emit(n,...a,n);break;case ft.MBA:let h=Z.unpack(s);0===n.indexOf("@")&&this.emit("@",...h.args,n),"@"!==n&&this.emit(n,...h.args,n)}}catch(t){}break;case ct.RESPONSE_MBP:this.testPromise(t);break;case Be.BohoMsg.AUTH_NONCE:let a=this.boho.auth_hmac(t);a?this.send(a):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case Be.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case Be.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(t)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(ve.from([ct.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{e=Ae.decode(t),this.emit("text_message",e)}catch(t){}}}iam(t){t?this.send_enc_mode(Z.pack(Z.MB("#MsgType","8",ct.IAM),Z.MB("#",t))):this.send_enc_mode(Z.pack(Z.MB("#MsgType","8",ct.IAM)))}ping(){this.send(ve.from([ct.PING]))}pong(){this.send(ve.from([ct.PONG]))}echo(t){t?(console.log("echo args:",t),this.send_enc_mode(Z.pack(Z.MB("#MsgType","8",ct.ECHO),Z.MB("#msg",t)))):this.send(ve.from([ct.ECHO]))}bin(...t){this.send(Z.U8pack(...t))}send(t){if(t.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",t.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(t)}getEncryptionMode(){return!(this.encMode!==at.YES&&(this.encMode!==at.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(t,e){if(void 0===e&&(e=this.getEncryptionMode()),t[0]==ct.SIGNAL_E2E&&e){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Be.BohoMsg.ENC_E2E,this.send(ve.concat([r,t.subarray(3+e)]))}else if(e){let e=this.boho.encrypt_488(t);this.send(e)}else this.send(t)}setMsgPromise(t){return new Promise(((e,r)=>{this.promiseMap.set(t,[e,r]),setTimeout((e=>{this.promiseMap.has(t)&&(r("timeout"),this.promiseMap.delete(t))}),this.promiseTimeOut)}))}testPromise(t){let e=Z.unpack(t);if(e)if(this.promiseMap.has(e.mid)){let[t,r]=this.promiseMap.get(e.mid);this.promiseMap.delete(e.mid),e.status<128?(e.ok=!0,t(e)):(e.ok=!1,r(e))}else console.log("no promise id")}publish(...t){this.signal(...t)}signal(t,...e){if("string"!=typeof t)throw TypeError("tag should be string.");let r=gt(t,...e);this.send_enc_mode(r)}decrypt_e2e(t,e){return this.boho.decrypt_e2e(t,e)}signal_e2e(t,e,r){if("string"!=typeof t)throw TypeError("tag should be string.");let n=Se.encode(t),i=Z.B8(e),s=this.boho.encrypt_e2e(i,r),o=Z.pack(Z.MB("#MsgType","8",ct.SIGNAL_E2E),Z.MB("#tagLen","8",n.byteLength),Z.MB("#tag",n),Z.MB("#payloadType","8",ft.BINARY),Z.MB("#payload",s));this.send_enc_mode(o)}set(t,...e){return t&&0!=e.length?this.req("store","set",t,...e):Promise.reject(new Error("set need storeName and value)"))}async get(t){if(!t)return Promise.reject(new Error("store get need storeName)"));let e=await this.req("store","get",t),{$:r}=Z.unpack(e.body);return r}req(t,e,...r){if(!t||!e)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?Z.pack(Z.MB("#MsgType","8",ct.REQUEST),Z.MB("mid","16",++this.mid),Z.MB("target",t),Z.MB("topic",e),Z.MBA(...r)):Z.pack(Z.MB("#MsgType","8",ct.REQUEST),Z.MB("mid","16",++this.mid),Z.MB("target",t),Z.MB("topic",e)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==st.READY)return;t.split(",").forEach((t=>{this.channels.add(t)}));let e=Se.encode(t);if(e.byteLength>ht.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+ht.TAG_LEN1);this.send_enc_mode(ve.concat([Z.NB("8",ct.SUBSCRIBE),Z.NB("8",e.byteLength),e]))}subscribe_promise(t){if("string"!=typeof t)throw TypeError("tag should be string.");if(this.state!==st.READY)return Promise.reject("subscribe_promise:: connection is not ready");let e=Se.encode(t);if(e.byteLength>ht.TAG_LEN2)throw TypeError("please use tag string bytelength: "+ht.TAG_LEN2);return this.send_enc_mode(ve.concat([Z.NB("8",ct.SUBSCRIBE_REQ),Z.NB("16",++this.mid),Z.NB("16",e.byteLength),e])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let t=Array.from(this.channels).join(",");this.subscribe_promise(t).then((t=>{})).catch((t=>{console.log(">> SUBSCRIBE FAIL:",t)}))}unsubscribe(t=""){if("string"!=typeof t)throw TypeError("tag should be string.");if(""==t)this.channels.clear();else{t.split(",").forEach((t=>{this.channels.delete(t)}))}let e=Se.encode(t);if(e.byteLength>ht.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+ht.TAG_LEN1);this.send_enc_mode(ve.concat([Z.NB("8",ct.UNSUBSCRIBE),Z.NB("8",e.byteLength),e]))}listen(t,e){if("string"!=typeof t)throw TypeError("tag should be string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof e)throw TypeError("handler is not a function.");0!==t.indexOf("@")&&this.channels.add(t),this.on(t,e)}link(t,e,r){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==e.indexOf("@")&&this.channels.add(e),n=this.linkMap.has(t)?this.linkMap.get(t):new Set,n.add(e),this.linkMap.set(t,n),this.on(e,r),this.subscribe(e)}unlink(t,e){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if("string"!=typeof e)throw TypeError("tag is not a string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if(!this.linkMap.has(t))return;let r=this.linkMap.get(t),n=Array.from(r);for(let i=0;i<n.length;i++)if(n[i]==e){this.unsubscribe(e),this.removeAllListeners(e),r.delete(e),this.linkMap.set(t,r);break}}unlinkAll(t){if("string"!=typeof t)throw TypeError("to(local link target) is not a string.");if(!this.linkMap.has(t))return;let e=this.linkMap.get(t),r=Array.from(e);for(let t=0;t<r.length;t++)this.unsubscribe(r[t]),this.removeAllListeners(r[t]),e.delete(r[t]);this.linkMap.delete(t)}getMetric(){return{tx:this.txCounter,rx:this.rxCounter,txb:this.txBytes,rxb:this.rxBytes,last:(Date.now()-this.lastTxRxTime)/1e3}}getState(){return this.state}getStateName(){return st[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(t,e){let r=t.toLowerCase();this.state=st[t.toUpperCase()],e&&this.emit(r,e),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const Le=1,Ie=2,Te=3,Ue=4;function xe(t){if(t.byteLength<256)return Z.pack(Z.MB("#type","8",Le),Z.MB("#payloadLen1","8",t.byteLength),Z.MB("#payload",t));if(t.byteLength<65536)return Z.pack(Z.MB("#type","8",Ie),Z.MB("#payloadLen2","16L",t.byteLength),Z.MB("#payload",t));if(t.byteLength<2**24){let e=Buffer.alloc(4);e.writeUint32LE(t.byteLength);let r=e.subarray(0,3);return Z.pack(Z.MB("#type","8",Te),Z.MB("#payloadLen3",r),Z.MB("#payload",t))}return Z.pack(Z.MB("#type","8",Ue),Z.MB("#payloadLen4","32L",t.byteLength),Z.MB("#payload",t))}class Oe extends e{constructor(t){super(t),this.buffer=Buffer.alloc(0),this.frames=[],this.rxi=0,this.rxi_zero=0}_transform(t,e,r){this.addData(t),this.frames.length>0&&(this.frames.forEach((t=>{this.push(t)})),this.frames=[]),r()}addData(t){let e=t.byteLength,r=0;for(;e--;)this.rxi++,0==t[r++]&&this.rxi_zero++;this.buffer.byteLength>0?this.buffer=Buffer.concat([this.buffer,t]):this.buffer=t,this.parse()}parse(){let t,e,r=this.buffer[0];if(r==Le){if(t=2,this.buffer.byteLength<t)return;e=this.buffer.readUint8(1)}else if(r==Ie){if(t=3,this.buffer.byteLength<t)return;e=this.buffer.readUint16LE(1)}else if(r==Te){if(t=4,this.buffer.byteLength<t)return;e=this.buffer.readUint16LE(1)+65536*this.buffer.readUint8(3)}else if(r==Ue){if(t=5,this.buffer.byteLength<t)return;e=this.buffer.readUint32LE(1)}else this.emit("wrong",this.buffer),this.buffer=Buffer.alloc(0);if(e==this.buffer.byteLength-t)return this.frames.push(this.buffer.subarray(t)),void(this.buffer=Buffer.alloc(0));e<this.buffer.byteLength-t&&(this.frames.push(this.buffer.subarray(t,t+e)),this.buffer=this.buffer.subarray(t+e),this.parse())}}class Ce extends ke{constructor(t){super(t),t&&this.open()}close(){this.socket?.end(),this.socket=null}stop(){this.close(),clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null}keepAlive(){let t=this.socket?.readyState;(!this.socket||"open"!==t&&"opening"!==t)&&this.open()}createConnection(t){let e=new URL(t);"cong:"!=e.protocol&&(e=new URL("cong://"+t)),this.socket=r.createConnection(e.port,e.hostname),this.stateChange("opening"),this.socket.on("connect",(()=>{this.congRx=new Oe,this.socket.pipe(this.congRx),this.congRx.on("data",this.onTCPSocketMessage.bind(this)),this.emit("open")})),this.socket.on("error",(t=>{this.emit("error",t)})),this.socket.on("close",(()=>{this.emit("close")}))}onTCPSocketMessage(t){this.rxCounter++,this.rxBytes+=t.byteLength,this.lastTxRxTime=Date.now(),this.emit("socket_data",t)}socket_send(t){if("open"===this.socket?.readyState){let e=xe(t);this.socket.write(e),this.txCounter++,this.txBytes+=e.byteLength,this.lastTxRxTime=Date.now()}else console.log(".")}}var Re,Ne,Me={exports:{}};function Pe(){if(Ne)return Re;Ne=1;const t=["nodebuffer","arraybuffer","fragments"],e="undefined"!=typeof Blob;return e&&t.push("blob"),Re={BINARY_TYPES:t,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:e,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}}var De={exports:{}};function $e(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Fe,He,je,ze,Ge,We,Ve,qe,Ye,Qe,Je,Xe={exports:{}};function Ke(){if(je)return Xe.exports;je=1;const t="function"==typeof __webpack_require__?__non_webpack_require__:$e;return"function"==typeof t.addon?Xe.exports=t.addon.bind(t):Xe.exports=function(){if(He)return Fe;He=1;var t=i,e=o,r=a,n="function"==typeof __webpack_require__?__non_webpack_require__:$e,s=process.config&&process.config.variables||{},h=!!process.env.PREBUILDS_ONLY,f=process.versions.modules,c=process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE||"undefined"!=typeof window&&window.process&&"renderer"===window.process.type?"electron":process.versions&&process.versions.nw?"node-webkit":"node",u=process.env.npm_config_arch||r.arch(),l=process.env.npm_config_platform||r.platform(),p=process.env.LIBC||(function(e){return"linux"===e&&t.existsSync("/etc/alpine-release")}(l)?"musl":"glibc"),d=process.env.ARM_VERSION||("arm64"===u?"8":s.arm_version)||"",g=(process.versions.uv||"").split(".")[0];function y(t){return n(y.resolve(t))}function m(e){try{return t.readdirSync(e)}catch(t){return[]}}function _(t,r){var n=m(t).filter(r);return n[0]&&e.join(t,n[0])}function b(t){return/\.node$/.test(t)}function w(t){var e=t.split("-");if(2===e.length){var r=e[0],n=e[1].split("+");if(r&&n.length&&n.every(Boolean))return{name:t,platform:r,architectures:n}}}function E(t,e){return function(r){return null!=r&&r.platform===t&&r.architectures.includes(e)}}function B(t,e){return t.architectures.length-e.architectures.length}function v(t){var e=t.split("."),r={file:t,specificity:0};if("node"===e.pop()){for(var n=0;n<e.length;n++){var i=e[n];if("node"===i||"electron"===i||"node-webkit"===i)r.runtime=i;else if("napi"===i)r.napi=!0;else if("abi"===i.slice(0,3))r.abi=i.slice(3);else if("uv"===i.slice(0,2))r.uv=i.slice(2);else if("armv"===i.slice(0,4))r.armv=i.slice(4);else{if("glibc"!==i&&"musl"!==i)continue;r.libc=i}r.specificity++}return r}}function S(t,e){return function(r){return!(null==r||r.runtime&&r.runtime!==t&&!function(t){return"node"===t.runtime&&t.napi}(r)||r.abi&&r.abi!==e&&!r.napi||r.uv&&r.uv!==g||r.armv&&r.armv!==d||r.libc&&r.libc!==p)}}function A(t){return function(e,r){return e.runtime!==r.runtime?e.runtime===t?-1:1:e.abi!==r.abi?e.abi?-1:1:e.specificity!==r.specificity?e.specificity>r.specificity?-1:1:0}}return Fe=y,y.resolve=y.path=function(t){t=e.resolve(t||".");try{var r=n(e.join(t,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[r+"_PREBUILD"]&&(t=process.env[r+"_PREBUILD"])}catch(t){}if(!h){var i=_(e.join(t,"build/Release"),b);if(i)return i;var s=_(e.join(t,"build/Debug"),b);if(s)return s}var o=k(t);if(o)return o;var a=k(e.dirname(process.execPath));if(a)return a;var y=["platform="+l,"arch="+u,"runtime="+c,"abi="+f,"uv="+g,d?"armv="+d:"","libc="+p,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"","function"==typeof __webpack_require__?"webpack=true":""].filter(Boolean).join(" ");throw new Error("No native build was found for "+y+"\n loaded from: "+t+"\n");function k(t){var r=m(e.join(t,"prebuilds")).map(w).filter(E(l,u)).sort(B)[0];if(r){var n=e.join(t,"prebuilds",r.name),i=m(n).map(v).filter(S(c,f)).sort(A(c))[0];return i?e.join(n,i.file):void 0}}},y.parseTags=v,y.matchTags=S,y.compareTags=A,y.parseTuple=w,y.matchTuple=E,y.compareTuples=B,Fe}(),Xe.exports}function Ze(){if(We)return De.exports;We=1;try{De.exports=Ke()(__dirname)}catch(t){De.exports=(Ge||(Ge=1,ze={mask:(t,e,r,n,i)=>{for(var s=0;s<i;s++)r[n+s]=t[s]^e[3&s]},unmask:(t,e)=>{const r=t.length;for(var n=0;n<r;n++)t[n]^=e[3&n]}}),ze)}return De.exports}function tr(){if(Ve)return Me.exports;Ve=1;const{EMPTY_BUFFER:t}=Pe(),e=Buffer[Symbol.species];function r(t,e,r,n,i){for(let s=0;s<i;s++)r[n+s]=t[s]^e[3&s]}function n(t,e){for(let r=0;r<t.length;r++)t[r]^=e[3&r]}if(Me.exports={concat:function(r,n){if(0===r.length)return t;if(1===r.length)return r[0];const i=Buffer.allocUnsafe(n);let s=0;for(let t=0;t<r.length;t++){const e=r[t];i.set(e,s),s+=e.length}return s<n?new e(i.buffer,i.byteOffset,s):i},mask:r,toArrayBuffer:function(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)},toBuffer:function t(r){if(t.readOnly=!0,Buffer.isBuffer(r))return r;let n;return r instanceof ArrayBuffer?n=new e(r):ArrayBuffer.isView(r)?n=new e(r.buffer,r.byteOffset,r.byteLength):(n=Buffer.from(r),t.readOnly=!1),n},unmask:n},!process.env.WS_NO_BUFFER_UTIL)try{const t=Ze();Me.exports.mask=function(e,n,i,s,o){o<48?r(e,n,i,s,o):t.mask(e,n,i,s,o)},Me.exports.unmask=function(e,r){e.length<32?n(e,r):t.unmask(e,r)}}catch(t){}return Me.exports}function er(){if(Je)return Qe;Je=1;const t=n,e=tr(),r=function(){if(Ye)return qe;Ye=1;const t=Symbol("kDone"),e=Symbol("kRun");return qe=class{constructor(r){this[t]=()=>{this.pending--,this[e]()},this.concurrency=r||1/0,this.jobs=[],this.pending=0}add(t){this.jobs.push(t),this[e]()}[e](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[t])}}}}(),{kStatusCode:i}=Pe(),s=Buffer[Symbol.species],o=Buffer.from([0,0,255,255]),a=Symbol("permessage-deflate"),h=Symbol("total-length"),f=Symbol("callback"),c=Symbol("buffers"),u=Symbol("error");let l;function p(t){this[c].push(t),this[h]+=t.length}function d(t){this[h]+=t.length,this[a]._maxPayload<1||this[h]<=this[a]._maxPayload?this[c].push(t):(this[u]=new RangeError("Max payload size exceeded"),this[u].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[u][i]=1009,this.removeListener("data",d),this.reset())}function g(t){this[a]._inflate=null,t[i]=1007,this[f](t)}return Qe=class{constructor(t,e,n){if(this._maxPayload=0|n,this._options=t||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!e,this._deflate=null,this._inflate=null,this.params=null,!l){const t=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;l=new r(t)}}static get extensionName(){return"permessage-deflate"}offer(){const t={};return this._options.serverNoContextTakeover&&(t.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(t.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(t.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?t.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(t.client_max_window_bits=!0),t}accept(t){return t=this.normalizeParams(t),this.params=this._isServer?this.acceptAsServer(t):this.acceptAsClient(t),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const t=this._deflate[f];this._deflate.close(),this._deflate=null,t&&t(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(t){const e=this._options,r=t.find((t=>!(!1===e.serverNoContextTakeover&&t.server_no_context_takeover||t.server_max_window_bits&&(!1===e.serverMaxWindowBits||"number"==typeof e.serverMaxWindowBits&&e.serverMaxWindowBits>t.server_max_window_bits)||"number"==typeof e.clientMaxWindowBits&&!t.client_max_window_bits)));if(!r)throw new Error("None of the extension offers can be accepted");return e.serverNoContextTakeover&&(r.server_no_context_takeover=!0),e.clientNoContextTakeover&&(r.client_no_context_takeover=!0),"number"==typeof e.serverMaxWindowBits&&(r.server_max_window_bits=e.serverMaxWindowBits),"number"==typeof e.clientMaxWindowBits?r.client_max_window_bits=e.clientMaxWindowBits:!0!==r.client_max_window_bits&&!1!==e.clientMaxWindowBits||delete r.client_max_window_bits,r}acceptAsClient(t){const e=t[0];if(!1===this._options.clientNoContextTakeover&&e.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(e.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&e.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(e.client_max_window_bits=this._options.clientMaxWindowBits);return e}normalizeParams(t){return t.forEach((t=>{Object.keys(t).forEach((e=>{let r=t[e];if(r.length>1)throw new Error(`Parameter "${e}" must have only a single value`);if(r=r[0],"client_max_window_bits"===e){if(!0!==r){const t=+r;if(!Number.isInteger(t)||t<8||t>15)throw new TypeError(`Invalid value for parameter "${e}": ${r}`);r=t}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${e}": ${r}`)}else if("server_max_window_bits"===e){const t=+r;if(!Number.isInteger(t)||t<8||t>15)throw new TypeError(`Invalid value for parameter "${e}": ${r}`);r=t}else{if("client_no_context_takeover"!==e&&"server_no_context_takeover"!==e)throw new Error(`Unknown parameter "${e}"`);if(!0!==r)throw new TypeError(`Invalid value for parameter "${e}": ${r}`)}t[e]=r}))})),t}decompress(t,e,r){l.add((n=>{this._decompress(t,e,((t,e)=>{n(),r(t,e)}))}))}compress(t,e,r){l.add((n=>{this._compress(t,e,((t,e)=>{n(),r(t,e)}))}))}_decompress(r,n,i){const s=this._isServer?"client":"server";if(!this._inflate){const e=`${s}_max_window_bits`,r="number"!=typeof this.params[e]?t.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=t.createInflateRaw({...this._options.zlibInflateOptions,windowBits:r}),this._inflate[a]=this,this._inflate[h]=0,this._inflate[c]=[],this._inflate.on("error",g),this._inflate.on("data",d)}this._inflate[f]=i,this._inflate.write(r),n&&this._inflate.write(o),this._inflate.flush((()=>{const t=this._inflate[u];if(t)return this._inflate.close(),this._inflate=null,void i(t);const r=e.concat(this._inflate[c],this._inflate[h]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[h]=0,this._inflate[c]=[],n&&this.params[`${s}_no_context_takeover`]&&this._inflate.reset()),i(null,r)}))}_compress(r,n,i){const o=this._isServer?"server":"client";if(!this._deflate){const e=`${o}_max_window_bits`,r="number"!=typeof this.params[e]?t.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=t.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:r}),this._deflate[h]=0,this._deflate[c]=[],this._deflate.on("data",p)}this._deflate[f]=i,this._deflate.write(r),this._deflate.flush(t.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let t=e.concat(this._deflate[c],this._deflate[h]);n&&(t=new s(t.buffer,t.byteOffset,t.length-4)),this._deflate[f]=null,this._deflate[h]=0,this._deflate[c]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,t)}))}}}var rr,nr,ir,sr,or,ar,hr,fr,cr,ur,lr,pr,dr,gr,yr={exports:{}},mr={exports:{}};function _r(){if(ir)return mr.exports;ir=1;try{mr.exports=Ke()(__dirname)}catch(t){mr.exports=(nr||(nr=1,rr=function(t){const e=t.length;let r=0;for(;r<e;)if(128&t[r])if(192==(224&t[r])){if(r+1===e||128!=(192&t[r+1])||192==(254&t[r]))return!1;r+=2}else if(224==(240&t[r])){if(r+2>=e||128!=(192&t[r+1])||128!=(192&t[r+2])||224===t[r]&&128==(224&t[r+1])||237===t[r]&&160==(224&t[r+1]))return!1;r+=3}else{if(240!=(248&t[r]))return!1;if(r+3>=e||128!=(192&t[r+1])||128!=(192&t[r+2])||128!=(192&t[r+3])||240===t[r]&&128==(240&t[r+1])||244===t[r]&&t[r+1]>143||t[r]>244)return!1;r+=4}else r++;return!0}),rr)}return mr.exports}function br(){if(sr)return yr.exports;sr=1;const{isUtf8:t}=h,{hasBlob:e}=Pe();function r(t){const e=t.length;let r=0;for(;r<e;)if(128&t[r])if(192==(224&t[r])){if(r+1===e||128!=(192&t[r+1])||192==(254&t[r]))return!1;r+=2}else if(224==(240&t[r])){if(r+2>=e||128!=(192&t[r+1])||128!=(192&t[r+2])||224===t[r]&&128==(224&t[r+1])||237===t[r]&&160==(224&t[r+1]))return!1;r+=3}else{if(240!=(248&t[r]))return!1;if(r+3>=e||128!=(192&t[r+1])||128!=(192&t[r+2])||128!=(192&t[r+3])||240===t[r]&&128==(240&t[r+1])||244===t[r]&&t[r+1]>143||t[r]>244)return!1;r+=4}else r++;return!0}if(yr.exports={isBlob:function(t){return e&&"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&("Blob"===t[Symbol.toStringTag]||"File"===t[Symbol.toStringTag])},isValidStatusCode:function(t){return t>=1e3&&t<=1014&&1004!==t&&1005!==t&&1006!==t||t>=3e3&&t<=4999},isValidUTF8:r,tokenChars:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0]},t)yr.exports.isValidUTF8=function(e){return e.length<24?r(e):t(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const t=_r();yr.exports.isValidUTF8=function(e){return e.length<32?r(e):t(e)}}catch(t){}return yr.exports}function wr(){if(ar)return or;ar=1;const{Writable:e}=t,r=er(),{BINARY_TYPES:n,EMPTY_BUFFER:i,kStatusCode:s,kWebSocket:o}=Pe(),{concat:a,toArrayBuffer:h,unmask:f}=tr(),{isValidStatusCode:c,isValidUTF8:u}=br(),l=Buffer[Symbol.species];return or=class extends e{constructor(t={}){super(),this._allowSynchronousEvents=void 0===t.allowSynchronousEvents||t.allowSynchronousEvents,this._binaryType=t.binaryType||n[0],this._extensions=t.extensions||{},this._isServer=!!t.isServer,this._maxPayload=0|t.maxPayload,this._skipUTF8Validation=!!t.skipUTF8Validation,this[o]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=0}_write(t,e,r){if(8===this._opcode&&0==this._state)return r();this._bufferedBytes+=t.length,this._buffers.push(t),this.startLoop(r)}consume(t){if(this._bufferedBytes-=t,t===this._buffers[0].length)return this._buffers.shift();if(t<this._buffers[0].length){const e=this._buffers[0];return this._buffers[0]=new l(e.buffer,e.byteOffset+t,e.length-t),new l(e.buffer,e.byteOffset,t)}const e=Buffer.allocUnsafe(t);do{const r=this._buffers[0],n=e.length-t;t>=r.length?e.set(this._buffers.shift(),n):(e.set(new Uint8Array(r.buffer,r.byteOffset,t),n),this._buffers[0]=new l(r.buffer,r.byteOffset+t,r.length-t)),t-=r.length}while(t>0);return e}startLoop(t){this._loop=!0;do{switch(this._state){case 0:this.getInfo(t);break;case 1:this.getPayloadLength16(t);break;case 2:this.getPayloadLength64(t);break;case 3:this.getMask();break;case 4:this.getData(t);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||t()}getInfo(t){if(this._bufferedBytes<2)return void(this._loop=!1);const e=this.consume(2);if(48&e[0]){return void t(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const n=!(64&~e[0]);if(!n||this._extensions[r.extensionName]){if(this._fin=!(128&~e[0]),this._opcode=15&e[0],this._payloadLength=127&e[1],0===this._opcode){if(n){return void t(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void t(this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE"))}this._opcode=this._fragmented}else if(1===this._opcode||2===this._opcode){if(this._fragmented){return void t(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}this._compressed=n}else{if(!(this._opcode>7&&this._opcode<11)){return void t(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void t(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(n){return void t(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(this._payloadLength>125||8===this._opcode&&1===this._payloadLength){return void t(this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"))}}if(this._fin||this._fragmented||(this._fragmented=this._opcode),this._masked=!(128&~e[1]),this._isServer){if(!this._masked){return void t(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void t(this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK"))}126===this._payloadLength?this._state=1:127===this._payloadLength?this._state=2:this.haveLength(t)}else{t(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}}getPayloadLength16(t){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(t))}getPayloadLength64(t){if(this._bufferedBytes<8)return void(this._loop=!1);const e=this.consume(8),r=e.readUInt32BE(0);if(r>Math.pow(2,21)-1){t(this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"))}else this._payloadLength=r*Math.pow(2,32)+e.readUInt32BE(4),this.haveLength(t)}haveLength(t){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){t(this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"))}else this._masked?this._state=3:this._state=4}getMask(){this._bufferedBytes<4?this._loop=!1:(this._mask=this.consume(4),this._state=4)}getData(t){let e=i;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);e=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&f(e,this._mask)}if(this._opcode>7)this.controlMessage(e,t);else{if(this._compressed)return this._state=5,void this.decompress(e,t);e.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(e)),this.dataMessage(t)}}decompress(t,e){this._extensions[r.extensionName].decompress(t,this._fin,((t,r)=>{if(t)return e(t);if(r.length){if(this._messageLength+=r.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const t=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void e(t)}this._fragments.push(r)}this.dataMessage(e),0===this._state&&this.startLoop(e)}))}dataMessage(t){if(!this._fin)return void(this._state=0);const e=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let n;n="nodebuffer"===this._binaryType?a(r,e):"arraybuffer"===this._binaryType?h(a(r,e)):"blob"===this._binaryType?new Blob(r):r,this._allowSynchronousEvents?(this.emit("message",n,!0),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",n,!0),this._state=0,this.startLoop(t)})))}else{const n=a(r,e);if(!this._skipUTF8Validation&&!u(n)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}5===this._state||this._allowSynchronousEvents?(this.emit("message",n,!1),this._state=0):(this._state=6,setImmediate((()=>{this.emit("message",n,!1),this._state=0,this.startLoop(t)})))}}controlMessage(t,e){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",t),this._state=0):(this._state=6,setImmediate((()=>{this.emit(9===this._opcode?"ping":"pong",t),this._state=0,this.startLoop(e)})));else{if(0===t.length)this._loop=!1,this.emit("conclude",1005,i),this.end();else{const r=t.readUInt16BE(0);if(!c(r)){const t=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void e(t)}const n=new l(t.buffer,t.byteOffset+2,t.length-2);if(!this._skipUTF8Validation&&!u(n)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}this._loop=!1,this.emit("conclude",r,n),this.end()}this._state=0}}createError(t,e,r,n,i){this._loop=!1,this._errored=!0;const o=new t(r?`Invalid WebSocket frame: ${e}`:e);return Error.captureStackTrace(o,this.createError),o.code=i,o[s]=n,o}},or}function Er(){if(fr)return hr;fr=1;const{randomFillSync:t}=f,e=er(),{EMPTY_BUFFER:r,kWebSocket:n,NOOP:i}=Pe(),{isBlob:s,isValidStatusCode:o}=br(),{mask:a,toBuffer:h}=tr(),c=Symbol("kByteLength"),u=Buffer.alloc(4),l=8192;let p,d=l;class g{constructor(t,e,r){this._extensions=e||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=t,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=i,this[n]=void 0}static frame(e,r){let n,i,s=!1,o=2,h=!1;r.mask&&(n=r.maskBuffer||u,r.generateMask?r.generateMask(n):(d===l&&(void 0===p&&(p=Buffer.alloc(l)),t(p,0,l),d=0),n[0]=p[d++],n[1]=p[d++],n[2]=p[d++],n[3]=p[d++]),h=!(n[0]|n[1]|n[2]|n[3]),o=6),"string"==typeof e?i=r.mask&&!h||void 0===r[c]?(e=Buffer.from(e)).length:r[c]:(i=e.length,s=r.mask&&r.readOnly&&!h);let f=i;i>=65536?(o+=8,f=127):i>125&&(o+=2,f=126);const g=Buffer.allocUnsafe(s?i+o:o);return g[0]=r.fin?128|r.opcode:r.opcode,r.rsv1&&(g[0]|=64),g[1]=f,126===f?g.writeUInt16BE(i,2):127===f&&(g[2]=g[3]=0,g.writeUIntBE(i,4,6)),r.mask?(g[1]|=128,g[o-4]=n[0],g[o-3]=n[1],g[o-2]=n[2],g[o-1]=n[3],h?[g,e]:s?(a(e,n,g,o,i),[g]):(a(e,n,e,0,i),[g,e])):[g,e]}close(t,e,n,i){let s;if(void 0===t)s=r;else{if("number"!=typeof t||!o(t))throw new TypeError("First argument must be a valid error code number");if(void 0!==e&&e.length){const r=Buffer.byteLength(e);if(r>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+r),s.writeUInt16BE(t,0),"string"==typeof e?s.write(e,2):s.set(e,2)}else s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0)}const a={[c]:s.length,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};0!==this._state?this.enqueue([this.dispatch,s,!1,a,i]):this.sendFrame(g.frame(s,a),i)}ping(t,e,r){let n,i;if("string"==typeof t?(n=Buffer.byteLength(t),i=!1):s(t)?(n=t.size,i=!1):(n=(t=h(t)).length,i=h.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[c]:n,fin:!0,generateMask:this._generateMask,mask:e,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};s(t)?0!==this._state?this.enqueue([this.getBlobData,t,!1,o,r]):this.getBlobData(t,!1,o,r):0!==this._state?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(g.frame(t,o),r)}pong(t,e,r){let n,i;if("string"==typeof t?(n=Buffer.byteLength(t),i=!1):s(t)?(n=t.size,i=!1):(n=(t=h(t)).length,i=h.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[c]:n,fin:!0,generateMask:this._generateMask,mask:e,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};s(t)?0!==this._state?this.enqueue([this.getBlobData,t,!1,o,r]):this.getBlobData(t,!1,o,r):0!==this._state?this.enqueue([this.dispatch,t,!1,o,r]):this.sendFrame(g.frame(t,o),r)}send(t,r,n){const i=this._extensions[e.extensionName];let o,a,f=r.binary?2:1,u=r.compress;"string"==typeof t?(o=Buffer.byteLength(t),a=!1):s(t)?(o=t.size,a=!1):(o=(t=h(t)).length,a=h.readOnly),this._firstFragment?(this._firstFragment=!1,u&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(u=o>=i._threshold),this._compress=u):(u=!1,f=0),r.fin&&(this._firstFragment=!0);const l={[c]:o,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:f,readOnly:a,rsv1:u};s(t)?0!==this._state?this.enqueue([this.getBlobData,t,this._compress,l,n]):this.getBlobData(t,this._compress,l,n):0!==this._state?this.enqueue([this.dispatch,t,this._compress,l,n]):this.dispatch(t,this._compress,l,n)}getBlobData(t,e,r,n){this._bufferedBytes+=r[c],this._state=2,t.arrayBuffer().then((t=>{if(this._socket.destroyed){const t=new Error("The socket was closed while the blob was being read");return void process.nextTick(y,this,t,n)}this._bufferedBytes-=r[c];const i=h(t);e?this.dispatch(i,e,r,n):(this._state=0,this.sendFrame(g.frame(i,r),n),this.dequeue())})).catch((t=>{process.nextTick(m,this,t,n)}))}dispatch(t,r,n,i){if(!r)return void this.sendFrame(g.frame(t,n),i);const s=this._extensions[e.extensionName];this._bufferedBytes+=n[c],this._state=1,s.compress(t,n.fin,((t,e)=>{if(this._socket.destroyed){y(this,new Error("The socket was closed while data was being compressed"),i)}else this._bufferedBytes-=n[c],this._state=0,n.readOnly=!1,this.sendFrame(g.frame(e,n),i),this.dequeue()}))}dequeue(){for(;0===this._state&&this._queue.length;){const t=this._queue.shift();this._bufferedBytes-=t[3][c],Reflect.apply(t[0],this,t.slice(1))}}enqueue(t){this._bufferedBytes+=t[3][c],this._queue.push(t)}sendFrame(t,e){2===t.length?(this._socket.cork(),this._socket.write(t[0]),this._socket.write(t[1],e),this._socket.uncork()):this._socket.write(t[0],e)}}function y(t,e,r){"function"==typeof r&&r(e);for(let r=0;r<t._queue.length;r++){const n=t._queue[r],i=n[n.length-1];"function"==typeof i&&i(e)}}function m(t,e,r){y(t,e,r),t.onerror(e)}return hr=g}function Br(){if(pr)return lr;pr=1;const{tokenChars:t}=br();function e(t,e,r){void 0===t[e]?t[e]=[r]:t[e].push(r)}return lr={format:function(t){return Object.keys(t).map((e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map((t=>[e].concat(Object.keys(t).map((e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map((t=>!0===t?e:`${e}=${t}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(r){const n=Object.create(null);let i,s,o=Object.create(null),a=!1,h=!1,f=!1,c=-1,u=-1,l=-1,p=0;for(;p<r.length;p++)if(u=r.charCodeAt(p),void 0===i)if(-1===l&&1===t[u])-1===c&&(c=p);else if(0===p||32!==u&&9!==u){if(59!==u&&44!==u)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===l&&(l=p);const t=r.slice(c,l);44===u?(e(n,t,o),o=Object.create(null)):i=t,c=l=-1}}else-1===l&&-1!==c&&(l=p);else if(void 0===s)if(-1===l&&1===t[u])-1===c&&(c=p);else if(32===u||9===u)-1===l&&-1!==c&&(l=p);else if(59===u||44===u){if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===l&&(l=p),e(o,r.slice(c,l),!0),44===u&&(e(n,i,o),o=Object.create(null),i=void 0),c=l=-1}else{if(61!==u||-1===c||-1!==l)throw new SyntaxError(`Unexpected character at index ${p}`);s=r.slice(c,p),c=l=-1}else if(h){if(1!==t[u])throw new SyntaxError(`Unexpected character at index ${p}`);-1===c?c=p:a||(a=!0),h=!1}else if(f)if(1===t[u])-1===c&&(c=p);else if(34===u&&-1!==c)f=!1,l=p;else{if(92!==u)throw new SyntaxError(`Unexpected character at index ${p}`);h=!0}else if(34===u&&61===r.charCodeAt(p-1))f=!0;else if(-1===l&&1===t[u])-1===c&&(c=p);else if(-1===c||32!==u&&9!==u){if(59!==u&&44!==u)throw new SyntaxError(`Unexpected character at index ${p}`);{if(-1===c)throw new SyntaxError(`Unexpected character at index ${p}`);-1===l&&(l=p);let t=r.slice(c,l);a&&(t=t.replace(/\\/g,""),a=!1),e(o,s,t),44===u&&(e(n,i,o),o=Object.create(null),i=void 0),s=void 0,c=l=-1}}else-1===l&&(l=p);if(-1===c||f||32===u||9===u)throw new SyntaxError("Unexpected end of input");-1===l&&(l=p);const d=r.slice(c,l);return void 0===i?e(n,d,o):(void 0===s?e(o,d,!0):e(o,s,a?d.replace(/\\/g,""):d),e(n,i,o)),n}},lr}function vr(){if(gr)return dr;gr=1;const t=c,e=u,n=l,i=r,s=p,{randomBytes:o,createHash:a}=f,{URL:h}=d,g=er(),y=wr(),m=Er(),{isBlob:_}=br(),{BINARY_TYPES:b,EMPTY_BUFFER:w,GUID:E,kForOnEventAttribute:B,kListener:v,kStatusCode:S,kWebSocket:A,NOOP:k}=Pe(),{EventTarget:{addEventListener:L,removeEventListener:I}}=function(){if(ur)return cr;ur=1;const{kForOnEventAttribute:t,kListener:e}=Pe(),r=Symbol("kCode"),n=Symbol("kData"),i=Symbol("kError"),s=Symbol("kMessage"),o=Symbol("kReason"),a=Symbol("kTarget"),h=Symbol("kType"),f=Symbol("kWasClean");class c{constructor(t){this[a]=null,this[h]=t}get target(){return this[a]}get type(){return this[h]}}Object.defineProperty(c.prototype,"target",{enumerable:!0}),Object.defineProperty(c.prototype,"type",{enumerable:!0});class u extends c{constructor(t,e={}){super(t),this[r]=void 0===e.code?0:e.code,this[o]=void 0===e.reason?"":e.reason,this[f]=void 0!==e.wasClean&&e.wasClean}get code(){return this[r]}get reason(){return this[o]}get wasClean(){return this[f]}}Object.defineProperty(u.prototype,"code",{enumerable:!0}),Object.defineProperty(u.prototype,"reason",{enumerable:!0}),Object.defineProperty(u.prototype,"wasClean",{enumerable:!0});class l extends c{constructor(t,e={}){super(t),this[i]=void 0===e.error?null:e.error,this[s]=void 0===e.message?"":e.message}get error(){return this[i]}get message(){return this[s]}}Object.defineProperty(l.prototype,"error",{enumerable:!0}),Object.defineProperty(l.prototype,"message",{enumerable:!0});class p extends c{constructor(t,e={}){super(t),this[n]=void 0===e.data?null:e.data}get data(){return this[n]}}Object.defineProperty(p.prototype,"data",{enumerable:!0});const d={addEventListener(r,n,i={}){for(const s of this.listeners(r))if(!i[t]&&s[e]===n&&!s[t])return;let s;if("message"===r)s=function(t,e){const r=new p("message",{data:e?t:t.toString()});r[a]=this,g(n,this,r)};else if("close"===r)s=function(t,e){const r=new u("close",{code:t,reason:e.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[a]=this,g(n,this,r)};else if("error"===r)s=function(t){const e=new l("error",{error:t,message:t.message});e[a]=this,g(n,this,e)};else{if("open"!==r)return;s=function(){const t=new c("open");t[a]=this,g(n,this,t)}}s[t]=!!i[t],s[e]=n,i.once?this.once(r,s):this.on(r,s)},removeEventListener(r,n){for(const i of this.listeners(r))if(i[e]===n&&!i[t]){this.removeListener(r,i);break}}};function g(t,e,r){"object"==typeof t&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}return cr={CloseEvent:u,ErrorEvent:l,Event:c,EventTarget:d,MessageEvent:p}}(),{format:T,parse:U}=Br(),{toBuffer:x}=tr(),O=3e4,C=Symbol("kAborted"),R=[8,13],N=["CONNECTING","OPEN","CLOSING","CLOSED"],M=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class P extends t{constructor(t,e,r){super(),this._binaryType=b[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=w,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=P.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==t?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===e?e=[]:Array.isArray(e)||("object"==typeof e&&null!==e?(r=e,e=[]):e=[e]),D(this,t,e,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(t){b.includes(t)&&(this._binaryType=t,this._receiver&&(this._receiver._binaryType=t))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(t,e,r){const n=new y({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),i=new m(t,this._extensions,r.generateMask);this._receiver=n,this._sender=i,this._socket=t,n[A]=this,i[A]=this,t[A]=this,n.on("conclude",G),n.on("drain",W),n.on("error",V),n.on("message",Y),n.on("ping",Q),n.on("pong",J),i.onerror=K,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),e.length>0&&t.unshift(e),t.on("close",tt),t.on("data",et),t.on("end",rt),t.on("error",nt),this._readyState=P.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=P.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[g.extensionName]&&this._extensions[g.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=P.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,e){if(this.readyState!==P.CLOSED)if(this.readyState!==P.CONNECTING)this.readyState!==P.CLOSING?(this._readyState=P.CLOSING,this._sender.close(t,e,!this._isServer,(t=>{t||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),Z(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const t="WebSocket was closed before the connection was established";j(this,this._req,t)}}pause(){this.readyState!==P.CONNECTING&&this.readyState!==P.CLOSED&&(this._paused=!0,this._socket.pause())}ping(t,e,r){if(this.readyState===P.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=e=void 0):"function"==typeof e&&(r=e,e=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===P.OPEN?(void 0===e&&(e=!this._isServer),this._sender.ping(t||w,e,r)):z(this,t,r)}pong(t,e,r){if(this.readyState===P.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(r=t,t=e=void 0):"function"==typeof e&&(r=e,e=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===P.OPEN?(void 0===e&&(e=!this._isServer),this._sender.pong(t||w,e,r)):z(this,t,r)}resume(){this.readyState!==P.CONNECTING&&this.readyState!==P.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,e,r){if(this.readyState===P.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof e&&(r=e,e={}),"number"==typeof t&&(t=t.toString()),this.readyState!==P.OPEN)return void z(this,t,r);const n={binary:"string"!=typeof t,mask:!this._isServer,compress:!0,fin:!0,...e};this._extensions[g.extensionName]||(n.compress=!1),this._sender.send(t||w,n,r)}terminate(){if(this.readyState!==P.CLOSED)if(this.readyState!==P.CONNECTING)this._socket&&(this._readyState=P.CLOSING,this._socket.destroy());else{const t="WebSocket was closed before the connection was established";j(this,this._req,t)}}}function D(t,r,i,s){const f={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:R[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...s,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=f.autoPong,!R.includes(f.protocolVersion))throw new RangeError(`Unsupported protocol version: ${f.protocolVersion} (supported versions: ${R.join(", ")})`);let c;if(r instanceof h)c=r;else try{c=new h(r)}catch(t){throw new SyntaxError(`Invalid URL: ${r}`)}"http:"===c.protocol?c.protocol="ws:":"https:"===c.protocol&&(c.protocol="wss:"),t._url=c.href;const u="wss:"===c.protocol,l="ws+unix:"===c.protocol;let p;if("ws:"===c.protocol||u||l?l&&!c.pathname?p="The URL's pathname is empty":c.hash&&(p="The URL contains a fragment identifier"):p='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"',p){const e=new SyntaxError(p);if(0===t._redirects)throw e;return void $(t,e)}const d=u?443:80,y=o(16).toString("base64"),m=u?e.request:n.request,_=new Set;let b,w;if(f.createConnection=f.createConnection||(u?H:F),f.defaultPort=f.defaultPort||d,f.port=c.port||d,f.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,f.headers={...f.headers,"Sec-WebSocket-Version":f.protocolVersion,"Sec-WebSocket-Key":y,Connection:"Upgrade",Upgrade:"websocket"},f.path=c.pathname+c.search,f.timeout=f.handshakeTimeout,f.perMessageDeflate&&(b=new g(!0!==f.perMessageDeflate?f.perMessageDeflate:{},!1,f.maxPayload),f.headers["Sec-WebSocket-Extensions"]=T({[g.extensionName]:b.offer()})),i.length){for(const t of i){if("string"!=typeof t||!M.test(t)||_.has(t))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(t)}f.headers["Sec-WebSocket-Protocol"]=i.join(",")}if(f.origin&&(f.protocolVersion<13?f.headers["Sec-WebSocket-Origin"]=f.origin:f.headers.Origin=f.origin),(c.username||c.password)&&(f.auth=`${c.username}:${c.password}`),l){const t=f.path.split(":");f.socketPath=t[0],f.path=t[1]}if(f.followRedirects){if(0===t._redirects){t._originalIpc=l,t._originalSecure=u,t._originalHostOrSocketPath=l?f.socketPath:c.host;const e=s&&s.headers;if(s={...s,headers:{}},e)for(const[t,r]of Object.entries(e))s.headers[t.toLowerCase()]=r}else if(0===t.listenerCount("redirect")){const e=l?!!t._originalIpc&&f.socketPath===t._originalHostOrSocketPath:!t._originalIpc&&c.host===t._originalHostOrSocketPath;(!e||t._originalSecure&&!u)&&(delete f.headers.authorization,delete f.headers.cookie,e||delete f.headers.host,f.auth=void 0)}f.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(f.auth).toString("base64")),w=t._req=m(f),t._redirects&&t.emit("redirect",t.url,w)}else w=t._req=m(f);f.timeout&&w.on("timeout",(()=>{j(t,w,"Opening handshake has timed out")})),w.on("error",(e=>{null===w||w[C]||(w=t._req=null,$(t,e))})),w.on("response",(e=>{const n=e.headers.location,o=e.statusCode;if(n&&f.followRedirects&&o>=300&&o<400){if(++t._redirects>f.maxRedirects)return void j(t,w,"Maximum redirects exceeded");let e;w.abort();try{e=new h(n,r)}catch(e){const r=new SyntaxError(`Invalid URL: ${n}`);return void $(t,r)}D(t,e,i,s)}else t.emit("unexpected-response",w,e)||j(t,w,`Unexpected server response: ${e.statusCode}`)})),w.on("upgrade",((e,r,n)=>{if(t.emit("upgrade",e),t.readyState!==P.CONNECTING)return;w=t._req=null;const i=e.headers.upgrade;if(void 0===i||"websocket"!==i.toLowerCase())return void j(t,r,"Invalid Upgrade header");const s=a("sha1").update(y+E).digest("base64");if(e.headers["sec-websocket-accept"]!==s)return void j(t,r,"Invalid Sec-WebSocket-Accept header");const o=e.headers["sec-websocket-protocol"];let h;if(void 0!==o?_.size?_.has(o)||(h="Server sent an invalid subprotocol"):h="Server sent a subprotocol but none was requested":_.size&&(h="Server sent no subprotocol"),h)return void j(t,r,h);o&&(t._protocol=o);const c=e.headers["sec-websocket-extensions"];if(void 0!==c){if(!b){return void j(t,r,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let e;try{e=U(c)}catch(e){return void j(t,r,"Invalid Sec-WebSocket-Extensions header")}const n=Object.keys(e);if(1!==n.length||n[0]!==g.extensionName){return void j(t,r,"Server indicated an extension that was not requested")}try{b.accept(e[g.extensionName])}catch(e){return void j(t,r,"Invalid Sec-WebSocket-Extensions header")}t._extensions[g.extensionName]=b}t.setSocket(r,n,{allowSynchronousEvents:f.allowSynchronousEvents,generateMask:f.generateMask,maxPayload:f.maxPayload,skipUTF8Validation:f.skipUTF8Validation})})),f.finishRequest?f.finishRequest(w,t):w.end()}function $(t,e){t._readyState=P.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function F(t){return t.path=t.socketPath,i.connect(t)}function H(t){return t.path=void 0,t.servername||""===t.servername||(t.servername=i.isIP(t.host)?"":t.host),s.connect(t)}function j(t,e,r){t._readyState=P.CLOSING;const n=new Error(r);Error.captureStackTrace(n,j),e.setHeader?(e[C]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick($,t,n)):(e.destroy(n),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function z(t,e,r){if(e){const r=_(e)?e.size:x(e).length;t._socket?t._sender._bufferedBytes+=r:t._bufferedAmount+=r}if(r){const e=new Error(`WebSocket is not open: readyState ${t.readyState} (${N[t.readyState]})`);process.nextTick(r,e)}}function G(t,e){const r=this[A];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,void 0!==r._socket[A]&&(r._socket.removeListener("data",et),process.nextTick(X,r._socket),1005===t?r.close():r.close(t,e))}function W(){const t=this[A];t.isPaused||t._socket.resume()}function V(t){const e=this[A];void 0!==e._socket[A]&&(e._socket.removeListener("data",et),process.nextTick(X,e._socket),e.close(t[S])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function q(){this[A].emitClose()}function Y(t,e){this[A].emit("message",t,e)}function Q(t){const e=this[A];e._autoPong&&e.pong(t,!this._isServer,k),e.emit("ping",t)}function J(t){this[A].emit("pong",t)}function X(t){t.resume()}function K(t){const e=this[A];e.readyState!==P.CLOSED&&(e.readyState===P.OPEN&&(e._readyState=P.CLOSING,Z(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Z(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),O)}function tt(){const t=this[A];let e;this.removeListener("close",tt),this.removeListener("data",et),this.removeListener("end",rt),t._readyState=P.CLOSING,this._readableState.endEmitted||t._closeFrameReceived||t._receiver._writableState.errorEmitted||null===(e=t._socket.read())||t._receiver.write(e),t._receiver.end(),this[A]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",q),t._receiver.on("finish",q))}function et(t){this[A]._receiver.write(t)||this.pause()}function rt(){const t=this[A];t._readyState=P.CLOSING,t._receiver.end(),this.end()}function nt(){const t=this[A];this.removeListener("error",nt),this.on("error",k),t&&(t._readyState=P.CLOSING,this.destroy())}return Object.defineProperty(P,"CONNECTING",{enumerable:!0,value:N.indexOf("CONNECTING")}),Object.defineProperty(P.prototype,"CONNECTING",{enumerable:!0,value:N.indexOf("CONNECTING")}),Object.defineProperty(P,"OPEN",{enumerable:!0,value:N.indexOf("OPEN")}),Object.defineProperty(P.prototype,"OPEN",{enumerable:!0,value:N.indexOf("OPEN")}),Object.defineProperty(P,"CLOSING",{enumerable:!0,value:N.indexOf("CLOSING")}),Object.defineProperty(P.prototype,"CLOSING",{enumerable:!0,value:N.indexOf("CLOSING")}),Object.defineProperty(P,"CLOSED",{enumerable:!0,value:N.indexOf("CLOSED")}),Object.defineProperty(P.prototype,"CLOSED",{enumerable:!0,value:N.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((t=>{Object.defineProperty(P.prototype,t,{enumerable:!0})})),["open","error","close","message"].forEach((t=>{Object.defineProperty(P.prototype,`on${t}`,{enumerable:!0,get(){for(const e of this.listeners(t))if(e[B])return e[v];return null},set(e){for(const e of this.listeners(t))if(e[B]){this.removeListener(t,e);break}"function"==typeof e&&this.addEventListener(t,e,{[B]:!0})}})})),P.prototype.addEventListener=L,P.prototype.removeEventListener=I,dr=P}wr(),Er();var Sr,Ar,kr,Lr,Ir=tt(vr());function Tr(){if(Ar)return Sr;Ar=1;const{tokenChars:t}=br();return Sr={parse:function(e){const r=new Set;let n=-1,i=-1,s=0;for(;s<e.length;s++){const o=e.charCodeAt(s);if(-1===i&&1===t[o])-1===n&&(n=s);else if(0===s||32!==o&&9!==o){if(44!==o)throw new SyntaxError(`Unexpected character at index ${s}`);{if(-1===n)throw new SyntaxError(`Unexpected character at index ${s}`);-1===i&&(i=s);const t=e.slice(n,i);if(r.has(t))throw new SyntaxError(`The "${t}" subprotocol is duplicated`);r.add(t),n=i=-1}}else-1===i&&-1!==n&&(i=s)}if(-1===n||-1!==i)throw new SyntaxError("Unexpected end of input");const o=e.slice(n,s);if(r.has(o))throw new SyntaxError(`The "${o}" subprotocol is duplicated`);return r.add(o),r}},Sr}var Ur=function(){if(Lr)return kr;Lr=1;const t=c,e=l,{createHash:r}=f,n=Br(),i=er(),s=Tr(),o=vr(),{GUID:a,kWebSocket:h}=Pe(),u=/^[+/0-9A-Za-z]{22}==$/;function p(t){t._state=2,t.emit("close")}function d(){this.destroy()}function g(t,r,n,i){n=n||e.STATUS_CODES[r],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${r} ${e.STATUS_CODES[r]}\r\n`+Object.keys(i).map((t=>`${t}: ${i[t]}`)).join("\r\n")+"\r\n\r\n"+n)}function y(t,e,r,n,i){if(t.listenerCount("wsClientError")){const n=new Error(i);Error.captureStackTrace(n,y),t.emit("wsClientError",n,r,e)}else g(r,n,i)}return kr=class extends t{constructor(t,r){if(super(),null==(t={allowSynchronousEvents:!0,autoPong:!0,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:o,...t}).port&&!t.server&&!t.noServer||null!=t.port&&(t.server||t.noServer)||t.server&&t.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=t.port?(this._server=e.createServer(((t,r)=>{const n=e.STATUS_CODES[426];r.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),r.end(n)})),this._server.listen(t.port,t.host,t.backlog,r)):t.server&&(this._server=t.server),this._server){const t=this.emit.bind(this,"connection");this._removeListeners=function(t,e){for(const r of Object.keys(e))t.on(r,e[r]);return function(){for(const r of Object.keys(e))t.removeListener(r,e[r])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(e,r,n)=>{this.handleUpgrade(e,r,n,t)}})}!0===t.perMessageDeflate&&(t.perMessageDeflate={}),t.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=t,this._state=0}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(t){if(2===this._state)return t&&this.once("close",(()=>{t(new Error("The server is not running"))})),void process.nextTick(p,this);if(t&&this.once("close",t),1!==this._state)if(this._state=1,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients&&this.clients.size?this._shouldEmitClose=!0:process.nextTick(p,this);else{const t=this._server;this._removeListeners(),this._removeListeners=this._server=null,t.close((()=>{p(this)}))}}shouldHandle(t){if(this.options.path){const e=t.url.indexOf("?");if((-1!==e?t.url.slice(0,e):t.url)!==this.options.path)return!1}return!0}handleUpgrade(t,e,r,o){e.on("error",d);const a=t.headers["sec-websocket-key"],h=t.headers.upgrade,f=+t.headers["sec-websocket-version"];if("GET"!==t.method){return void y(this,t,e,405,"Invalid HTTP method")}if(void 0===h||"websocket"!==h.toLowerCase()){return void y(this,t,e,400,"Invalid Upgrade header")}if(void 0===a||!u.test(a)){return void y(this,t,e,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==f&&13!==f){return void y(this,t,e,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(t))return void g(e,400);const c=t.headers["sec-websocket-protocol"];let l=new Set;if(void 0!==c)try{l=s.parse(c)}catch(r){return void y(this,t,e,400,"Invalid Sec-WebSocket-Protocol header")}const p=t.headers["sec-websocket-extensions"],m={};if(this.options.perMessageDeflate&&void 0!==p){const r=new i(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const t=n.parse(p);t[i.extensionName]&&(r.accept(t[i.extensionName]),m[i.extensionName]=r)}catch(r){return void y(this,t,e,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const n={origin:t.headers[""+(8===f?"sec-websocket-origin":"origin")],secure:!(!t.socket.authorized&&!t.socket.encrypted),req:t};if(2===this.options.verifyClient.length)return void this.options.verifyClient(n,((n,i,s,h)=>{if(!n)return g(e,i||401,s,h);this.completeUpgrade(m,a,l,t,e,r,o)}));if(!this.options.verifyClient(n))return g(e,401)}this.completeUpgrade(m,a,l,t,e,r,o)}completeUpgrade(t,e,s,o,f,c,u){if(!f.readable||!f.writable)return f.destroy();if(f[h])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return g(f,503);const l=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${r("sha1").update(e+a).digest("base64")}`],y=new this.options.WebSocket(null,void 0,this.options);if(s.size){const t=this.options.handleProtocols?this.options.handleProtocols(s,o):s.values().next().value;t&&(l.push(`Sec-WebSocket-Protocol: ${t}`),y._protocol=t)}if(t[i.extensionName]){const e=t[i.extensionName].params,r=n.format({[i.extensionName]:[e]});l.push(`Sec-WebSocket-Extensions: ${r}`),y._extensions=t}this.emit("headers",l,o),f.write(l.concat("\r\n").join("\r\n")),f.removeListener("error",d),y.setSocket(f,c,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(y),y.on("close",(()=>{this.clients.delete(y),this._shouldEmitClose&&!this.clients.size&&process.nextTick(p,this)}))),u(y,o)}},kr}(),xr=tt(Ur);class Or extends ke{constructor(t){super(t),t&&this.open()}close(){this.socket&&(this.socket.onclose=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.close(),this.socket=null),this.emit("close")}stop(){this.close(),clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null}keepAlive(){this.socket&&3!==this.socket?.readyState||this.open()}createConnection(t){this.socket=new Ir(t),this.stateChange("opening"),this.socket.onopen=()=>{this.socket.on("message",this.onWebSocketMessage.bind(this)),this.emit("open")},this.socket.onerror=t=>{this.emit("error",t)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(t){this.rxCounter++,this.lastTxRxTime=Date.now(),this.rxBytes+=t.byteLength,this.emit("socket_data",t)}socket_send(t){1===this.socket?.readyState?(this.socket.send(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}}let Cr={clientTracking:!1,port:0,httpServer:null,congPort:0,timeout:5e4,showMessage:"none",showMetric:0,showChannel:0,monitorPeriod:5e3,fileLogger:{connection:{use:!1,path:"connection.log"},auth:{use:!1,path:"auth.log"},attack:{use:!1,path:"attack.log"}},useQuota:{signalSize:!1,publishCounter:!1,trafficRate:!1,disconnect:!1},defaultQuotaIndex:3,adminLevel:255,debug:{slow:!1,delay:500,showAuthInfo:!1},retain:{isAvailable:!0,limitSize:1e5,limitCounter:1e3},auth:{delay_auth_fail:1e3},memberOnly:!1};const Rr=new TextDecoder;Z.NB;const Nr=Z.MB;class Mr{constructor(t,e){this.socket=t,t.isAlive=!0,t.txCounter=0,t.rxCounter=0,t.openTime=Date.now(),this.boho=new Be,this.encMode=at.AUTO,this.channels=new Set,this.retain_signal=new Map,this.ssid=Mr.ssid++,this.manager=e,this.cid,this.did,this.uid,this.nick="",this.lastEchoMessage="N",this.privateNode=!1,this.HOME_CHANNEL="",this.level=Cr.defaultQuotaIndex,this.quota=pt[this.level],this.isAdmin=!1,this.state,this.stateLog=[],this.setState(ot.INIT)}static ssid=1;setState(t){this.state=t,Cr.debug.showAuthInfo&&(this.stateLog.push(t),console.log(this.stateLog.join(">")))}getState(){return this.state}getStateName(){return ot[this.state].toLowerCase()}showMessageLog(t,e){let r=this.boho.isAuthorized?`did: ${this.did} ${this.cid}@`:`${this.cid}@`;if(e){let e=ct[t[0]];e||(e=Be.BohoMsg[t[0]]),e=" ["+e+"]",t.byteLength>40?console.log(r+e+" LEN:",t.length):console.log(r+e,t)}else console.log(r+" [TEXT] %s",t)}rxQuotaChecker(t){let e=t.byteLength;return this.manager.rxBytes+=e,!(Cr.useQuota.signalSize&&e>this.quota.signalSize)||(console.log("## quota: size over"),this.send(Buffer.from([ct.OVER_SIZE])),Cr.useQuota.disconnect&&this.close(),!1)}onTimeDelayMessage(t,e=!0){setTimeout((()=>{this.onSocketMessage(t,e)}),Cr.debug.delay)}onSocketMessage(t,e=!0){if(this.receiveMonitor(),!this.rxQuotaChecker(t))return;let r,n;if("message"===Cr.showMessage&&this.showMessageLog(t,e),e){if(r=t[0],r===Be.BohoMsg.ENC_488){try{n=this.boho.decrypt_488(t)}catch(t){return void console.log("-- E488 DEC_FAIL",t)}if(!n)return;r=n[0],t=n}else if(r===Be.BohoMsg.ENC_E2E){try{n=this.boho.decrypt_488(t)}catch(t){return}if(!n)return;r=n[0],t.set(n,Be.MetaSize.ENC_488),t=t.subarray(Be.MetaSize.ENC_488)}switch(r){case ct.PING:this.pong();break;case ct.PONG:break;case ct.CID_REQ:this.state<ot.SENT_SERVER_READY&&this.close(),this.cid||(this.cid="?"+globalThis.crypto.getRandomValues(Buffer.alloc(3)).toString("base64url"),this.manager.cid2remote.set(this.cid,this)),this.send_enc_mode(Z.pack(Nr("#cid_ack","8",ct.CID_RES),Nr("#cid",this.cid))),this.setState(ot.CID_READY);break;case ct.ECHO:try{let e=Rr.decode(t.subarray(1));this.lastEchoMessage=e}catch(t){}this.send(t,e);break;case ct.IAM:if(t.byteLength>1){let e=t.subarray(1);this.nick=Rr.decode(e),console.log("iam nick reset",this.nick)}this.iamResponse();break;case ct.SIGNAL_E2E:case ct.SIGNAL:if(t.byteLength>=3){let e=t.readUInt8(1);if(t.byteLength>=e+2){let r=t.subarray(2,2+e);r=Rr.decode(r),this.manager.sender(r,this,t)}}break;case ct.UNSUBSCRIBE:if(2==t.byteLength)this.manager.unsubscribe([""],this);else if(t.byteLength>=3){let e=t.readUInt8(1);if(t.byteLength==e+2){let r=t.subarray(2,2+e);r=Rr.decode(r);let n=r.split(",");this.manager.unsubscribe(n,this)}}break;case ct.SUBSCRIBE:if(t.byteLength>=3){let e=t.readUInt8(1);if(t.byteLength==e+2){let r=t.subarray(2,2+e);r=Rr.decode(r);let n=r.split(",");this.manager.subscribe(n,this)}}break;case ct.SUBSCRIBE_REQ:if(t.byteLength>=6){let e=t.readUInt16BE(1),r=t.readUInt16BE(3);if(t.byteLength==r+5){let n=t.subarray(5,5+r);n=Rr.decode(n);let i=n.split(",");this.manager.subscribe(i,this),this.response(e,0)}else this.response(e,255)}break;case ct.REQUEST:try{let e=Z.unpack(t);if(e){if(!e.target||!e.topic)return;this.manager.server.apiNames.has(e.target)&&this.manager.server.emit(e.target,this,e)}}catch(t){console.log("request catch error",t)}break;case ct.CLOSE:if(t.byteLength>1){let e=Rr.decode(t.subarray(1));console.log(">> CLOSE reason:",e),this.close()}break;case Be.BohoMsg.AUTH_REQ:if(!this.manager.authManager)return;this.state<ot.SENT_SERVER_READY&&this.close(),this.setState(ot.RECV_AUTH_REQ);let r=this.boho.auth_nonce();this.send(r),this.setState(ot.SENT_SERVER_NONCE);break;case Be.BohoMsg.AUTH_HMAC:if(!this.manager.authManager)return;return this.state<ot.SENT_SERVER_NONCE&&this.close(),this.setState(ot.RECV_AUTH_HMAC),void this.manager.authManager.verify_auth_hmac(t,this).then((t=>{t&&this.manager.deligateSignal(remote,"@$name",t.name)})).catch((t=>{}))}}else try{let e=Rr.decode(t);this.manager.server.emit("text_message",e,this)}catch(t){}}response(t,e,r){r?this.send_enc_mode(Z.pack(Nr("#type","8",ct.RESPONSE_MBP),Nr("status","8",e),Nr("mid","16",t),Nr("body",r))):this.send_enc_mode(Z.pack(Nr("#type","8",ct.RESPONSE_MBP),Nr("status","8",e),Nr("mid","16",t)))}send_enc_mode(t,e=!1){if((this.encMode===at.YES||this.encMode===at.AUTO&&!this.TLS&&this.boho.isAuthorized)&&(e=!0),e&&t[0]==ct.SIGNAL_E2E){let e=t[1],r=this.boho.encrypt_488(t.subarray(0,3+e));r[0]=Be.BohoMsg.ENC_E2E;let n=Buffer.concat([r,t.subarray(3+e)]);this.send(n)}else if(e){let e=this.boho.encrypt_488(t);e&&this.send(e)}else this.send(t)}iamResponse(t=""){if(""==t){let e=[];for(let t of this.channels.keys())e.push(t);t={ssid:this.ssid,uid:this.uid,cid:this.cid,did:this.did,nick:this.nick,ip:this.ip,tag:e}}let e=Z.pack(Nr("#MsgType","8",ct.IAM_RES),Nr("#info",t));this.send_enc_mode(e)}}const Pr=new TextDecoder;class Dr extends Mr{constructor(t,e,r){super(t,r),this.socketType=t.socketType,"websocket"===this.socketType?(this.TLS="https"===e.headers["x-forwarded-proto"],this.ip=this.getRemoteIP(e)):(this.TLS=!1,this.ip=this.getRemoteIP(t.remoteAddress)),!function(t){if(0===t.indexOf("0.0.0.0"))return!0;if(0===t.indexOf("127.0.0.1"))return!0;if(0===t.indexOf("192.168."))return!0;if(0===t.indexOf("10."))return!0;if(0===t.indexOf("172.")){if(0===t.indexOf("172.16."))return!0;if(0===t.indexOf("172.17."))return!0;if(0===t.indexOf("172.18."))return!0;if(0===t.indexOf("172.19."))return!0;if(0===t.indexOf("172.20."))return!0;if(0===t.indexOf("172.21."))return!0;if(0===t.indexOf("172.22."))return!0;if(0===t.indexOf("172.23."))return!0;if(0===t.indexOf("172.24."))return!0;if(0===t.indexOf("172.25."))return!0;if(0===t.indexOf("172.26."))return!0;if(0===t.indexOf("172.27."))return!0;if(0===t.indexOf("172.28."))return!0;if(0===t.indexOf("172.29."))return!0;if(0===t.indexOf("172.30."))return!0;if(0===t.indexOf("172.31."))return!0}return!1}(this.ip)?this.HOME_CHANNEL="IP:"+function(t){let e=t.split(".");return Buffer.from(e).toString("hex")}(this.ip):(this.HOME_CHANNEL="PRIVATE:",this.privateNode=!0),"websocket"===this.socketType?(Cr.debug.slow?t.on("message",this.onTimeDelayMessage.bind(this)):t.on("message",this.onSocketMessage.bind(this)),t.on("pong",this.receiveMonitor.bind(this)),t.on("ping",this.receiveMonitor.bind(this)),t.on("error",(t=>{console.log("Websocket error",t,t.code)})),t.onclose=t=>{this.manager.removeRemote(this)}):(this.congRx=new Oe,t.on("data",(t=>{this.congRx.write(t)})),this.congRx.on("wrong",this.onWrongCongPacketMessage.bind(this)),Cr.debug.slow?this.congRx.on("data",this.onTimeDelayMessage.bind(this)):this.congRx.on("data",this.onSocketMessage.bind(this)),t.on("error",(t=>{console.log("TCP Socket error",t)})),t.on("close",(t=>{this.manager.removeRemote(this)})))}onWrongCongPacketMessage(t){if(this.cid);else{let e="";try{e=Pr.decode(t)}catch(r){e+="Len: "+t.byteLength}if(this.manager.attackLogger){let t=`> ${this.ssid} ${this.ip} ${e}`;this.manager.attackLogger.log(t)}this.close(!0)}}permissionChecker(){this.socket.bytesWritten||this.socket._socket,this.socket.bytesRead||this.socket._socket}receiveMonitor(){this.socket.rxCounter++,this.socket.isAlive=!0}isConnectionHTTPS(t){return t.headers["x-forwarded-proto"]}getRemoteIP(t){let e;return t&&t.headers?(e=t.headers["x-forwarded-for"],null==e&&(e=t.socket.remoteAddress)):e=t,e?(0==e.indexOf("::ffff:")&&(e=e.substring(7)),"::1"==e&&(e="127.0.0.1")):e="0.0.0.0",e}ping(){"websocket"===this.socketType?(this.socket.ping(),this.socket.txCounter++):this.send(Buffer.from([ct.PING]))}pong(){"websocket"===this.socketType?(this.socket.pong(),this.socket.txCounter++):this.send(Buffer.from([ct.PONG]))}getTraffic(){this.socket.bytesWritten||this.socket._socket,this.socket.bytesRead||this.socket._socket,this.socket.txCounter,this.socket.rxCounter}close(t=!1){this.getTraffic(),"websocket"===this.socketType?t?this.socket.terminate():this.socket.close():t?this.socket.destroy():this.socket.end()}send(t,e){this.manager.txBytes+=t.byteLength,this.socket.txCounter++,"websocket"===this.socketType?1===this.socket.readyState?null!=e?this.socket.send(t,{binary:e}):this.socket.send(t):this.close(!0):"open"==this.socket.readyState?this.socket.write(xe(t)):this.close(!0)}}const $r=new Intl.DateTimeFormat("ko-KR",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",hour12:!1,timeZone:"Asia/Seoul"});class Fr{constructor(t){this.file=i.openSync(t,"a+"),console.log("new FileLogger logFile: ",t,this.file)}log(t){let e=$r.format(new Date)+" "+t+"\n";i.write(this.file,e,(t=>{if(t)throw t}))}}class Hr{constructor(t){this.manager=t,this.metricsPack={remotes:[0],channels:[0],txBytes:[0],rxBytes:[0],unixTime:[Math.floor(Date.now()/1e3)],period:0},this.tickId=setInterval((t=>{this.metricsPack.remotes.push(this.manager.remotes.size),this.metricsPack.remotes.length>10&&this.metricsPack.remotes.shift(),this.metricsPack.channels.push(this.manager.channel_map.size),this.metricsPack.channels.length>10&&this.metricsPack.channels.shift(),this.metricsPack.txBytes.push(this.manager.txBytes),this.metricsPack.txBytes.length>10&&this.metricsPack.txBytes.shift(),this.metricsPack.rxBytes.push(this.manager.rxBytes),this.metricsPack.rxBytes.length>10&&this.metricsPack.rxBytes.shift(),this.metricsPack.unixTime=Math.floor(Date.now()/1e3),this.metricsPack.period=1e4,this.manager.txBytes=0,this.manager.rxBytes=0}),1e4)}oneline(t){let e=[{...g()}];t&&console.table(e,["rss","heapTotal","heapUsed","external","arrayBuffers"]);let r=[{lastSSID:this.manager.lastSSID,remotes:this.manager.remotes.size,channels:this.manager.channel_map.size,txBytes:this.manager.txBytes,rxBytes:this.manager.rxBytes}];return t&&console.table(r,["lastSSID","remotes","channels","txBytes","rxBytes"]),r[0]}getRemotes(t){let e=Array.from(this.manager.remotes.values()).map((t=>"#"+t.ssid+":"+t.cid+"("+t.state+")"));return t&&console.table(e),e}getCIdList(t){let e=Array.from(this.manager.cid2remote.keys());return t&&console.table(e),e}getChannelList(t){let e=Array.from(this.manager.channel_map.keys());return t&&console.table(e),e}getSubscribers(t){let e=[];if(this.manager.channel_map.has(t)){this.manager.channel_map.get(t).forEach((t=>{e.push(t.cid)}))}return e}getRemoteByCId(t,e=1){if(!this.manager.cid2remote.has(t))return{result:"nop"};{let r=this.manager.cid2remote.get(t);if(1==e)return{ip:r.ip,id:r.cid,ssid:r.ssid,cid:r.cid,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),tx:r.socket.txCounter,rx:r.socket.rxCounter,txBytes:r.socket.bytesWritten||r.socket._socket?.bytesWritten,rxBytes:r.socket.bytesRead||r.socket._socket?.bytesRead};if(2==e)return{ip:r.ip,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),nick:r.nick,ssid:r.ssid,echo:r.lastEchoMessage};if(3==e)return{ip:r.ip,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),nick:r.nick,ssid:r.ssid,isSecure:r.TLS,isAuth:r.boho.isAuthorized,encMode:at[r.encMode]};if(4==e){let t=Array.from(r.channels.keys()),e=Array.from(r.memory.keys()),n=Array.from(r.retain_signal.keys());return{ip:r.ip,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),channels:t,set:e,retain:n}}}}}const jr=new TextEncoder,zr=new TextDecoder;class Gr{constructor(t,e){this.server=t,this.txBytes=0,this.rxBytes=0,this.authManager=e,this.connectionLogger,Cr.fileLogger.connection.use&&(this.connectionLogger=new Fr(Cr.fileLogger.connection.path)),this.attackLogger,Cr.fileLogger.attack.use&&(this.attackLogger=new Fr(Cr.fileLogger.attack.path)),this.remotes=new Set,this.cid2remote=new Map,this.retain_messages=new Map,this.channel_map=new Map,this.CHANNEL_PREFIX="CH:",this.CID_PREFIX="CID:",this.metric=new Hr(this),this.lastSSID=0,this.pingIntervalID=setInterval((t=>{this.remotes.forEach((function(t){let e=t.socket;!1===e.isAlive&&(console.log("## timeout. cid:",t.cid),t.close()),e.txCounter++,e.isAlive=!1,"websocket"===t.socketType?e.ping():t.ping()}))}),Cr.timeout),Cr.showMetric&&(this.monitIntervalID=setInterval((t=>{this.monitor()}),Cr.monitorPeriod))}addRemote(t,e){t.isAlive=!0;let r=new Dr(t,e,this);this.remotes.add(r),r.send(Buffer.from([ct.SERVER_READY])),r.setState(ot.SENT_SERVER_READY),this.lastSSID=r.ssid;let n=`+ IP:${r.ip} #${r.ssid} ${"websocket"===t.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(n)}removeRemote(t){let e=`- IP:${t.ip} #${t.ssid} cid:${t.cid} ${"websocket"===t?.socket.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(e),this.deligateSignal(t,"@state","close"),this.deligateSignal(t,"@$state","close");for(let e of t.channels.keys())if(this.channel_map.has(e)){const r=this.channel_map.get(e);r.delete(t),0==r.size&&this.channel_map.delete(e)}if(t.boho.isAuthorized);else for(let e of t.retain_signal.keys())e=this.CID_PREFIX+t.cid+"@"+e,this.channel_map.has(e)&&this.channel_map.delete(e);if(t.uid&&this.server.apiNames.has("account")){let e={topic:"detachUserRemote",args:["caller:manager.removeRemote"]};this.server.emit("account",t,e)}this.remotes.delete(t),this.cid2remote.delete(t.cid),t=null}serverSignal(t){let e=Z.pack(Z.MB("#MsgType","8",ct.SERVER_SIGNAL),Z.MB("#signalObject",t));this.remotes.forEach((t=>{t.send_enc_mode(e)}))}getSignalTag(t){let e=t.readUint8(1),r=t.subarray(2,2+e);return zr.decode(r)}getNewSignalTagMessage(t,e){let r=t[0],n=t.readUint8(1),i=jr.encode(e),s=i.byteLength,o=t.subarray(2+n);return Buffer.concat([Buffer.from([r,s]),i,o])}deligateSignal(t,e,...r){let n=gt(e,...r);this.sender(e,t,n)}adminSignal(t,e){return this.cid2remote.has(t)?void this.cid2remote.get(t).send_enc_mode(e):"no cid"}serverSignalTo(t,...e){let r=t.split("@")[0],n=gt("@"+t.split("@")[1],...e);if(r&&this.cid2remote.has(r)){let t=this.cid2remote.get(r);return console.log("target",t.state,t.cid),void t.send_enc_mode(n)}return"no cid"}sender(t,e,r){if(Cr.memberOnly&&!e.boho.isAuthorized)return e.send(Buffer.from([ct.SERVER_CLEAR_AUTH])),e.close(),["err","not autrized"];if(0==t.indexOf("$"))return["err","prefix $ is reserved for userSet tag."];let n=t.indexOf("@");if(0===n)t=e.cid+t,r=this.getNewSignalTagMessage(r,t);else if(n>0){let e=t.split("@")[0];if(this.cid2remote.has(e)){let n="@"+t.split("@")[1];return r=this.getNewSignalTagMessage(r,n),this.cid2remote.get(e).send_enc_mode(r),["ok",1]}return["err","Invalid cid"]}if((t=0===t.indexOf("#")?e.HOME_CHANNEL+t:t.includes("@")?this.CID_PREFIX+t:this.CHANNEL_PREFIX+t).includes("$")&&Cr.retain.isAvailable&&Cr.retain.limitCounter>this.retain_messages.size&&Cr.retain.limitSize>r.byteLength)if(t.includes("@")){let n=t.split("@")[1];e.retain_signal.set(n,r)}else this.retain_messages.set(t,r);let i=0;if(this.channel_map.has(t)){let n=this.channel_map.get(t);if(n.size>=1){let t;t=Cr.useQuota.publishCounter?Math.min(e.quota.publishCounter,n.size):n.size;let s=n.values();for(;i<t;){let t=s.next().value;if(!t)break;t!==e&&(t.send_enc_mode(r),i++)}return Cr.useQuota.publishCounter,["ok",i]}}return["err","No subscriber."]}subscribe(t,e){return t.forEach((t=>{if(t=0===t.indexOf("#")?e.HOME_CHANNEL+t:t.includes("@")?this.CID_PREFIX+t:this.CHANNEL_PREFIX+t,this.channel_map.has(t)?this.channel_map.get(t).add(e):this.channel_map.set(t,new Set([e])),e.channels.add(t),t.includes("$")&&Cr.retain.isAvailable){let r;if(t.includes("@")){let e=t.split("@")[0];e=e.split(this.CID_PREFIX)[1];let n=t.split("@")[1];if(!this.cid2remote.has(e))return;r=this.cid2remote.get(e).retain_signal.get(n)}else this.retain_messages.has(t)&&(r=this.retain_messages.get(t));r&&e.send_enc_mode(r)}})),e.channels.size}unsubscribe(t,e){1==t.length&&""==t[0]?(e.channels.forEach((t=>{if(this.channel_map.has(t)){let r=this.channel_map.get(t);r.delete(e),0==r.size&&this.channel_map.delete(t)}})),e.channels.clear()):t.forEach((t=>{if(t=0===t.indexOf("#")?e.HOME_CHANNEL+t:t.includes("@")?this.CID_PREFIX+t:this.CHANNEL_PREFIX+t,this.channel_map.has(t)){let r=this.channel_map.get(t);r.delete(e),0==r.size&&this.channel_map.delete(t)}e.channels.delete(t)}))}monitor(){switch(process.stdout.isTTY&&(process.stdout.cursorTo(0,0),process.stdout.clearScreenDown()),Cr.showChannel>0&&this.metric.channels(Cr.showChannel),parseInt(Cr.showMetric)){case 1:this.metric.oneline(!0);break;case 2:this.metric.getRemotes(!0);break;case 3:this.metric.getChannelList(!0)}}closeRemoteByCId(t){return this.cid2remote.has(t)?(this.cid2remote.get(t).close(),1):0}}const Wr=0,Vr=255;class qr extends c{constructor(t,e){if(super(),this.apiNames=new Set,this.wss={},t.timeout){let e=parseInt(t.timeout);e&&e>=1e3&&(Cr.timeout=e)}if(t.monitorPeriod){let e=parseInt(t.monitorPeriod);e&&e>=1e3&&(Cr.monitorPeriod=e)}t.showMessage&&(Cr.showMessage=t.showMessage),t.showMetric&&(Cr.showMetric=t.showMetric),t.timeout&&(Cr.timeout=t.timeout),t.port&&(Cr.port=parseInt(t.port)),t.httpServer&&(Cr.httpServer=t.httpServer),t.congPort&&(Cr.congPort=parseInt(t.congPort)),this.manager=new Gr(this,e),(Cr.port||Cr.httpServer)&&this.startWSServer(Cr),Cr.congPort&&this.startCongServer(Cr.congPort)}startWSServer(t){if(t.port)console.log("opening WebSocket Server port:",t.port),this.wss=new xr({port:t.port});else{if(!t.httpServer)throw new TypeError('One and only one of the "port", "httpServer"must be specified');console.log("opening WebSocket Server external httpServer:"),this.wss=new xr({server:t.httpServer})}this.wss.on("error",(t=>{console.error("### ws server error:",t.message),"EADDRINUSE"==t.code&&process.exit()})),this.wss.on("close",(t=>{console.log("### WS server closed.",t)})),this.wss.on("connection",((t,e)=>{t.socketType="websocket",this.manager.addRemote(t,e)}))}startCongServer(t){console.log("opening CongSocket Server:",t),this.congServer=r.createServer((t=>{this.manager.addRemote(t)})).on("error",(t=>{console.log("### cong server error:",t.message),"EADDRINUSE"==t.code&&process.exit()})).listen(t,(()=>{}))}api(t,e){if(this.apiNames.add(t),!e.checkPermission||"function"!=typeof e.checkPermission)throw new Error("wrong api interface. no checkPermission function.");if("function"==typeof e.request&&Array.isArray(e.commands))console.log(`API TYPE1. A Class with one request function. target: ${t} list: ${e.commands}`),this.on(t,((t,r)=>{e.checkPermission(t,r)?e.request(t,r):t.response(r.mid,Vr,"NO_PERMISSION.")}));else{let r=[];Object.keys(e).forEach((t=>{"function"==typeof e[t]&&r.push(t),console.log("api list",typeof e[t],t)})),console.log(`API TYPE2. Multiple function list. target: ${t} list:${r}`),this.on(t,((r,n)=>{let i;if(e.checkPermission(r,n)){if(e[n.topic])return console.log(`API TYPE2. request target: ${t} has topic:${n.topic}`),void e[n.topic](r,n);i=`target: ${n.target} has not topic name: ${n.topic}`}else i="NO_PERMISSION.";r.response(n.mid,Vr,i)}))}return this}}const Yr=new TextDecoder;class Qr{constructor(){this.authLogger,Cr.fileLogger.auth.use&&(this.authLogger=new Fr(Cr.fileLogger.auth.path),console.log("Auth: begin file logger.[auth]"))}send_auth_fail(t,e){if(this.authLogger){let r=`FAIL #${t.ssid} reason:${e} `;this.authLogger.log(r)}console.log("## AUTH_FAIL reason:",e),t.setState(ot.AUTH_FAIL),setTimeout((e=>{t.send(Buffer.from([Be.BohoMsg.AUTH_FAIL]))}),Cr.auth.delay_auth_fail)}async verify_auth_hmac(t,e){try{let r=Z.unpack(t,Be.Meta.AUTH_HMAC);if(!r)return void this.send_auth_fail(e,"unpack auth_pack fail");let n="";n=r.id8.includes(0)?Yr.decode(r.id8.subarray(0,r.id8.indexOf(0))):Yr.decode(r.id8);let i,s=await this.getAuth(n);if(Cr.debug.showAuthInfo,!s)return void this.send_auth_fail(e,"NO ID:"+n);e.boho.copy_id8(r.id8);const o=44;s.key.length==o?(i=Buffer.from(s.key,"base64"),e.boho.copy_key(i)):e.boho.set_key(s.key);let a=e.boho.check_auth_hmac(r);if(!a)return void this.send_auth_fail(e,"hmac dismatched");if(e.manager.cid2remote.has(s.cid)){let t=e.manager.cid2remote.get(s.cid);return t==e?void console.log("## trying RELOGIN with SAME ID. ignored."):(console.log("### clear_auth and close old connection:",t.cid),t.send(Buffer.from([ct.SERVER_CLEAR_AUTH])),t.close(),void e.close())}e.cid&&e.manager.cid2remote.delete(e.cid),e.did=n,e.cid=s.cid,e.nick=s.cid;let h=Cr.defaultQuotaIndex;s.level&&(h=s.level),h=parseInt(h);let f=pt[h];if(!f){let t="no index quotaTable for auth.level: "+h;return console.log("##AUTH:DATA ERROR##",t),void this.send_auth_fail(e,t)}if(e.level=h,e.quota=f,e.level===Cr.adminLevel&&(console.log("## LOGIN ADMIN CID:",e.cid),e.isAdmin=!0),e.send(Buffer.from([ct.QUOTA_LEVEL,h])),e.manager.cid2remote.set(e.cid,e),e.send(a),e.setState(ot.AUTH_READY),this.authLogger){let t=`OK #${e.ssid} cid: ${e.cid} did:${e.did}`;e.isAdmin&&(t="#ADMIN# "+t),this.authLogger.log(t)}return s}catch(t){this.send_auth_fail(e,"caught: unknown error"+t)}}}class Jr extends Qr{constructor(t){super(),this.AUTH=new Map;let e=o.parse(t);this.path=o.resolve(t),console.log("auth from file path:",this.path);let r=e.ext;".js"==r.toLowerCase()||".mjs"==r.toLowerCase()?(console.log("#JS path:",this.path),this.loadAuthInfoFile_JS(this.path)):".json"==r.toLowerCase()?(console.log("#JSON path:",this.path),this.loadAuthInfoFile_JSON(this.path)):console.log("no authinfofile path.")}async getAuth(t){return this.AUTH.get(t)}async getAuthIdList(){return Array.from(this.AUTH.keys())}loadAuthInfoFile_JS(t){import(t).then((t=>{console.log(t.authInfo),t.authInfo.forEach((t=>{this.addAuth(...t)})),console.log("total AUTH INFO size: ",this.AUTH.size)})).catch((t=>{console.log(t)}))}loadAuthInfoFile_JSON(t){let e=s(t);e=(new TextDecoder).decode(e),JSON.parse(e).forEach((t=>{this.addAuth(...t)})),console.log("total AUTH INFO size: ",this.AUTH.size)}addAuth(t,e,r,n=0){let i=Buffer.from(Be.sha256.hash(e)).toString("base64");this.AUTH.set(t,{key:i,cid:r,level:n})}}class Xr extends Qr{constructor(t){let e;super(),t?e=t.split(","):process.env.BOHO_AUTH?(t=process.env.BOHO_AUTH,e=process.env.BOHO_AUTH.split(",")):(console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo"),process.exit()),this.AUTH=new Map,e.length>=1?e.forEach((t=>{let e=t.split(".")[0],r=t.split(".")[1],n=t.split(".")[2];if(n=parseInt(n),e&&r&&"number"==typeof n){let t=e;this.addAuth(e,r,t,n)}else console.log("Wrong process.env.BOHO_AUTH authentication value.",id,r,n),process.exit()})):(console.log("Wrong process.env.BOHO_AUTH authentication value."),process.exit())}async getAuth(t){return this.AUTH.get(t)}async getAuthIdList(){return Array.from(this.AUTH.keys())}addAuth(t,e,r,n=0){let i=Buffer.from(Be.sha256.hash(e)).toString("base64");this.AUTH.set(t,{key:i,cid:r,level:n})}}const Kr="device:";class Zr extends Qr{constructor(t){if(super(),!t)throw new Error("AuthRedis constructor: no redisClient");this.redis=t}async getAuth(t){let e=await this.redis.hGetAll(Kr+t);if(e.key)return e}async getAuthIdList(){let t=await this.redis.keys(Kr+"*");if(t=t.map((t=>t.split(":")[1])),t)return t}async addAuth(t,e,r="",n=0){let i=Buffer.from(Be.sha256.hash(e)).toString("base64");return this.redis.hSet(Kr+t,{key:i,cid:r,level:n})}async delAuth(t){return this.redis.del(Kr+t)}async save(t){return this.redis.save()}}var tn=Object.freeze({__proto__:null,checkPermission:function(t){return t.level>=0},date:async function(t,e){let r=(new Date).toUTCString();t.response(e.mid,Wr,r)},echo:async function(t,e){e.args?t.response(e.mid,Wr,e.args):t.response(e.mid,Vr,"no message to echo")},unixtime:async function(t,e){let r=Math.floor(Date.now()/1e3);t.response(e.mid,Wr,r)}});var en=Object.freeze({__proto__:null,checkPermission:function(t){return t.level>=255},commands:["cid","remotes","clients","channels","subscribers","remote","client","close","addauth","getauth","delauth","getauthidlist","getdevicelist","adddevice","getdevice","deldevice"],request:async function(t,e){let r,n=0;try{let i=e.topic;if(i=i.toLowerCase(),"cid"==i)r=t.manager.metric.getCIdList();else if("remotes"==i||"clients"==i)r=t.manager.metric.getRemotes();else if("channels"==i)r=t.manager.metric.getChannelList();else if("subscribers"==i){let n=e.$[0];n&&(r=t.manager.metric.getSubscribers(n))}else if("remote"==i||"client"==i){let n=e.$[0],i=e.$[1];n&&(r=t.manager.metric.getRemoteByCId(n,i))}else if("close"==i)e.$[0]&&(r=t.manager.closeRemoteByCId(e.$[0]));else if("addauth"==i||"adddevice"==i){if(t.manager.authManager&&4==e.$.length&&t.manager.authManager.addAuth){let n=e.$[0],i=e.$[1],s=e.$[2],o=e.$[3];r=await t.manager.authManager.addAuth(n,i,s,o)}}else if("delauth"==i||"deldevice"==i){if(t.manager.authManager&&1==e.$.length&&t.manager.authManager.delAuth){let n=e.$[0];r=await t.manager.authManager.delAuth(n)}}else if("getauth"==i||"getdevice"==i){if(t.manager.authManager&&1==e.$.length&&t.manager.authManager.getAuth){let n=e.$[0];r=await t.manager.authManager.getAuth(n)}}else"getauthidlist"==i||"getdevicelist"==i?t.manager.authManager&&t.manager.authManager.getAuthIdList&&(r=await t.manager.authManager.getAuthIdList()):(n=Vr,r="api sudo: no such a cmd: "+i);t.response(e.mid,n,r)}catch(r){t.response(e.mid,Vr,r.message)}}});const rn=["GET","SET","HGETALL","HGET","HSET","SADD","SISMEMBER","SMEMBERS","EXISTS","SREM","DEL","KEYS","SAVE"];class nn{constructor(t,e){if(!t)throw new Error("RedisAPI constructor: no redisClient");this.redisClient=t,this.minLevel=e||200,this.commands=rn}checkPermission(t,e){return console.log("checkPermission",t.level,"vs",this.minLevel),t.level>=this.minLevel}async request(t,e){let r,n=Wr;try{let i=e.topic;i=i.toUpperCase(),rn.includes(i)?(console.log("RedisAPI call:",i,e.args),r=e.args.length>0?await this.redisClient[i](...e.args):await this.redisClient[i]()):n=Vr,t.response(e.mid,n,r)}catch(r){t.response(e.mid,Vr,r.message)}}}export{ut as API_TYPE,Xr as Auth_Env,Jr as Auth_File,Zr as Auth_Redis,Be as Boho,Qr as BohoAuth,ot as CLIENT_STATE,Oe as CongRx,at as ENC_MODE,Fr as FileLogger,Or as IO,Ce as IOCongSocket,ct as IOMsg,Z as MBP,ft as PAYLOAD_TYPE,nn as RedisAPI,ht as SIZE_LIMIT,st as STATES,lt as STATUS,qr as Server,tn as api_reply,en as api_sudo,mt as getPayloadFromSignalPack,gt as getSignalPack,xe as pack,yt as parsePayload,Cr as serverOption,y as version};
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
+ export {version} from "./package.json";
1
2
  export { IOCongSocket } from './src/client/IOCongSocket.js'
2
- export { IOWS } from './src/client/IOWS.js'
3
+ export { IOWS as IO } from './src/client/IOWS.js'
3
4
  export { pack, CongRx } from './src/client/CongPacket.js'
4
5
  export { Server } from './src/server/Server.js'
5
6
  export { serverOption } from './src/server/serverOption.js'