iosignal 2.1.0 → 2.2.1

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.
package/dist/iosignal.cjs CHANGED
@@ -1,20 +1,18 @@
1
- "use strict";for(var e=require("stream"),t=require("net"),r=require("zlib"),n=require("fs"),i=require("path"),s=require("os"),o=require("buffer"),a=require("crypto"),h=require("events"),f=require("https"),c=require("http"),u=require("tls"),l=require("url"),p=require("process"),d={},g={byteLength:function(e){var t=w(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=w(e),i=n[0],s=n[1],o=new _(function(e,t,r){return 3*(t+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)t=m[e.charCodeAt(r)]<<18|m[e.charCodeAt(r+1)]<<12|m[e.charCodeAt(r+2)]<<6|m[e.charCodeAt(r+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=255&t;return 2===s&&(t=m[e.charCodeAt(r)]<<2|m[e.charCodeAt(r+1)]>>4,o[a++]=255&t),1===s&&(t=m[e.charCodeAt(r)]<<10|m[e.charCodeAt(r+1)]<<4|m[e.charCodeAt(r+2)]>>2,o[a++]=t>>8&255,o[a++]=255&t),o},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(B(e,o,o+s>a?a:o+s));return 1===n?(t=e[r-1],i.push(y[t>>2]+y[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(y[t>>10]+y[t>>4&63]+y[t<<2&63]+"=")),i.join("")}},y=[],m=[],_="undefined"!=typeof Uint8Array?Uint8Array:Array,b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",E=0;E<64;++E)y[E]=b[E],m[b.charCodeAt(E)]=E;function w(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function B(e,t,r){for(var n,i,s=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),s.push(y[(i=n)>>18&63]+y[i>>12&63]+y[i>>6&63]+y[63&i]);return s.join("")}m["-".charCodeAt(0)]=62,m["_".charCodeAt(0)]=63;var v={
2
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3
- read:function(e,t,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=e[t+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+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(e,t,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=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=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=(t*h-1)*Math.pow(2,i),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=255&o,p+=d,o/=256,f-=8);e[r+p-d]|=128*g}};
1
+ "use strict";var e,t,r,n=require("stream"),i=require("net"),s=require("events"),o=require("https"),a=require("http"),h=require("tls"),f=require("crypto"),c=require("url"),u=require("zlib"),l=require("fs"),p=require("path"),d=require("os"),g=require("buffer"),y=require("process"),m={},_={},b={};
4
2
  /*!
5
3
  * The buffer module from node.js, for the browser.
6
4
  *
7
5
  * @author Feross Aboukhadijeh <https://feross.org>
8
6
  * @license MIT
9
- */!function(e){const t=g,r=v,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|p(e,t);let n=s(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(Q(e,Uint8Array)){const t=new Uint8Array(e);return u(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(Q(e,ArrayBuffer)||e&&Q(e.buffer,ArrayBuffer))return u(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(Q(e,SharedArrayBuffer)||e&&Q(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);const i=function(e){if(o.isBuffer(e)){const t=0|l(e.length),r=s(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||J(e.length)?s(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return h(e),s(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=s(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function u(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function l(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||Q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return V(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(e).length;default:if(i)return n?-1:V(e).length;t=(""+t).toLowerCase(),i=!0}}function d(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return x(this,t,r);case"utf8":case"utf-8":return k(this,t,r);case"ascii":return I(this,t,r);case"latin1":case"binary":return T(this,t,r);case"base64":return A(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function y(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function m(e,t,r,n,i){if(0===e.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:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:_(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):_(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function _(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function b(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(J(n))return o;e[r+o]=n}return o}function E(e,t,r,n){return Y(V(t,e.length-r),e,r,n)}function w(e,t,r,n){return Y(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function B(e,t,r,n){return Y(q(t),e,r,n)}function S(e,t,r,n){return Y(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function A(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function k(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=L)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=L));return r}(n)}e.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,r){return a(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return h(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},o.allocUnsafe=function(e){return f(e)},o.allocUnsafeSlow=function(e){return f(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(Q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),Q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=o.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(Q(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)y(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)y(this,t,t+3),y(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)y(this,t,t+7),y(this,t+1,t+6),y(this,t+2,t+5),y(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?k(this,0,e):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(Q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<h;++e)if(f[e]!==c[e]){s=f[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return m(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return m(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>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,e,t,r);case"utf8":case"utf-8":return E(this,e,t,r);case"ascii":case"latin1":case"binary":return w(this,e,t,r);case"base64":return B(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,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(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function T(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function x(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=X[e[n]];return i}function U(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function O(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function C(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function R(e,t,r,n,i){j(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function N(e,t,r,n,i){j(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function M(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(e,t,n,i,s){return t=+t,n>>>=0,s||M(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function D(e,t,n,i,s){return t=+t,n>>>=0,s||M(e,0,n,8),r.write(e,t,n,i,52,8),n+8}o.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||O(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=K((function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=K((function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||O(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||O(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},o.prototype.readInt8=function(e,t){return e>>>=0,t||O(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||O(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||O(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||O(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=K((function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=K((function(e){z(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||W(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||O(e,4,this.length),r.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||O(e,4,this.length),r.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||O(e,8,this.length),r.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||O(e,8,this.length),r.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||C(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||C(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=K((function(e,t=0){return R(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=K((function(e,t=0){return N(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=K((function(e,t=0){return R(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=K((function(e,t=0){return N(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,r){return P(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return P(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return D(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return D(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};const $={};function F(e,t,r){$[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function H(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function j(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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,e)}!function(e,t,r){z(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||W(t,e.length-(r+1))}(n,i,s)}function z(e,t){if("number"!=typeof e)throw new $.ERR_INVALID_ARG_TYPE(t,"number",e)}function W(e,t,r){if(Math.floor(e)!==e)throw z(e,r),new $.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new $.ERR_BUFFER_OUT_OF_BOUNDS;throw new $.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}F("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),F("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),F("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" 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 ${t}. Received ${i}`,n}),RangeError);const G=/[^+/0-9A-Za-z-_]/g;function V(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function q(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(G,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Y(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function J(e){return e!=e}const X=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function K(e){return"undefined"==typeof BigInt?Z:e}function Z(){throw new Error("BigInt not supported")}}(d);const S=new TextEncoder,A=new TextDecoder,k=L;function L(e,t=0){let r;if(void 0===e||"string"!=typeof e||"number"!=typeof t)throw TypeError("invlaid init variablie type name. ");return(e=e.toUpperCase()).includes("8")?(r=d.Buffer.alloc(1),e.includes("I")?r.writeInt8(t):r.writeUint8(t)):e.includes("16")?(r=d.Buffer.alloc(2),e.includes("I")?e.includes("L")?r.writeInt16LE(t):r.writeInt16BE(t):e.includes("L")?r.writeUint16LE(t):r.writeUint16BE(t)):e.includes("32")?(r=d.Buffer.alloc(4),e.includes("I")?e.includes("L")?r.writeInt32LE(t):r.writeInt32BE(t):e.includes("L")?r.writeUint32LE(t):r.writeUint32BE(t)):e.includes("F")?(r=d.Buffer.alloc(4),e.includes("L")?r.writeFloatLE(t):r.writeFloatBE(t)):e.includes("N")?r=d.Buffer.from(String(t)):console.log(`invalid type: ${e} or initvalue: ${t}`),r}const I=T;function T(e,t,r){let n,i="B";if("number"==typeof t)"number"==typeof r?(n=d.Buffer.alloc(t),0!==r&&n.fill(r),i="B"):(n=d.Buffer.from(String(t)),i="N");else if("string"==typeof t&&"number"==typeof r)i=t.toUpperCase(),n=L(t,r);else if("string"==typeof t&&void 0===r)n=d.Buffer.from(t),i="S";else if(t instanceof Uint8Array&&void 0===r)n=t instanceof d.Buffer?t:d.Buffer.from(t);else if(t instanceof ArrayBuffer&&void 0===r)n=d.Buffer.from(t);else if(ArrayBuffer.isView(t))n=d.Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if("object"==typeof t&&void 0===r)n=d.Buffer.from(JSON.stringify(t)),i="O";else{if("boolean"!=typeof t||void 0!==r)throw TypeError("invalid meta buffer type");{const e=t?1:0;n=d.Buffer.from([e]),i="!"}}return"string"==typeof e&&e.includes("#")&&(e=""),[e,i,n]}const x=U;function U(...e){let t=0;return e.map((e=>{const r=t++;return"number"==typeof e?I(r,"N",e):I(r,e)}))}function O(e){if((e=e.toUpperCase()).includes("8"))return e.includes("I")?"int8":"uint8";if(e.includes("16"))return e.includes("I")?e.includes("L")?"int16_le":"int16_be":e.includes("L")?"uint16_le":"uint16_be";if(e.includes("32"))return e.includes("I")?e.includes("L")?"int32_le":"int32_be":e.includes("L")?"uint32_le":"uint32_be";if(e.includes("F"))return e.includes("L")?"float_le":"float_be";if("B"===e)return"buffer";if("S"===e)return"string";if("N"===e)return"number";if("O"===e)return"object";if("!"===e)return"boolean";throw TypeError("invalid data type")}function C(e,t,r,n){try{const i=O(e);if("int8"==i)return t.readInt8(r);if("uint8"===i)return t.readUint8(r);if("int16_le"===i)return t.readInt16LE(r);if("int16_be"===i)return t.readInt16BE(r);if("uint16_le"===i)return t.readUint16LE(r);if("uint16_be"===i)return t.readUint16BE(r);if("int32_le"===i)return t.readInt32LE(r);if("int32_be"===i)return t.readInt32BE(r);if("uint32_le"===i)return t.readUint32LE(r);if("uint32_be"===i)return t.readUint32BE(r);if("float_le"===i)return t.readFloatLE(r);if("float_be"===i)return t.readFloatBE(r);if("buffer"===i)return t.subarray(r,r+n);if("string"===i){const e=t.subarray(r,r+n);return A.decode(e)}if("number"===i){const e=t.subarray(r,r+n);return Number(A.decode(e))}if("object"===i){const e=t.subarray(r,r+n);return JSON.parse(A.decode(e))}return"boolean"===i?1===t.readInt8(r):void 0}catch(e){}}function R(...e){const t=function(e){let t=[];return e.filter((e=>{if(!Array.isArray(e[0]))return e;t=t.concat(e)})).concat(t)}(e);let r=0;const n=[];let i,s,o=0;if(t.forEach((e=>{const[t,i,s]=e;r+=s.byteLength,("number"==typeof t||t.length>0)&&n.push([t,i,o,s.byteLength]),o=r})),n.length>0){let e=JSON.stringify(n);i=S.encode(e),s=i.byteLength,r=r+s+2}const a=d.Buffer.alloc(r);if(o=0,t.forEach((e=>{const t=e[2];a.set(t,o),o+=t.byteLength})),n.length>0){a.set(i,o);const e=k("16",s);return a.set(e,o+s),a}return a}const N=M;function M(e,t=!1){if(void 0===e)throw TypeError("Invalid data type: Undefined");if("string"==typeof e)return S.encode(e);if("number"==typeof e)return Uint8Array.from([e]);if(e instanceof ArrayBuffer){if(t)return new Uint8Array(e);{const t=new Uint8Array(e),r=new Uint8Array(e.byteLength);return r.set(t),r}}if(ArrayBuffer.isView(e)){if(t)return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);{const t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(e.byteLength);return r.set(t),r}}return S.encode(JSON.stringify(e))}const P=D;function D(e,t=!1){const r=M(e,t);return t?d.Buffer.from(r.buffer,r.byteOffset,r.byteLength):d.Buffer.from(r)}const $=F;function F(...e){const t=e.map((e=>D(e)));return d.Buffer.concat(t)}const H=j;function j(...e){try{let t=0,r=0;const n=e.map((e=>M(e)));n.forEach((e=>{t+=e.byteLength}));const i=new Uint8Array(t);return n.forEach((e=>{i.set(e,r),r+=e.byteLength})),i}catch(e){console.log(e)}}function z(e){return 0===q(e)?e.byteLength:e.byteLength-q(e)-G}function W(e,t){try{const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=r.byteLength-t-2,i=r.subarray(n,r.byteLength-2),s=A.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(e){}}const G=2;function V(e){return e instanceof ArrayBuffer&&(e=d.Buffer.from(e)),e instanceof Uint8Array?e.byteLength<=G?0:new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(e.byteLength-G):0}function q(e){if(e instanceof ArrayBuffer&&(e=d.Buffer.from(e)),e instanceof Uint8Array){const t=e.byteLength;if(t<=G)return 0;const r=V(e);return 0===r||r>t?0:W(e,r)?r:0}return 0}function Y(e){const t=z(e);return e.subarray(0,t)}function Q(e,t=!1){e instanceof ArrayBuffer&&(e=d.Buffer.from(e));const r=V(e);if(0===r)return;let n=W(e,r);return n?t?(n.forEach((e=>{null==e[3]&&(e[1].includes("8")?e[3]=1:e[1].includes("16")?e[3]=2:e[1].includes("32")||e[1].includes("F")?e[3]=4:e[1].includes("!")&&(e[3]=1)),e[4]=O(e[1])})),n):n:void 0}var J=Object.freeze({__proto__:null,B8:P,B8pack:$,Buffer:d.Buffer,MB:I,MBA:x,NB:k,TAIL_LEN:G,U8:N,U8pack:H,equal:function(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},getBuffer:Y,getBufferSize:z,getMeta:Q,getMetaDetail:function(e){return Q(e,!0)},getMetaSize:q,hex:function(e){return Array.prototype.map.call(new Uint8Array(e),(e=>("00"+e.toString(16)).slice(-2))).join("")},meta:function(...e){return Q(R(...e))},metaBuffer:T,metaBufferArguments:U,metaDetail:function(...e){return Q(R(...e),!0)},numberBuffer:L,pack:R,parseBuffer:D,parseBufferThenConcat:F,parseMetaInfo:W,parseTypeName:O,parseUint8Array:M,parseUint8ThenConcat:j,rawPack:function(...e){return Y(R(...e))},readTail:V,readTypedBuffer:C,unpack:function(e,t){const r=t||Q(e);if(!r)return;const n=d.Buffer.from(e),i={};let s=0;if(r.forEach((e=>{const[t,r,o,a]=e;let h=C(r,n,o,a);null!=h&&(i[t]=h,a&&(s+=a))})),t&&n.byteLength!==s){let e=n.byteLength-s,t=C("b",n,s,e);if(null==t)return;i.$OTHERS=t}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});function X(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var K={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function i(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,n,s,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,s||e,o),h=r?r+t:t;return e._events[h]?e._events[h].fn?e._events[h]=[e._events[h],a]:e._events[h].push(a):(e._events[h]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}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 e,n,i=[];if(0===this._eventsCount)return i;for(n in e=this._events)t.call(e,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];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(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,i,s,o){var a=r?r+e:e;if(!this._events[a])return!1;var h,f,c=this._events[a],u=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,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(e,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,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,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(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,n,i){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||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!==t||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(e){var t;return e?(t=r?r+e:e,this._events[t]&&o(this,t)):(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,e.exports=a}(K);var Z=X(K.exports);const ee={OPENING:0,OPEN:1,CLOSING:2,CLOSED:3,SERVER_READY:4,AUTH_FAIL:5,AUTH_READY:6,READY:7,REDIRECTING:8};for(let e in ee)ee[ee[e]]=e;const te={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 e in te)te[te[e]]=e;let re={NO:0,YES:1,AUTO:2};for(let e in re)re[re[e]]=e;const ne={TAG_LEN1:255,TAG_LEN2:65535,CONNECTION_CHECKER_PERIOD:3e3,PROMISE_TIMEOUT:5e3,DID:8,CID:12};let ie={EMPTY:0,TEXT:1,BINARY:2,OBJECT:3,MJSON:4,MBA:5};for(let e in ie)ie[ie[e]]=e;let se={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 e in se)se[se[e]]=e;let oe={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 ae=new TextEncoder;function he(e,...t){if("string"!=typeof e)throw TypeError("tag should be string.");let r,n=ae.encode(e),i=fe(t);if(i.type==ie.EMPTY)r=J.pack(J.MB("#MsgType","8",se.SIGNAL),J.MB("#tagLen","8",n.byteLength),J.MB("#tag",n),J.MB("#payloadType","8",i.type));else if(i.type==ie.MBA){let e=J.pack(J.MBA(...t));r=J.pack(J.MB("#MsgType","8",se.SIGNAL),J.MB("#tagLen","8",n.byteLength),J.MB("#tag",n),J.MB("#payloadType","8",i.type),J.MB("#mbaBuffer",e))}else r=J.pack(J.MB("#MsgType","8",se.SIGNAL),J.MB("#tagLen","8",n.byteLength),J.MB("#tag",n),J.MB("#payloadType","8",i.type),J.MB("#payload",i.buffer));return r}function fe(e){let t,r;if(0==e.length)t=ie.EMPTY,r=null;else if(1==e.length)if("string"==typeof e[0]||"number"==typeof e[0])t=ie.TEXT,r=ae.encode(e[0]+"."),r[r.byteLength-1]=0;else if(ArrayBuffer.isView(e[0])||e[0]instanceof ArrayBuffer)t=ie.BINARY,r=J.B8(e[0]);else{if("object"!=typeof e[0])throw new Error("unknown payload arguments");t=ie.OBJECT,r=ae.encode(JSON.stringify(e[0]))}else{let n=!1;e.forEach((e=>{(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)&&(n=!0)})),n?t=ie.MBA:(t=ie.MJSON,r=ae.encode(JSON.stringify(e)))}return{type:t,buffer:r}}const ce=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 ue(e,t,r,n,i){let s,o,a,h,f,c,u,l,p,d,g,y,m;for(;i>=64;){for(s=t[0],o=t[1],a=t[2],h=t[3],f=t[4],c=t[5],u=t[6],l=t[7],d=0;d<16;d++)g=n+4*d,e[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=e[d-2],y=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,p=e[d-15],m=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,e[d]=(y+e[d-7]|0)+(m+e[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+(ce[d]+e[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;t[0]+=s,t[1]+=o,t[2]+=a,t[3]+=h,t[4]+=f,t[5]+=c,t[6]+=u,t[7]+=l,n+=64,i-=64}return n}const le=function(){function e(){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 e.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},e.prototype.clean=function(){for(var e=0;e<this.buffer.length;e++)this.buffer[e]=0;for(e=0;e<this.temp.length;e++)this.temp[e]=0;this.reset()},e.prototype.update=function(e,t){if(void 0===t&&(t=e.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");let r=0;if(this.bytesHashed+=t,this.bufferLength>0){for(;this.bufferLength<64&&t>0;)this.buffer[this.bufferLength++]=e[r++],t--;64===this.bufferLength&&(ue(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(t>=64&&(r=ue(this.temp,this.state,e,r,t),t%=64);t>0;)this.buffer[this.bufferLength++]=e[r++],t--;return this},e.prototype.finish=function(e){if(!this.finished){const e=this.bytesHashed,r=this.bufferLength,n=e/536870912|0,i=e<<3,s=e%64<56?64:128;this.buffer[r]=128;for(var t=r+1;t<s-8;t++)this.buffer[t]=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,ue(this.temp,this.state,this.buffer,0,s),this.finished=!0}for(t=0;t<8;t++)e[4*t+0]=this.state[t]>>>24&255,e[4*t+1]=this.state[t]>>>16&255,e[4*t+2]=this.state[t]>>>8&255,e[4*t+3]=this.state[t]>>>0&255;return this},e.prototype.digest=function(){const e=new Uint8Array(this.digestLength);return this.finish(e),e},e.prototype._saveState=function(e){for(let t=0;t<this.state.length;t++)e[t]=this.state[t]},e.prototype._restoreState=function(e,t){for(let t=0;t<this.state.length;t++)this.state[t]=e[t];this.bytesHashed=t,this.finished=!1,this.bufferLength=0},e}(),pe=function(){function e(e){this.inner=new le,this.outer=new le,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;const t=new Uint8Array(this.blockSize);if(e.length>this.blockSize)(new le).update(e).finish(t).clean();else for(var r=0;r<e.length;r++)t[r]=e[r];for(r=0;r<t.length;r++)t[r]^=54;for(this.inner.update(t),r=0;r<t.length;r++)t[r]^=106;for(this.outer.update(t),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate),r=0;r<t.length;r++)t[r]=0}return e.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},e.prototype.clean=function(){for(let e=0;e<this.istate.length;e++)this.ostate[e]=this.istate[e]=0;this.inner.clean(),this.outer.clean()},e.prototype.update=function(e){return this.inner.update(e),this},e.prototype.finish=function(e){return this.outer.finished?this.outer.finish(e):(this.inner.finish(e),this.outer.update(e,this.digestLength).finish(e)),this},e.prototype.digest=function(){const e=new Uint8Array(this.digestLength);return this.finish(e),e},e}();function de(e){const t=(new le).update(e),r=t.digest();return t.clean(),r}for(var ge={},ye={byteLength:function(e){var t=Be(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=Be(e),i=n[0],s=n[1],o=new be(function(e,t,r){return 3*(t+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)t=_e[e.charCodeAt(r)]<<18|_e[e.charCodeAt(r+1)]<<12|_e[e.charCodeAt(r+2)]<<6|_e[e.charCodeAt(r+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=255&t;return 2===s&&(t=_e[e.charCodeAt(r)]<<2|_e[e.charCodeAt(r+1)]>>4,o[a++]=255&t),1===s&&(t=_e[e.charCodeAt(r)]<<10|_e[e.charCodeAt(r+1)]<<4|_e[e.charCodeAt(r+2)]>>2,o[a++]=t>>8&255,o[a++]=255&t),o},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(ve(e,o,o+s>a?a:o+s));return 1===n?(t=e[r-1],i.push(me[t>>2]+me[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(me[t>>10]+me[t>>4&63]+me[t<<2&63]+"=")),i.join("")}},me=[],_e=[],be="undefined"!=typeof Uint8Array?Uint8Array:Array,Ee="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",we=0;we<64;++we)me[we]=Ee[we],_e[Ee.charCodeAt(we)]=we;function Be(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function ve(e,t,r){for(var n,i,s=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),s.push(me[(i=n)>>18&63]+me[i>>12&63]+me[i>>6&63]+me[63&i]);return s.join("")}_e["-".charCodeAt(0)]=62,_e["_".charCodeAt(0)]=63;var Se={
10
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
11
- read:function(e,t,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=e[t+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+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(e,t,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=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=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=(t*h-1)*Math.pow(2,i),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=255&o,p+=d,o/=256,f-=8);e[r+p-d]|=128*g}};
7
+ */
8
+ var w=(r||(r=1,function(r){const n=function(){if(e)return _;e=1,_.byteLength=function(e){var t=o(e),r=t[0],n=t[1];return 3*(r+n)/4-n},_.toByteArray=function(e){var t,i,s=o(e),a=s[0],h=s[1],f=new n(function(e,t,r){return 3*(t+r)/4-r}(0,a,h)),c=0,u=h>0?a-4:a;for(i=0;i<u;i+=4)t=r[e.charCodeAt(i)]<<18|r[e.charCodeAt(i+1)]<<12|r[e.charCodeAt(i+2)]<<6|r[e.charCodeAt(i+3)],f[c++]=t>>16&255,f[c++]=t>>8&255,f[c++]=255&t;return 2===h&&(t=r[e.charCodeAt(i)]<<2|r[e.charCodeAt(i+1)]>>4,f[c++]=255&t),1===h&&(t=r[e.charCodeAt(i)]<<10|r[e.charCodeAt(i+1)]<<4|r[e.charCodeAt(i+2)]>>2,f[c++]=t>>8&255,f[c++]=255&t),f},_.fromByteArray=function(e){for(var r,n=e.length,i=n%3,s=[],o=16383,h=0,f=n-i;h<f;h+=o)s.push(a(e,h,h+o>f?f:h+o));return 1===i?(r=e[n-1],s.push(t[r>>2]+t[r<<4&63]+"==")):2===i&&(r=(e[n-2]<<8)+e[n-1],s.push(t[r>>10]+t[r>>4&63]+t[r<<2&63]+"=")),s.join("")};for(var t=[],r=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)t[s]=i[s],r[i.charCodeAt(s)]=s;function o(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function a(e,r,n){for(var i,s,o=[],a=r;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(t[(s=i)>>18&63]+t[s>>12&63]+t[s>>6&63]+t[63&s]);return o.join("")}return r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63,_}(),i=(t||(t=1,b.read=function(e,t,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=e[t+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+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)},b.write=function(e,t,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=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=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=(t*h-1)*Math.pow(2,i),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=255&o,p+=d,o/=256,f-=8);e[r+p-d]|=128*g}),b),s="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;r.Buffer=h,r.SlowBuffer=function(e){return+e!=e&&(e=0),h.alloc(+e)},r.INSPECT_MAX_BYTES=50;const o=2147483647;function a(e){if(e>o)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,h.prototype),t}function h(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return f(e,t,r)}function f(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!h.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|g(e,t);let n=a(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(X(e,Uint8Array)){const t=new Uint8Array(e);return p(t.buffer,t.byteOffset,t.byteLength)}return l(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(X(e,ArrayBuffer)||e&&X(e.buffer,ArrayBuffer))return p(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(X(e,SharedArrayBuffer)||e&&X(e.buffer,SharedArrayBuffer)))return p(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return h.from(n,t,r);const i=function(e){if(h.isBuffer(e)){const t=0|d(e.length),r=a(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||K(e.length)?a(0):l(e):"Buffer"===e.type&&Array.isArray(e.data)?l(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return h.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return c(e),a(e<0?0:0|d(e))}function l(e){const t=e.length<0?0:0|d(e.length),r=a(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function p(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,h.prototype),n}function d(e){if(e>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|e}function g(e,t){if(h.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||X(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(i)return n?-1:Y(e).length;t=(""+t).toLowerCase(),i=!0}}function y(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return O(this,t,r);case"utf8":case"utf-8":return T(this,t,r);case"ascii":return x(this,t,r);case"latin1":case"binary":return U(this,t,r);case"base64":return L(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function m(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function w(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),K(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=h.from(t,n)),h.isBuffer(t))return 0===t.length?-1:E(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):E(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function E(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function B(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(K(n))return o;e[r+o]=n}return o}function v(e,t,r,n){return J(Y(t,e.length-r),e,r,n)}function S(e,t,r,n){return J(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function A(e,t,r,n){return J(Q(t),e,r,n)}function k(e,t,r,n){return J(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function L(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function T(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=I));return r}(n)}r.kMaxLength=o,h.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}(),h.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(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}}),h.poolSize=8192,h.from=function(e,t,r){return f(e,t,r)},Object.setPrototypeOf(h.prototype,Uint8Array.prototype),Object.setPrototypeOf(h,Uint8Array),h.alloc=function(e,t,r){return function(e,t,r){return c(e),e<=0?a(e):void 0!==t?"string"==typeof r?a(e).fill(t,r):a(e).fill(t):a(e)}(e,t,r)},h.allocUnsafe=function(e){return u(e)},h.allocUnsafeSlow=function(e){return u(e)},h.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==h.prototype},h.compare=function(e,t){if(X(e,Uint8Array)&&(e=h.from(e,e.offset,e.byteLength)),X(t,Uint8Array)&&(t=h.from(t,t.offset,t.byteLength)),!h.isBuffer(e)||!h.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},h.isEncoding=function(e){switch(String(e).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}},h.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return h.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=h.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(X(t,Uint8Array))i+t.length>n.length?(h.isBuffer(t)||(t=h.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!h.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},h.byteLength=g,h.prototype._isBuffer=!0,h.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)m(this,t,t+1);return this},h.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)m(this,t,t+3),m(this,t+1,t+2);return this},h.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)m(this,t,t+7),m(this,t+1,t+6),m(this,t+2,t+5),m(this,t+3,t+4);return this},h.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?T(this,0,e):y.apply(this,arguments)},h.prototype.toLocaleString=h.prototype.toString,h.prototype.equals=function(e){if(!h.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===h.compare(this,e)},h.prototype.inspect=function(){let e="";const t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(h.prototype[s]=h.prototype.inspect),h.prototype.compare=function(e,t,r,n,i){if(X(e,Uint8Array)&&(e=h.from(e,e.offset,e.byteLength)),!h.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),o=(r>>>=0)-(t>>>=0);const a=Math.min(s,o),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<a;++e)if(f[e]!==c[e]){s=f[e],o=c[e];break}return s<o?-1:o<s?1:0},h.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},h.prototype.indexOf=function(e,t,r){return w(this,e,t,r,!0)},h.prototype.lastIndexOf=function(e,t,r){return w(this,e,t,r,!1)},h.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>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,e,t,r);case"utf8":case"utf-8":return v(this,e,t,r);case"ascii":case"latin1":case"binary":return S(this,e,t,r);case"base64":return A(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const I=4096;function x(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function U(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function O(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=Z[e[n]];return i}function C(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function R(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function N(e,t,r,n,i,s){if(!h.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function M(e,t,r,n,i){G(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function P(e,t,r,n,i){G(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function D(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function $(e,t,r,n,s){return t=+t,r>>>=0,s||D(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function F(e,t,r,n,s){return t=+t,r>>>=0,s||D(e,0,r,8),i.write(e,t,r,n,52,8),r+8}h.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,h.prototype),n},h.prototype.readUintLE=h.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},h.prototype.readUintBE=h.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},h.prototype.readUint8=h.prototype.readUInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),this[e]},h.prototype.readUint16LE=h.prototype.readUInt16LE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]|this[e+1]<<8},h.prototype.readUint16BE=h.prototype.readUInt16BE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]<<8|this[e+1]},h.prototype.readUint32LE=h.prototype.readUInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},h.prototype.readUint32BE=h.prototype.readUInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},h.prototype.readBigUInt64LE=ee((function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||V(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),h.prototype.readBigUInt64BE=ee((function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||V(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),h.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},h.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},h.prototype.readInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},h.prototype.readInt16LE=function(e,t){e>>>=0,t||R(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(e,t){e>>>=0,t||R(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},h.prototype.readInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},h.prototype.readBigInt64LE=ee((function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||V(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),h.prototype.readBigInt64BE=ee((function(e){W(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||V(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),h.prototype.readFloatLE=function(e,t){return e>>>=0,t||R(e,4,this.length),i.read(this,e,!0,23,4)},h.prototype.readFloatBE=function(e,t){return e>>>=0,t||R(e,4,this.length),i.read(this,e,!1,23,4)},h.prototype.readDoubleLE=function(e,t){return e>>>=0,t||R(e,8,this.length),i.read(this,e,!0,52,8)},h.prototype.readDoubleBE=function(e,t){return e>>>=0,t||R(e,8,this.length),i.read(this,e,!1,52,8)},h.prototype.writeUintLE=h.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},h.prototype.writeUintBE=h.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||N(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},h.prototype.writeUint8=h.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,255,0),this[t]=255&e,t+1},h.prototype.writeUint16LE=h.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},h.prototype.writeUint16BE=h.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},h.prototype.writeUint32LE=h.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},h.prototype.writeUint32BE=h.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},h.prototype.writeBigUInt64LE=ee((function(e,t=0){return M(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),h.prototype.writeBigUInt64BE=ee((function(e,t=0){return P(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),h.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},h.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},h.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},h.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},h.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},h.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},h.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||N(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},h.prototype.writeBigInt64LE=ee((function(e,t=0){return M(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),h.prototype.writeBigInt64BE=ee((function(e,t=0){return P(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),h.prototype.writeFloatLE=function(e,t,r){return $(this,e,t,!0,r)},h.prototype.writeFloatBE=function(e,t,r){return $(this,e,t,!1,r)},h.prototype.writeDoubleLE=function(e,t,r){return F(this,e,t,!0,r)},h.prototype.writeDoubleBE=function(e,t,r){return F(this,e,t,!1,r)},h.prototype.copy=function(e,t,r,n){if(!h.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},h.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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&&!h.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=h.isBuffer(e)?e:h.from(e,n),o=s.length;if(0===o)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%o]}return this};const H={};function j(e,t,r){H[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function z(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function G(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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 H.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,r){W(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||V(t,e.length-(r+1))}(n,i,s)}function W(e,t){if("number"!=typeof e)throw new H.ERR_INVALID_ARG_TYPE(t,"number",e)}function V(e,t,r){if(Math.floor(e)!==e)throw W(e,r),new H.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new H.ERR_BUFFER_OUT_OF_BOUNDS;throw new H.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}j("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),j("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),j("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=z(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=z(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n}),RangeError);const q=/[^+/0-9A-Za-z-_]/g;function Y(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function Q(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function J(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function X(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function K(e){return e!=e}const Z=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function ee(e){return"undefined"==typeof BigInt?te:e}function te(){throw new Error("BigInt not supported")}}(m)),m);const E=new TextEncoder,B=new TextDecoder,v=S;function S(e,t=0){let r;if(void 0===e||"string"!=typeof e||"number"!=typeof t)throw TypeError("invlaid init variablie type name. ");return(e=e.toUpperCase()).includes("8")?(r=w.Buffer.alloc(1),e.includes("I")?r.writeInt8(t):r.writeUint8(t)):e.includes("16")?(r=w.Buffer.alloc(2),e.includes("I")?e.includes("L")?r.writeInt16LE(t):r.writeInt16BE(t):e.includes("L")?r.writeUint16LE(t):r.writeUint16BE(t)):e.includes("32")?(r=w.Buffer.alloc(4),e.includes("I")?e.includes("L")?r.writeInt32LE(t):r.writeInt32BE(t):e.includes("L")?r.writeUint32LE(t):r.writeUint32BE(t)):e.includes("F")?(r=w.Buffer.alloc(4),e.includes("L")?r.writeFloatLE(t):r.writeFloatBE(t)):e.includes("N")?r=w.Buffer.from(String(t)):console.log(`invalid type: ${e} or initvalue: ${t}`),r}const A=k;function k(e,t,r){let n,i="B";if("number"==typeof t)"number"==typeof r?(n=w.Buffer.alloc(t),0!==r&&n.fill(r),i="B"):(n=w.Buffer.from(String(t)),i="N");else if("string"==typeof t&&"number"==typeof r)i=t.toUpperCase(),n=S(t,r);else if("string"==typeof t&&void 0===r)n=w.Buffer.from(t),i="S";else if(t instanceof Uint8Array&&void 0===r)n=t instanceof w.Buffer?t:w.Buffer.from(t);else if(t instanceof ArrayBuffer&&void 0===r)n=w.Buffer.from(t);else if(ArrayBuffer.isView(t))n=w.Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if("object"==typeof t&&void 0===r)n=w.Buffer.from(JSON.stringify(t)),i="O";else{if("boolean"!=typeof t||void 0!==r)throw TypeError("invalid meta buffer type");{const e=t?1:0;n=w.Buffer.from([e]),i="!"}}return"string"==typeof e&&e.includes("#")&&(e=""),[e,i,n]}const L=T;function T(...e){let t=0;return e.map((e=>{const r=t++;return"number"==typeof e?A(r,"N",e):A(r,e)}))}function I(e){if((e=e.toUpperCase()).includes("8"))return e.includes("I")?"int8":"uint8";if(e.includes("16"))return e.includes("I")?e.includes("L")?"int16_le":"int16_be":e.includes("L")?"uint16_le":"uint16_be";if(e.includes("32"))return e.includes("I")?e.includes("L")?"int32_le":"int32_be":e.includes("L")?"uint32_le":"uint32_be";if(e.includes("F"))return e.includes("L")?"float_le":"float_be";if("B"===e)return"buffer";if("S"===e)return"string";if("N"===e)return"number";if("O"===e)return"object";if("!"===e)return"boolean";throw TypeError("invalid data type")}function x(e,t,r,n){try{const i=I(e);if("int8"==i)return t.readInt8(r);if("uint8"===i)return t.readUint8(r);if("int16_le"===i)return t.readInt16LE(r);if("int16_be"===i)return t.readInt16BE(r);if("uint16_le"===i)return t.readUint16LE(r);if("uint16_be"===i)return t.readUint16BE(r);if("int32_le"===i)return t.readInt32LE(r);if("int32_be"===i)return t.readInt32BE(r);if("uint32_le"===i)return t.readUint32LE(r);if("uint32_be"===i)return t.readUint32BE(r);if("float_le"===i)return t.readFloatLE(r);if("float_be"===i)return t.readFloatBE(r);if("buffer"===i)return t.subarray(r,r+n);if("string"===i){const e=t.subarray(r,r+n);return B.decode(e)}if("number"===i){const e=t.subarray(r,r+n);return Number(B.decode(e))}if("object"===i){const e=t.subarray(r,r+n);return JSON.parse(B.decode(e))}return"boolean"===i?1===t.readInt8(r):void 0}catch(e){}}function U(...e){const t=function(e){let t=[];return e.filter((e=>{if(!Array.isArray(e[0]))return e;t=t.concat(e)})).concat(t)}(e);let r=0;const n=[];let i,s,o=0;if(t.forEach((e=>{const[t,i,s]=e;r+=s.byteLength,("number"==typeof t||t.length>0)&&n.push([t,i,o,s.byteLength]),o=r})),n.length>0){let e=JSON.stringify(n);i=E.encode(e),s=i.byteLength,r=r+s+2}const a=w.Buffer.alloc(r);if(o=0,t.forEach((e=>{const t=e[2];a.set(t,o),o+=t.byteLength})),n.length>0){a.set(i,o);const e=v("16",s);return a.set(e,o+s),a}return a}const O=C;function C(e,t=!1){if(void 0===e)throw TypeError("Invalid data type: Undefined");if("string"==typeof e)return E.encode(e);if("number"==typeof e)return Uint8Array.from([e]);if(e instanceof ArrayBuffer){if(t)return new Uint8Array(e);{const t=new Uint8Array(e),r=new Uint8Array(e.byteLength);return r.set(t),r}}if(ArrayBuffer.isView(e)){if(t)return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);{const t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(e.byteLength);return r.set(t),r}}return E.encode(JSON.stringify(e))}const R=N;function N(e,t=!1){const r=C(e,t);return t?w.Buffer.from(r.buffer,r.byteOffset,r.byteLength):w.Buffer.from(r)}const M=P;function P(...e){const t=e.map((e=>N(e)));return w.Buffer.concat(t)}const D=$;function $(...e){try{let t=0,r=0;const n=e.map((e=>C(e)));n.forEach((e=>{t+=e.byteLength}));const i=new Uint8Array(t);return n.forEach((e=>{i.set(e,r),r+=e.byteLength})),i}catch(e){console.log(e)}}function F(e){return 0===G(e)?e.byteLength:e.byteLength-G(e)-j}function H(e,t){try{const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=r.byteLength-t-2,i=r.subarray(n,r.byteLength-2),s=B.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(e){}}const j=2;function z(e){return e instanceof ArrayBuffer&&(e=w.Buffer.from(e)),e instanceof Uint8Array?e.byteLength<=j?0:new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(e.byteLength-j):0}function G(e){if(e instanceof ArrayBuffer&&(e=w.Buffer.from(e)),e instanceof Uint8Array){const t=e.byteLength;if(t<=j)return 0;const r=z(e);return 0===r||r>t?0:H(e,r)?r:0}return 0}function W(e){const t=F(e);return e.subarray(0,t)}function V(e,t=!1){e instanceof ArrayBuffer&&(e=w.Buffer.from(e));const r=z(e);if(0===r)return;let n=H(e,r);return n?t?(n.forEach((e=>{null==e[3]&&(e[1].includes("8")?e[3]=1:e[1].includes("16")?e[3]=2:e[1].includes("32")||e[1].includes("F")?e[3]=4:e[1].includes("!")&&(e[3]=1)),e[4]=I(e[1])})),n):n:void 0}var q=Object.freeze({__proto__:null,B8:R,B8pack:M,Buffer:w.Buffer,MB:A,MBA:L,NB:v,TAIL_LEN:j,U8:O,U8pack:D,equal:function(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},getBuffer:W,getBufferSize:F,getMeta:V,getMetaDetail:function(e){return V(e,!0)},getMetaSize:G,hex:function(e){return Array.prototype.map.call(new Uint8Array(e),(e=>("00"+e.toString(16)).slice(-2))).join("")},meta:function(...e){return V(U(...e))},metaBuffer:k,metaBufferArguments:T,metaDetail:function(...e){return V(U(...e),!0)},numberBuffer:S,pack:U,parseBuffer:N,parseBufferThenConcat:P,parseMetaInfo:H,parseTypeName:I,parseUint8Array:C,parseUint8ThenConcat:$,rawPack:function(...e){return W(U(...e))},readTail:z,readTypedBuffer:x,unpack:function(e,t){const r=t||V(e);if(!r)return;const n=w.Buffer.from(e),i={};let s=0;if(r.forEach((e=>{const[t,r,o,a]=e;let h=x(r,n,o,a);null!=h&&(i[t]=h,a&&(s+=a))})),t&&n.byteLength!==s){let e=n.byteLength-s,t=x("b",n,s,e);if(null==t)return;i.$OTHERS=t}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});function Y(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Q,J={exports:{}};var X=(Q||(Q=1,function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function i(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,n,s,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,s||e,o),h=r?r+t:t;return e._events[h]?e._events[h].fn?e._events[h]=[e._events[h],a]:e._events[h].push(a):(e._events[h]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}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 e,n,i=[];if(0===this._eventsCount)return i;for(n in e=this._events)t.call(e,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];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(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,i,s,o){var a=r?r+e:e;if(!this._events[a])return!1;var h,f,c=this._events[a],u=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,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(e,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,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,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(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,n,i){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||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!==t||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(e){var t;return e?(t=r?r+e:e,this._events[t]&&o(this,t)):(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,e.exports=a}(J)),J.exports),K=Y(X);const Z={OPENING:0,OPEN:1,CLOSING:2,CLOSED:3,SERVER_READY:4,AUTH_FAIL:5,AUTH_READY:6,READY:7,REDIRECTING:8};for(let e in Z)Z[Z[e]]=e;const ee={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 e in ee)ee[ee[e]]=e;let te={NO:0,YES:1,AUTO:2};for(let e in te)te[te[e]]=e;const re={TAG_LEN1:255,TAG_LEN2:65535,CONNECTION_CHECKER_PERIOD:3e3,PROMISE_TIMEOUT:5e3,DID:8,CID:12};let ne={EMPTY:0,TEXT:1,BINARY:2,OBJECT:3,MJSON:4,MBA:5};for(let e in ne)ne[ne[e]]=e;let ie={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 e in ie)ie[ie[e]]=e;let se={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 oe=new TextEncoder;function ae(e,...t){if("string"!=typeof e)throw TypeError("tag should be string.");let r,n=oe.encode(e),i=he(t);if(i.type==ne.EMPTY)r=q.pack(q.MB("#MsgType","8",ie.SIGNAL),q.MB("#tagLen","8",n.byteLength),q.MB("#tag",n),q.MB("#payloadType","8",i.type));else if(i.type==ne.MBA){let e=q.pack(q.MBA(...t));r=q.pack(q.MB("#MsgType","8",ie.SIGNAL),q.MB("#tagLen","8",n.byteLength),q.MB("#tag",n),q.MB("#payloadType","8",i.type),q.MB("#mbaBuffer",e))}else r=q.pack(q.MB("#MsgType","8",ie.SIGNAL),q.MB("#tagLen","8",n.byteLength),q.MB("#tag",n),q.MB("#payloadType","8",i.type),q.MB("#payload",i.buffer));return r}function he(e){let t,r;if(0==e.length)t=ne.EMPTY,r=null;else if(1==e.length)if("string"==typeof e[0]||"number"==typeof e[0])t=ne.TEXT,r=oe.encode(e[0]+"."),r[r.byteLength-1]=0;else if(ArrayBuffer.isView(e[0])||e[0]instanceof ArrayBuffer)t=ne.BINARY,r=q.B8(e[0]);else{if("object"!=typeof e[0])throw new Error("unknown payload arguments");t=ne.OBJECT,r=oe.encode(JSON.stringify(e[0]))}else{let n=!1;e.forEach((e=>{(ArrayBuffer.isView(e)||e instanceof ArrayBuffer)&&(n=!0)})),n?t=ne.MBA:(t=ne.MJSON,r=oe.encode(JSON.stringify(e)))}return{type:t,buffer:r}}const fe=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 ce(e,t,r,n,i){let s,o,a,h,f,c,u,l,p,d,g,y,m;for(;i>=64;){for(s=t[0],o=t[1],a=t[2],h=t[3],f=t[4],c=t[5],u=t[6],l=t[7],d=0;d<16;d++)g=n+4*d,e[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=e[d-2],y=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,p=e[d-15],m=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,e[d]=(y+e[d-7]|0)+(m+e[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+(fe[d]+e[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;t[0]+=s,t[1]+=o,t[2]+=a,t[3]+=h,t[4]+=f,t[5]+=c,t[6]+=u,t[7]+=l,n+=64,i-=64}return n}const ue=function(){function e(){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 e.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},e.prototype.clean=function(){for(var e=0;e<this.buffer.length;e++)this.buffer[e]=0;for(e=0;e<this.temp.length;e++)this.temp[e]=0;this.reset()},e.prototype.update=function(e,t){if(void 0===t&&(t=e.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");let r=0;if(this.bytesHashed+=t,this.bufferLength>0){for(;this.bufferLength<64&&t>0;)this.buffer[this.bufferLength++]=e[r++],t--;64===this.bufferLength&&(ce(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(t>=64&&(r=ce(this.temp,this.state,e,r,t),t%=64);t>0;)this.buffer[this.bufferLength++]=e[r++],t--;return this},e.prototype.finish=function(e){if(!this.finished){const e=this.bytesHashed,r=this.bufferLength,n=e/536870912|0,i=e<<3,s=e%64<56?64:128;this.buffer[r]=128;for(var t=r+1;t<s-8;t++)this.buffer[t]=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,ce(this.temp,this.state,this.buffer,0,s),this.finished=!0}for(t=0;t<8;t++)e[4*t+0]=this.state[t]>>>24&255,e[4*t+1]=this.state[t]>>>16&255,e[4*t+2]=this.state[t]>>>8&255,e[4*t+3]=this.state[t]>>>0&255;return this},e.prototype.digest=function(){const e=new Uint8Array(this.digestLength);return this.finish(e),e},e.prototype._saveState=function(e){for(let t=0;t<this.state.length;t++)e[t]=this.state[t]},e.prototype._restoreState=function(e,t){for(let t=0;t<this.state.length;t++)this.state[t]=e[t];this.bytesHashed=t,this.finished=!1,this.bufferLength=0},e}(),le=function(){function e(e){this.inner=new ue,this.outer=new ue,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;const t=new Uint8Array(this.blockSize);if(e.length>this.blockSize)(new ue).update(e).finish(t).clean();else for(var r=0;r<e.length;r++)t[r]=e[r];for(r=0;r<t.length;r++)t[r]^=54;for(this.inner.update(t),r=0;r<t.length;r++)t[r]^=106;for(this.outer.update(t),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate),r=0;r<t.length;r++)t[r]=0}return e.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},e.prototype.clean=function(){for(let e=0;e<this.istate.length;e++)this.ostate[e]=this.istate[e]=0;this.inner.clean(),this.outer.clean()},e.prototype.update=function(e){return this.inner.update(e),this},e.prototype.finish=function(e){return this.outer.finished?this.outer.finish(e):(this.inner.finish(e),this.outer.update(e,this.digestLength).finish(e)),this},e.prototype.digest=function(){const e=new Uint8Array(this.digestLength);return this.finish(e),e},e}();function pe(e){const t=(new ue).update(e),r=t.digest();return t.clean(),r}var de,ge,ye,me={},_e={},be={};
9
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */function we(){return ge||(ge=1,be.read=function(e,t,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=e[t+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+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)},be.write=function(e,t,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=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=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=(t*h-1)*Math.pow(2,i),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=255&o,p+=d,o/=256,f-=8);e[r+p-d]|=128*g}),be}
12
10
  /*!
13
11
  * The buffer module from node.js, for the browser.
14
12
  *
15
13
  * @author Feross Aboukhadijeh <https://feross.org>
16
14
  * @license MIT
17
- */!function(e){const t=ye,r=Se,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|p(e,t);let n=s(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(q(e,Uint8Array)){const t=new Uint8Array(e);return u(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(q(e,ArrayBuffer)||e&&q(e.buffer,ArrayBuffer))return u(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(q(e,SharedArrayBuffer)||e&&q(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);const i=function(e){if(o.isBuffer(e)){const t=0|l(e.length),r=s(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?s(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return h(e),s(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=s(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function u(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function l(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return W(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:W(e).length;t=(""+t).toLowerCase(),i=!0}}function d(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return L(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.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:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function _(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(Y(n))return o;e[r+o]=n}return o}function b(e,t,r,n){return V(W(t,e.length-r),e,r,n)}function E(e,t,r,n){return V(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function w(e,t,r,n){return V(G(t),e,r,n)}function B(e,t,r,n){return V(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function v(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}e.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,r){return a(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return h(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},o.allocUnsafe=function(e){return f(e)},o.allocUnsafeSlow=function(e){return f(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=o.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(q(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<h;++e)if(f[e]!==c[e]){s=f[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":case"latin1":case"binary":return E(this,e,t,r);case"base64":return w(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,t,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(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function L(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function I(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=Q[e[n]];return i}function T(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function x(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function R(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function M(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,8),r.write(e,t,n,i,52,8),n+8}o.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},o.prototype.readInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=J((function(e,t=0){return O(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=J((function(e,t=0){return O(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,r){return N(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return N(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return M(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return M(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};const P={};function D(e,t,r){P[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function $(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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,e)}!function(e,t,r){H(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||j(t,e.length-(r+1))}(n,i,s)}function H(e,t){if("number"!=typeof e)throw new P.ERR_INVALID_ARG_TYPE(t,"number",e)}function j(e,t,r){if(Math.floor(e)!==e)throw H(e,r),new P.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" 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 ${t}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function W(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function V(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}}(ge);const Ae=new TextEncoder,ke=new TextDecoder,Le=Ie;function Ie(e,t=0){let r;if(void 0===e||"string"!=typeof e||"number"!=typeof t)throw TypeError("invlaid init variablie type name. ");return(e=e.toUpperCase()).includes("8")?(r=ge.Buffer.alloc(1),e.includes("I")?r.writeInt8(t):r.writeUint8(t)):e.includes("16")?(r=ge.Buffer.alloc(2),e.includes("I")?e.includes("L")?r.writeInt16LE(t):r.writeInt16BE(t):e.includes("L")?r.writeUint16LE(t):r.writeUint16BE(t)):e.includes("32")?(r=ge.Buffer.alloc(4),e.includes("I")?e.includes("L")?r.writeInt32LE(t):r.writeInt32BE(t):e.includes("L")?r.writeUint32LE(t):r.writeUint32BE(t)):e.includes("F")?(r=ge.Buffer.alloc(4),e.includes("L")?r.writeFloatLE(t):r.writeFloatBE(t)):e.includes("N")?r=ge.Buffer.from(String(t)):console.log(`invalid type: ${e} or initvalue: ${t}`),r}const Te=xe;function xe(e,t,r){let n,i="B";if("number"==typeof t)"number"==typeof r?(n=ge.Buffer.alloc(t),0!==r&&n.fill(r),i="B"):(n=ge.Buffer.from(String(t)),i="N");else if("string"==typeof t&&"number"==typeof r)i=t.toUpperCase(),n=Ie(t,r);else if("string"==typeof t&&void 0===r)n=ge.Buffer.from(t),i="S";else if(t instanceof Uint8Array&&void 0===r)n=t instanceof ge.Buffer?t:ge.Buffer.from(t);else if(t instanceof ArrayBuffer&&void 0===r)n=ge.Buffer.from(t);else if(ArrayBuffer.isView(t))n=ge.Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if("object"==typeof t&&void 0===r)n=ge.Buffer.from(JSON.stringify(t)),i="O";else{if("boolean"!=typeof t||void 0!==r)throw TypeError("invalid meta buffer type");{const e=t?1:0;n=ge.Buffer.from([e]),i="!"}}return"string"==typeof e&&e.includes("#")&&(e=""),[e,i,n]}const Ue=Oe;function Oe(...e){let t=0;return e.map((e=>{const r=t++;return"number"==typeof e?Te(r,"N",e):Te(r,e)}))}function Ce(e){if((e=e.toUpperCase()).includes("8"))return e.includes("I")?"int8":"uint8";if(e.includes("16"))return e.includes("I")?e.includes("L")?"int16_le":"int16_be":e.includes("L")?"uint16_le":"uint16_be";if(e.includes("32"))return e.includes("I")?e.includes("L")?"int32_le":"int32_be":e.includes("L")?"uint32_le":"uint32_be";if(e.includes("F"))return e.includes("L")?"float_le":"float_be";if("B"===e)return"buffer";if("S"===e)return"string";if("N"===e)return"number";if("O"===e)return"object";if("!"===e)return"boolean";throw TypeError("invalid data type")}function Re(e,t,r,n){try{const i=Ce(e);if("int8"==i)return t.readInt8(r);if("uint8"===i)return t.readUint8(r);if("int16_le"===i)return t.readInt16LE(r);if("int16_be"===i)return t.readInt16BE(r);if("uint16_le"===i)return t.readUint16LE(r);if("uint16_be"===i)return t.readUint16BE(r);if("int32_le"===i)return t.readInt32LE(r);if("int32_be"===i)return t.readInt32BE(r);if("uint32_le"===i)return t.readUint32LE(r);if("uint32_be"===i)return t.readUint32BE(r);if("float_le"===i)return t.readFloatLE(r);if("float_be"===i)return t.readFloatBE(r);if("buffer"===i)return t.subarray(r,r+n);if("string"===i){const e=t.subarray(r,r+n);return ke.decode(e)}if("number"===i){const e=t.subarray(r,r+n);return Number(ke.decode(e))}if("object"===i){const e=t.subarray(r,r+n);return JSON.parse(ke.decode(e))}return"boolean"===i?1===t.readInt8(r):void 0}catch(e){}}function Ne(...e){const t=function(e){let t=[];return e.filter((e=>{if(!Array.isArray(e[0]))return e;t=t.concat(e)})).concat(t)}(e);let r=0;const n=[];let i,s,o=0;if(t.forEach((e=>{const[t,i,s]=e;r+=s.byteLength,("number"==typeof t||t.length>0)&&n.push([t,i,o,s.byteLength]),o=r})),n.length>0){let e=JSON.stringify(n);i=Ae.encode(e),s=i.byteLength,r=r+s+2}const a=ge.Buffer.alloc(r);if(o=0,t.forEach((e=>{const t=e[2];a.set(t,o),o+=t.byteLength})),n.length>0){a.set(i,o);const e=Le("16",s);return a.set(e,o+s),a}return a}const Me=Pe;function Pe(e,t=!1){if(void 0===e)throw TypeError("Invalid data type: Undefined");if("string"==typeof e)return Ae.encode(e);if("number"==typeof e)return Uint8Array.from([e]);if(e instanceof ArrayBuffer){if(t)return new Uint8Array(e);{const t=new Uint8Array(e),r=new Uint8Array(e.byteLength);return r.set(t),r}}if(ArrayBuffer.isView(e)){if(t)return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);{const t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(e.byteLength);return r.set(t),r}}return Ae.encode(JSON.stringify(e))}const De=$e;function $e(e,t=!1){const r=Pe(e,t);return t?ge.Buffer.from(r.buffer,r.byteOffset,r.byteLength):ge.Buffer.from(r)}const Fe=He;function He(...e){const t=e.map((e=>$e(e)));return ge.Buffer.concat(t)}const je=ze;function ze(...e){try{let t=0,r=0;const n=e.map((e=>Pe(e)));n.forEach((e=>{t+=e.byteLength}));const i=new Uint8Array(t);return n.forEach((e=>{i.set(e,r),r+=e.byteLength})),i}catch(e){console.log(e)}}function We(e){return 0===Ye(e)?e.byteLength:e.byteLength-Ye(e)-Ve}function Ge(e,t){try{const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=r.byteLength-t-2,i=r.subarray(n,r.byteLength-2),s=ke.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(e){}}const Ve=2;function qe(e){return e instanceof ArrayBuffer&&(e=ge.Buffer.from(e)),e instanceof Uint8Array?e.byteLength<=Ve?0:new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(e.byteLength-Ve):0}function Ye(e){if(e instanceof ArrayBuffer&&(e=ge.Buffer.from(e)),e instanceof Uint8Array){const t=e.byteLength;if(t<=Ve)return 0;const r=qe(e);return 0===r||r>t?0:Ge(e,r)?r:0}return 0}function Qe(e){const t=We(e);return e.subarray(0,t)}function Je(e,t=!1){e instanceof ArrayBuffer&&(e=ge.Buffer.from(e));const r=qe(e);if(0===r)return;let n=Ge(e,r);return n?t?(n.forEach((e=>{null==e[3]&&(e[1].includes("8")?e[3]=1:e[1].includes("16")?e[3]=2:e[1].includes("32")||e[1].includes("F")?e[3]=4:e[1].includes("!")&&(e[3]=1)),e[4]=Ce(e[1])})),n):n:void 0}var Xe=Object.freeze({__proto__:null,B8:De,B8pack:Fe,Buffer:ge.Buffer,MB:Te,MBA:Ue,NB:Le,TAIL_LEN:Ve,U8:Me,U8pack:je,equal:function(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},getBuffer:Qe,getBufferSize:We,getMeta:Je,getMetaDetail:function(e){return Je(e,!0)},getMetaSize:Ye,hex:function(e){return Array.prototype.map.call(new Uint8Array(e),(e=>("00"+e.toString(16)).slice(-2))).join("")},meta:function(...e){return Je(Ne(...e))},metaBuffer:xe,metaBufferArguments:Oe,metaDetail:function(...e){return Je(Ne(...e),!0)},numberBuffer:Ie,pack:Ne,parseBuffer:$e,parseBufferThenConcat:He,parseMetaInfo:Ge,parseTypeName:Ce,parseUint8Array:Pe,parseUint8ThenConcat:ze,rawPack:function(...e){return Qe(Ne(...e))},readTail:qe,readTypedBuffer:Re,unpack:function(e,t){const r=t||Je(e);if(!r)return;const n=ge.Buffer.from(e),i={};let s=0;if(r.forEach((e=>{const[t,r,o,a]=e;let h=Re(r,n,o,a);null!=h&&(i[t]=h,a&&(s+=a))})),t&&n.byteLength!==s){let e=n.byteLength-s,t=Re("b",n,s,e);if(null==t)return;i.$OTHERS=t}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});const Ke={hash:function(e){return de(Xe.U8(e))},hex:function(e){return Xe.B8(de(Xe.U8(e))).toString("hex")},base64:function(e){return Xe.B8(de(Xe.U8(e))).toString("base64")},hmac:function(e,t){return function(e,t){const r=new pe(e).update(t),n=r.digest();return r.clean(),n}(Xe.U8(e),Xe.U8(t))}};for(var Ze={},et={byteLength:function(e){var t=ot(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=ot(e),i=n[0],s=n[1],o=new nt(function(e,t,r){return 3*(t+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)t=rt[e.charCodeAt(r)]<<18|rt[e.charCodeAt(r+1)]<<12|rt[e.charCodeAt(r+2)]<<6|rt[e.charCodeAt(r+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=255&t;return 2===s&&(t=rt[e.charCodeAt(r)]<<2|rt[e.charCodeAt(r+1)]>>4,o[a++]=255&t),1===s&&(t=rt[e.charCodeAt(r)]<<10|rt[e.charCodeAt(r+1)]<<4|rt[e.charCodeAt(r+2)]>>2,o[a++]=t>>8&255,o[a++]=255&t),o},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(at(e,o,o+s>a?a:o+s));return 1===n?(t=e[r-1],i.push(tt[t>>2]+tt[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(tt[t>>10]+tt[t>>4&63]+tt[t<<2&63]+"=")),i.join("")}},tt=[],rt=[],nt="undefined"!=typeof Uint8Array?Uint8Array:Array,it="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",st=0;st<64;++st)tt[st]=it[st],rt[it.charCodeAt(st)]=st;function ot(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function at(e,t,r){for(var n,i,s=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),s.push(tt[(i=n)>>18&63]+tt[i>>12&63]+tt[i>>6&63]+tt[63&i]);return s.join("")}rt["-".charCodeAt(0)]=62,rt["_".charCodeAt(0)]=63;var ht={
15
+ */var Ee=(ye||(ye=1,function(e){const t=function(){if(de)return _e;de=1,_e.byteLength=function(e){var t=s(e),r=t[0],n=t[1];return 3*(r+n)/4-n},_e.toByteArray=function(e){var n,i,o=s(e),a=o[0],h=o[1],f=new r(function(e,t,r){return 3*(t+r)/4-r}(0,a,h)),c=0,u=h>0?a-4:a;for(i=0;i<u;i+=4)n=t[e.charCodeAt(i)]<<18|t[e.charCodeAt(i+1)]<<12|t[e.charCodeAt(i+2)]<<6|t[e.charCodeAt(i+3)],f[c++]=n>>16&255,f[c++]=n>>8&255,f[c++]=255&n;return 2===h&&(n=t[e.charCodeAt(i)]<<2|t[e.charCodeAt(i+1)]>>4,f[c++]=255&n),1===h&&(n=t[e.charCodeAt(i)]<<10|t[e.charCodeAt(i+1)]<<4|t[e.charCodeAt(i+2)]>>2,f[c++]=n>>8&255,f[c++]=255&n),f},_e.fromByteArray=function(t){for(var r,n=t.length,i=n%3,s=[],a=16383,h=0,f=n-i;h<f;h+=a)s.push(o(t,h,h+a>f?f:h+a));return 1===i?(r=t[n-1],s.push(e[r>>2]+e[r<<4&63]+"==")):2===i&&(r=(t[n-2]<<8)+t[n-1],s.push(e[r>>10]+e[r>>4&63]+e[r<<2&63]+"=")),s.join("")};for(var e=[],t=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)e[i]=n[i],t[n.charCodeAt(i)]=i;function s(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function o(t,r,n){for(var i,s,o=[],a=r;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),o.push(e[(s=i)>>18&63]+e[s>>12&63]+e[s>>6&63]+e[63&s]);return o.join("")}return t["-".charCodeAt(0)]=62,t["_".charCodeAt(0)]=63,_e}(),r=we(),n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|p(e,t);let n=s(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(q(e,Uint8Array)){const t=new Uint8Array(e);return u(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(q(e,ArrayBuffer)||e&&q(e.buffer,ArrayBuffer))return u(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(q(e,SharedArrayBuffer)||e&&q(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);const i=function(e){if(o.isBuffer(e)){const t=0|l(e.length),r=s(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?s(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return h(e),s(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=s(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function u(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function l(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(e).length;default:if(i)return n?-1:G(e).length;t=(""+t).toLowerCase(),i=!0}}function d(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return L(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.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:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function _(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(Y(n))return o;e[r+o]=n}return o}function b(e,t,r,n){return V(G(t,e.length-r),e,r,n)}function w(e,t,r,n){return V(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function E(e,t,r,n){return V(W(t),e,r,n)}function B(e,t,r,n){return V(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function v(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}e.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,r){return a(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return h(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},o.allocUnsafe=function(e){return f(e)},o.allocUnsafeSlow=function(e){return f(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=o.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(q(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<h;++e)if(f[e]!==c[e]){s=f[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":case"latin1":case"binary":return w(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,t,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(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function L(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function T(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=Q[e[n]];return i}function I(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function x(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function R(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function M(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,8),r.write(e,t,n,i,52,8),n+8}o.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},o.prototype.readInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=J((function(e,t=0){return O(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=J((function(e,t=0){return O(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,r){return N(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return N(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return M(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return M(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};const P={};function D(e,t,r){P[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function $(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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,e)}!function(e,t,r){H(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||j(t,e.length-(r+1))}(n,i,s)}function H(e,t){if("number"!=typeof e)throw new P.ERR_INVALID_ARG_TYPE(t,"number",e)}function j(e,t,r){if(Math.floor(e)!==e)throw H(e,r),new P.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" 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 ${t}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function G(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function W(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function V(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}}(me)),me);const Be=new TextEncoder,ve=new TextDecoder,Se=Ae;function Ae(e,t=0){let r;if(void 0===e||"string"!=typeof e||"number"!=typeof t)throw TypeError("invlaid init variablie type name. ");return(e=e.toUpperCase()).includes("8")?(r=Ee.Buffer.alloc(1),e.includes("I")?r.writeInt8(t):r.writeUint8(t)):e.includes("16")?(r=Ee.Buffer.alloc(2),e.includes("I")?e.includes("L")?r.writeInt16LE(t):r.writeInt16BE(t):e.includes("L")?r.writeUint16LE(t):r.writeUint16BE(t)):e.includes("32")?(r=Ee.Buffer.alloc(4),e.includes("I")?e.includes("L")?r.writeInt32LE(t):r.writeInt32BE(t):e.includes("L")?r.writeUint32LE(t):r.writeUint32BE(t)):e.includes("F")?(r=Ee.Buffer.alloc(4),e.includes("L")?r.writeFloatLE(t):r.writeFloatBE(t)):e.includes("N")?r=Ee.Buffer.from(String(t)):console.log(`invalid type: ${e} or initvalue: ${t}`),r}const ke=Le;function Le(e,t,r){let n,i="B";if("number"==typeof t)"number"==typeof r?(n=Ee.Buffer.alloc(t),0!==r&&n.fill(r),i="B"):(n=Ee.Buffer.from(String(t)),i="N");else if("string"==typeof t&&"number"==typeof r)i=t.toUpperCase(),n=Ae(t,r);else if("string"==typeof t&&void 0===r)n=Ee.Buffer.from(t),i="S";else if(t instanceof Uint8Array&&void 0===r)n=t instanceof Ee.Buffer?t:Ee.Buffer.from(t);else if(t instanceof ArrayBuffer&&void 0===r)n=Ee.Buffer.from(t);else if(ArrayBuffer.isView(t))n=Ee.Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if("object"==typeof t&&void 0===r)n=Ee.Buffer.from(JSON.stringify(t)),i="O";else{if("boolean"!=typeof t||void 0!==r)throw TypeError("invalid meta buffer type");{const e=t?1:0;n=Ee.Buffer.from([e]),i="!"}}return"string"==typeof e&&e.includes("#")&&(e=""),[e,i,n]}const Te=Ie;function Ie(...e){let t=0;return e.map((e=>{const r=t++;return"number"==typeof e?ke(r,"N",e):ke(r,e)}))}function xe(e){if((e=e.toUpperCase()).includes("8"))return e.includes("I")?"int8":"uint8";if(e.includes("16"))return e.includes("I")?e.includes("L")?"int16_le":"int16_be":e.includes("L")?"uint16_le":"uint16_be";if(e.includes("32"))return e.includes("I")?e.includes("L")?"int32_le":"int32_be":e.includes("L")?"uint32_le":"uint32_be";if(e.includes("F"))return e.includes("L")?"float_le":"float_be";if("B"===e)return"buffer";if("S"===e)return"string";if("N"===e)return"number";if("O"===e)return"object";if("!"===e)return"boolean";throw TypeError("invalid data type")}function Ue(e,t,r,n){try{const i=xe(e);if("int8"==i)return t.readInt8(r);if("uint8"===i)return t.readUint8(r);if("int16_le"===i)return t.readInt16LE(r);if("int16_be"===i)return t.readInt16BE(r);if("uint16_le"===i)return t.readUint16LE(r);if("uint16_be"===i)return t.readUint16BE(r);if("int32_le"===i)return t.readInt32LE(r);if("int32_be"===i)return t.readInt32BE(r);if("uint32_le"===i)return t.readUint32LE(r);if("uint32_be"===i)return t.readUint32BE(r);if("float_le"===i)return t.readFloatLE(r);if("float_be"===i)return t.readFloatBE(r);if("buffer"===i)return t.subarray(r,r+n);if("string"===i){const e=t.subarray(r,r+n);return ve.decode(e)}if("number"===i){const e=t.subarray(r,r+n);return Number(ve.decode(e))}if("object"===i){const e=t.subarray(r,r+n);return JSON.parse(ve.decode(e))}return"boolean"===i?1===t.readInt8(r):void 0}catch(e){}}function Oe(...e){const t=function(e){let t=[];return e.filter((e=>{if(!Array.isArray(e[0]))return e;t=t.concat(e)})).concat(t)}(e);let r=0;const n=[];let i,s,o=0;if(t.forEach((e=>{const[t,i,s]=e;r+=s.byteLength,("number"==typeof t||t.length>0)&&n.push([t,i,o,s.byteLength]),o=r})),n.length>0){let e=JSON.stringify(n);i=Be.encode(e),s=i.byteLength,r=r+s+2}const a=Ee.Buffer.alloc(r);if(o=0,t.forEach((e=>{const t=e[2];a.set(t,o),o+=t.byteLength})),n.length>0){a.set(i,o);const e=Se("16",s);return a.set(e,o+s),a}return a}const Ce=Re;function Re(e,t=!1){if(void 0===e)throw TypeError("Invalid data type: Undefined");if("string"==typeof e)return Be.encode(e);if("number"==typeof e)return Uint8Array.from([e]);if(e instanceof ArrayBuffer){if(t)return new Uint8Array(e);{const t=new Uint8Array(e),r=new Uint8Array(e.byteLength);return r.set(t),r}}if(ArrayBuffer.isView(e)){if(t)return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);{const t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(e.byteLength);return r.set(t),r}}return Be.encode(JSON.stringify(e))}const Ne=Me;function Me(e,t=!1){const r=Re(e,t);return t?Ee.Buffer.from(r.buffer,r.byteOffset,r.byteLength):Ee.Buffer.from(r)}const Pe=De;function De(...e){const t=e.map((e=>Me(e)));return Ee.Buffer.concat(t)}const $e=Fe;function Fe(...e){try{let t=0,r=0;const n=e.map((e=>Re(e)));n.forEach((e=>{t+=e.byteLength}));const i=new Uint8Array(t);return n.forEach((e=>{i.set(e,r),r+=e.byteLength})),i}catch(e){console.log(e)}}function He(e){return 0===We(e)?e.byteLength:e.byteLength-We(e)-ze}function je(e,t){try{const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=r.byteLength-t-2,i=r.subarray(n,r.byteLength-2),s=ve.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(e){}}const ze=2;function Ge(e){return e instanceof ArrayBuffer&&(e=Ee.Buffer.from(e)),e instanceof Uint8Array?e.byteLength<=ze?0:new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(e.byteLength-ze):0}function We(e){if(e instanceof ArrayBuffer&&(e=Ee.Buffer.from(e)),e instanceof Uint8Array){const t=e.byteLength;if(t<=ze)return 0;const r=Ge(e);return 0===r||r>t?0:je(e,r)?r:0}return 0}function Ve(e){const t=He(e);return e.subarray(0,t)}function qe(e,t=!1){e instanceof ArrayBuffer&&(e=Ee.Buffer.from(e));const r=Ge(e);if(0===r)return;let n=je(e,r);return n?t?(n.forEach((e=>{null==e[3]&&(e[1].includes("8")?e[3]=1:e[1].includes("16")?e[3]=2:e[1].includes("32")||e[1].includes("F")?e[3]=4:e[1].includes("!")&&(e[3]=1)),e[4]=xe(e[1])})),n):n:void 0}var Ye=Object.freeze({__proto__:null,B8:Ne,B8pack:Pe,Buffer:Ee.Buffer,MB:ke,MBA:Te,NB:Se,TAIL_LEN:ze,U8:Ce,U8pack:$e,equal:function(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},getBuffer:Ve,getBufferSize:He,getMeta:qe,getMetaDetail:function(e){return qe(e,!0)},getMetaSize:We,hex:function(e){return Array.prototype.map.call(new Uint8Array(e),(e=>("00"+e.toString(16)).slice(-2))).join("")},meta:function(...e){return qe(Oe(...e))},metaBuffer:Le,metaBufferArguments:Ie,metaDetail:function(...e){return qe(Oe(...e),!0)},numberBuffer:Ae,pack:Oe,parseBuffer:Me,parseBufferThenConcat:De,parseMetaInfo:je,parseTypeName:xe,parseUint8Array:Re,parseUint8ThenConcat:Fe,rawPack:function(...e){return Ve(Oe(...e))},readTail:Ge,readTypedBuffer:Ue,unpack:function(e,t){const r=t||qe(e);if(!r)return;const n=Ee.Buffer.from(e),i={};let s=0;if(r.forEach((e=>{const[t,r,o,a]=e;let h=Ue(r,n,o,a);null!=h&&(i[t]=h,a&&(s+=a))})),t&&n.byteLength!==s){let e=n.byteLength-s,t=Ue("b",n,s,e);if(null==t)return;i.$OTHERS=t}let o=0,a=[];for(;i[o];)a.push(i[o++]);return a.length>0&&(i.args=a,i.$=i.args),i}});const Qe={hash:function(e){return pe(Ye.U8(e))},hex:function(e){return Ye.B8(pe(Ye.U8(e))).toString("hex")},base64:function(e){return Ye.B8(pe(Ye.U8(e))).toString("base64")},hmac:function(e,t){return function(e,t){const r=new le(e).update(t),n=r.digest();return r.clean(),n}(Ye.U8(e),Ye.U8(t))}};for(var Je={},Xe={byteLength:function(e){var t=nt(e),r=t[0],n=t[1];return 3*(r+n)/4-n},toByteArray:function(e){var t,r,n=nt(e),i=n[0],s=n[1],o=new et(function(e,t,r){return 3*(t+r)/4-r}(0,i,s)),a=0,h=s>0?i-4:i;for(r=0;r<h;r+=4)t=Ze[e.charCodeAt(r)]<<18|Ze[e.charCodeAt(r+1)]<<12|Ze[e.charCodeAt(r+2)]<<6|Ze[e.charCodeAt(r+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=255&t;return 2===s&&(t=Ze[e.charCodeAt(r)]<<2|Ze[e.charCodeAt(r+1)]>>4,o[a++]=255&t),1===s&&(t=Ze[e.charCodeAt(r)]<<10|Ze[e.charCodeAt(r+1)]<<4|Ze[e.charCodeAt(r+2)]>>2,o[a++]=t>>8&255,o[a++]=255&t),o},fromByteArray:function(e){for(var t,r=e.length,n=r%3,i=[],s=16383,o=0,a=r-n;o<a;o+=s)i.push(it(e,o,o+s>a?a:o+s));return 1===n?(t=e[r-1],i.push(Ke[t>>2]+Ke[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],i.push(Ke[t>>10]+Ke[t>>4&63]+Ke[t<<2&63]+"=")),i.join("")}},Ke=[],Ze=[],et="undefined"!=typeof Uint8Array?Uint8Array:Array,tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",rt=0;rt<64;++rt)Ke[rt]=tt[rt],Ze[tt.charCodeAt(rt)]=rt;function nt(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function it(e,t,r){for(var n,i,s=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),s.push(Ke[(i=n)>>18&63]+Ke[i>>12&63]+Ke[i>>6&63]+Ke[63&i]);return s.join("")}Ze["-".charCodeAt(0)]=62,Ze["_".charCodeAt(0)]=63;var st={
18
16
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
19
17
  read:function(e,t,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=e[t+u];for(u+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+e[t+u],u+=l,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+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(e,t,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=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-o))<1&&(o--,h*=2),(t+=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=(t*h-1)*Math.pow(2,i),o+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,i),o=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(o=o<<i|a,f+=i;f>0;e[r+p]=255&o,p+=d,o/=256,f-=8);e[r+p-d]|=128*g}};
20
18
  /*!
@@ -22,4 +20,4 @@ read:function(e,t,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?
22
20
  *
23
21
  * @author Feross Aboukhadijeh <https://feross.org>
24
22
  * @license MIT
25
- */!function(e){const t=et,r=ht,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|p(e,t);let n=s(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(q(e,Uint8Array)){const t=new Uint8Array(e);return u(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(q(e,ArrayBuffer)||e&&q(e.buffer,ArrayBuffer))return u(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(q(e,SharedArrayBuffer)||e&&q(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);const i=function(e){if(o.isBuffer(e)){const t=0|l(e.length),r=s(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?s(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return h(e),s(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=s(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function u(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function l(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return W(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:W(e).length;t=(""+t).toLowerCase(),i=!0}}function d(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return L(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.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:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function _(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(Y(n))return o;e[r+o]=n}return o}function b(e,t,r,n){return V(W(t,e.length-r),e,r,n)}function E(e,t,r,n){return V(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function w(e,t,r,n){return V(G(t),e,r,n)}function B(e,t,r,n){return V(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function v(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}e.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,r){return a(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return h(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},o.allocUnsafe=function(e){return f(e)},o.allocUnsafeSlow=function(e){return f(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=o.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(q(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<h;++e)if(f[e]!==c[e]){s=f[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":case"latin1":case"binary":return E(this,e,t,r);case"base64":return w(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,t,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(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function L(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function I(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=Q[e[n]];return i}function T(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function x(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function R(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function M(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,8),r.write(e,t,n,i,52,8),n+8}o.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},o.prototype.readInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=J((function(e,t=0){return O(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=J((function(e,t=0){return O(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,r){return N(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return N(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return M(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return M(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};const P={};function D(e,t,r){P[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function $(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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,e)}!function(e,t,r){H(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||j(t,e.length-(r+1))}(n,i,s)}function H(e,t){if("number"!=typeof e)throw new P.ERR_INVALID_ARG_TYPE(t,"number",e)}function j(e,t,r){if(Math.floor(e)!==e)throw H(e,r),new P.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" 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 ${t}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function W(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function V(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}}(Ze);let ft={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 e in ft)ft[ft[e]]=e;const ct={AUTH_REQ:Xe.meta(Xe.MB("header","8",0),Xe.MB("reserved","8",0)),AUTH_NONCE:Xe.meta(Xe.MB("header","8",0),Xe.MB("unixTime","32L",0),Xe.MB("milTime","32L",0),Xe.MB("nonce",Ze.Buffer.alloc(4))),AUTH_HMAC:Xe.meta(Xe.MB("header","8",0),Xe.MB("id8",Ze.Buffer.alloc(8)),Xe.MB("nonce",Ze.Buffer.alloc(4)),Xe.MB("hmac32",Ze.Buffer.alloc(32))),AUTH_ACK:Xe.meta(Xe.MB("header","8",0),Xe.MB("hmac32",Ze.Buffer.alloc(32))),ENC_PACK:Xe.meta(Xe.MB("type","8",0),Xe.MB("len","32L",0),Xe.MB("salt12",Ze.Buffer.alloc(12)),Xe.MB("hmac",8,0)),ENC_488:Xe.meta(Xe.MB("type","8",0),Xe.MB("len","32L",0),Xe.MB("otpSrc8",Ze.Buffer.alloc(8)),Xe.MB("hmac8",Ze.Buffer.alloc(8)))};function ut(e){let t=e[e.length-1];return t[2]+t[3]}const lt={AUTH_REQ:ut(ct.AUTH_REQ),AUTH_NONCE:ut(ct.AUTH_NONCE),AUTH_HMAC:ut(ct.AUTH_HMAC),AUTH_ACK:ut(ct.AUTH_ACK),ENC_PACK:ut(ct.ENC_PACK),ENC_488:ut(ct.ENC_488)};function pt(e){return globalThis.crypto.getRandomValues(Ze.Buffer.alloc(e))}class dt{constructor(){this._id8=Ze.Buffer.alloc(8),this._otpSrc44=Ze.Buffer.alloc(44),this._otp36=Ze.Buffer.alloc(36),this._hmac=Ze.Buffer.alloc(32),this.auth_salt12=Ze.Buffer.alloc(12),this.localNonce=Ze.Buffer.alloc(4),this.remoteNonce=Ze.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(e){Xe.B8(Ke.hash(e)).copy(this._id8,0,0,8)}set_id8(e){let t=Xe.B8(e);this._id8.fill(0),t.copy(this._id8,0,0,8)}set_key(e){Xe.B8(Ke.hash(e)).copy(this._otpSrc44,0,0,32)}set_id_key(e){let t=e.indexOf(".");if(-1==t)return;let r=e.substring(0,t),n=e.substring(t+1);this.set_id8(r),this.set_key(n)}copy_id8(e){e.copy(this._id8,0,0,8)}copy_key(e){e.copy(this._otpSrc44,0,0,32)}sha256_n(e,t){let r=Ke.hash(e);for(let e=0;e<t;e++)r=Ke.hash(r);return r}set_clock_rand(){let e=Date.now(),t=parseInt(e/1e3);e%=4294967295,Ze.Buffer.concat([Xe.NB("32L",t),Xe.NB("32L",e),pt(4)]).copy(this._otpSrc44,32)}set_clock_nonce(e){let t=Date.now(),r=parseInt(t/1e3);t%=4294967295,Ze.Buffer.concat([Xe.NB("32L",r),Xe.NB("32L",t),e]).copy(this._otpSrc44,32)}set_salt12(e){e.copy(this._otpSrc44,32)}resetOTP(){Xe.B8(Ke.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(e){return this._otp36.writeUInt32LE(e,32),Ke.hash(this._otp36)}generateHMAC(e){let t=Ze.Buffer.concat([this._otpSrc44,e]);this._hmac=Xe.B8(Ke.hash(t))}getHMAC8(e){let t=Ze.Buffer.concat([this._otpSrc44,e]);return this._hmac=Xe.B8(Ke.hash(t)),this._hmac.subarray(0,8)}xotp(e,t=0,r=!1){let n=(e=Xe.B8(e,r)).byteLength,i=t,s=0,o=0;for(;n>0;){o=n<32?n:32;let t=this.getIndexOTP(++i);for(let r=0;r<o;r++)e[s++]^=t[r];n-=32}return e}auth_req(){return Xe.pack(Xe.MB("#type","8",ft.AUTH_REQ),Xe.MB("#reserved","8",0))}auth_nonce(){let e=Date.now(),t=Math.floor(e/1e3),r=e%1e3;return this.localNonce=pt(4),this.auth_salt12=Ze.Buffer.concat([Xe.NB("32L",t),Xe.NB("32L",r),this.localNonce]),Ze.Buffer.concat([Xe.NB("8",ft.AUTH_NONCE),this.auth_salt12])}auth_hmac(e){let t=Xe.unpack(e,ct.AUTH_NONCE);if(t){let e=Ze.Buffer.concat([Xe.NB("32L",t.unixTime),Xe.NB("32L",t.milTime),t.nonce]);return this.set_salt12(e),this.localNonce=pt(4),this.generateHMAC(this.localNonce),this.remoteNonce=t.nonce,Xe.pack(Xe.MB("#header","8",ft.AUTH_HMAC),Xe.MB("#id8",this._id8),Xe.MB("#nonce",this.localNonce),Xe.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(e){let t;if(e instanceof Uint8Array){if(t=Xe.unpack(e,ct.AUTH_HMAC),!t)return}else t=e;this.set_salt12(this.auth_salt12),this.generateHMAC(t.nonce);let r=this._hmac;if(Xe.equal(t.hmac32,r)){this.remoteNonce=t.nonce;let e=Ze.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(e),this.generateHMAC(t.nonce);let r=this._hmac,n=Xe.rawPack(Xe.MB("header","8",ft.AUTH_ACK),Xe.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(e){let t=Xe.unpack(e,ct.AUTH_ACK);if(t){let e=Ze.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(e),this.generateHMAC(this.localNonce);let r=this._hmac;if(Xe.equal(r,t.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(e){if(!this.isAuthorized)return;e=Xe.B8(e),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let t=this.getHMAC8(e),r=this.xotp(e);return Xe.pack(Xe.MB("#type","8",ft.ENC_488),Xe.MB("#len","32L",e.byteLength),Xe.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Xe.MB("#hmac8",t),Xe.MB("#xdata",r))}decrypt_488(e){e=Xe.B8(e);let t=Xe.unpack(e,ct.ENC_488);if(t){let e=Ze.Buffer.concat([t.otpSrc8,this.localNonce]);this.set_salt12(e),this.resetOTP();let r=t.$OTHERS.subarray(0,t.len),n=this.xotp(r),i=this.getHMAC8(n);if(Xe.equal(i,t.hmac8))return n}}encryptPack(e){e=Xe.B8(e),this.set_clock_rand(),this.resetOTP();let t=this.getHMAC8(e),r=this.xotp(e);return Xe.pack(Xe.MB("#type","8",ft.ENC_PACK),Xe.MB("#len","32L",e.byteLength),Xe.MB("#salt12",this._otpSrc44.subarray(32)),Xe.MB("#hmac8",t),Xe.MB("#xdata",r))}decryptPack(e){if(e[0]===ft.ENC_PACK&&e.readUint32LE(1)==e.byteLength-lt.ENC_PACK)try{let t=Xe.unpack(e,ct.ENC_PACK);if(!t)return;this.set_salt12(t.salt12),this.resetOTP();let r=t.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Xe.equal(t.hmac,i))return t.data=n,t}catch(e){}}encrypt_e2e(e,t){let r=Ze.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(t);let n=this.encryptPack(e);return this._otpSrc44.set(r),n}decrypt_e2e(e,t){let r=Ze.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(t);let n=this.decryptPack(e);return this._otpSrc44.set(r),n}}dt.RAND=pt,dt.BohoMsg=ft,dt.Meta=ct,dt.MetaSize=lt,dt.sha256=Ke,dt.MBP=Xe,dt.Buffer=Ze.Buffer;const gt=J.Buffer,yt=new TextEncoder,mt=new TextDecoder;class _t extends Z{constructor(e){super(),this.cid="",this.ip="",this.socket=null,this.url=e,this.state=ee.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=ne.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new dt,this.TLS=!1,this.encMode=re.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=ne.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=oe[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(e){this.close(),this.stateChange("redirecting"),this.createConnection(e)}open(e){if(e||this.url){if(e)if(this.url){if(e!==this.url&&(this.url=e,this.socket))return void this.close()}else this.url=e;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(e,t){if(!e&&!t)return void console.log("no id and key.");if(console.log("manual login: ",e),!t&&e.includes("."))this.boho.set_id_key(e);else{if(!e||!t)return void console.log("no id or key.");this.boho.set_id8(e),this.boho.set_key(t)}this.useAuth=!0;let r=this.boho.auth_req();this.send(r)}auth(e,t){if(e||t){if(!t&&e.includes("."))this.boho.set_id_key(e);else{if(!e||!t)return void console.log("no id or key.");this.boho.set_id8(e),this.boho.set_key(t)}this.useAuth=!0}else console.log("no id and key.")}onData(e){let t,r=e[0];if(r===dt.BohoMsg.ENC_488)t=this.boho.decrypt_488(e),t&&(r=t[0],e=t);else if(r===dt.BohoMsg.ENC_E2E)try{if(t=this.boho.decrypt_488(e),!t)return;r=t[0],e.set(t,dt.MetaSize.ENC_488),e=e.subarray(dt.MetaSize.ENC_488)}catch(e){return}let n=se[r];switch(n||(n=dt.BohoMsg[r]),r){case se.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case se.PING:this.pong();break;case se.PONG:break;case se.IAM_RES:try{let t=mt.decode(e.subarray(1)),r=JSON.parse(t);r.ip&&(this.ip=r.ip),console.log("<IAM_RES>",JSON.stringify(r))}catch(e){}break;case se.CID_RES:let r=mt.decode(e.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case se.QUOTA_LEVEL:let n=e[1];this.level=n,this.quota=oe[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case se.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case se.SERVER_REDIRECT:let i,s,o;7==e.byteLength?(i=function(e){if(6!=e.byteLength)return;return e[0].toString()+"."+e[1].toString()+"."+e[2].toString()+"."+e[3].toString()+":"+((e[4]<<8)+e[5]).toString()}(e.subarray(1)),o="cong://"):(i=mt.decode(e.subarray(1)),o=""),s=o+i,this.redirect(s);break;case se.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(gt.from([se.CID_REQ]));break;case se.SERVER_SIGNAL:try{let t=mt.decode(e.subarray(1)),r=JSON.parse(t);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(e){}break;case se.SET:try{let t=J.unpack(e);t&&this.emit(t.topic,...t.args)}catch(e){}break;case se.SIGNAL_E2E:case se.SIGNAL:try{let t=e.readUint8(1),r=e.subarray(2,2+t),n=mt.decode(r),i=e.readUint8(2+t),s=e.subarray(3+t);switch(i){case ie.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case ie.TEXT:let e=s.subarray(0,s.byteLength-1),t=mt.decode(e);0===n.indexOf("@")&&this.emit("@",t,n),"@"!==n&&this.emit(n,t,n);break;case ie.BINARY:0===n.indexOf("@")&&this.emit("@",s,n),"@"!==n&&this.emit(n,s,n);break;case ie.OBJECT:let r=mt.decode(s),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case ie.MJSON:let o=mt.decode(s),a=JSON.parse(o);0===n.indexOf("@")&&this.emit("@",...a,n),"@"!==n&&this.emit(n,...a,n);break;case ie.MBA:let h=J.unpack(s);0===n.indexOf("@")&&this.emit("@",...h.args,n),"@"!==n&&this.emit(n,...h.args,n)}}catch(e){}break;case se.RESPONSE_MBP:this.testPromise(e);break;case dt.BohoMsg.AUTH_NONCE:let a=this.boho.auth_hmac(e);a?this.send(a):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case dt.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case dt.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(e)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(gt.from([se.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{t=mt.decode(e),this.emit("text_message",t)}catch(e){}}}iam(e){e?this.send_enc_mode(J.pack(J.MB("#MsgType","8",se.IAM),J.MB("#",e))):this.send_enc_mode(J.pack(J.MB("#MsgType","8",se.IAM)))}ping(){this.send(gt.from([se.PING]))}pong(){this.send(gt.from([se.PONG]))}echo(e){e?(console.log("echo args:",e),this.send_enc_mode(J.pack(J.MB("#MsgType","8",se.ECHO),J.MB("#msg",e)))):this.send(gt.from([se.ECHO]))}bin(...e){this.send(J.U8pack(...e))}send(e){if(e.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",e.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(e)}getEncryptionMode(){return!(this.encMode!==re.YES&&(this.encMode!==re.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(e,t){if(void 0===t&&(t=this.getEncryptionMode()),e[0]==se.SIGNAL_E2E&&t){let t=e[1],r=this.boho.encrypt_488(e.subarray(0,3+t));r[0]=dt.BohoMsg.ENC_E2E,this.send(gt.concat([r,e.subarray(3+t)]))}else if(t){let t=this.boho.encrypt_488(e);this.send(t)}else this.send(e)}setMsgPromise(e){return new Promise(((t,r)=>{this.promiseMap.set(e,[t,r]),setTimeout((t=>{this.promiseMap.has(e)&&(r("timeout"),this.promiseMap.delete(e))}),this.promiseTimeOut)}))}testPromise(e){let t=J.unpack(e);if(t)if(this.promiseMap.has(t.mid)){let[e,r]=this.promiseMap.get(t.mid);this.promiseMap.delete(t.mid),t.status<128?(t.ok=!0,e(t)):(t.ok=!1,r(t))}else console.log("no promise id")}publish(...e){this.signal(...e)}signal(e,...t){if("string"!=typeof e)throw TypeError("tag should be string.");let r=he(e,...t);this.send_enc_mode(r)}decrypt_e2e(e,t){return this.boho.decrypt_e2e(e,t)}signal_e2e(e,t,r){if("string"!=typeof e)throw TypeError("tag should be string.");let n=yt.encode(e),i=J.B8(t),s=this.boho.encrypt_e2e(i,r),o=J.pack(J.MB("#MsgType","8",se.SIGNAL_E2E),J.MB("#tagLen","8",n.byteLength),J.MB("#tag",n),J.MB("#payloadType","8",ie.BINARY),J.MB("#payload",s));this.send_enc_mode(o)}set(e,...t){return e&&0!=t.length?this.req("store","set",e,...t):Promise.reject(new Error("set need storeName and value)"))}async get(e){if(!e)return Promise.reject(new Error("store get need storeName)"));let t=await this.req("store","get",e),{$:r}=J.unpack(t.body);return r}req(e,t,...r){if(!e||!t)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?J.pack(J.MB("#MsgType","8",se.REQUEST),J.MB("mid","16",++this.mid),J.MB("target",e),J.MB("topic",t),J.MBA(...r)):J.pack(J.MB("#MsgType","8",se.REQUEST),J.MB("mid","16",++this.mid),J.MB("target",e),J.MB("topic",t)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(e){if("string"!=typeof e)throw TypeError("tag should be string.");if(this.state!==ee.READY)return;e.split(",").forEach((e=>{this.channels.add(e)}));let t=yt.encode(e);if(t.byteLength>ne.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+ne.TAG_LEN1);this.send_enc_mode(gt.concat([J.NB("8",se.SUBSCRIBE),J.NB("8",t.byteLength),t]))}subscribe_promise(e){if("string"!=typeof e)throw TypeError("tag should be string.");if(this.state!==ee.READY)return Promise.reject("subscribe_promise:: connection is not ready");let t=yt.encode(e);if(t.byteLength>ne.TAG_LEN2)throw TypeError("please use tag string bytelength: "+ne.TAG_LEN2);return this.send_enc_mode(gt.concat([J.NB("8",se.SUBSCRIBE_REQ),J.NB("16",++this.mid),J.NB("16",t.byteLength),t])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let e=Array.from(this.channels).join(",");this.subscribe_promise(e).then((e=>{})).catch((e=>{console.log(">> SUBSCRIBE FAIL:",e)}))}unsubscribe(e=""){if("string"!=typeof e)throw TypeError("tag should be string.");if(""==e)this.channels.clear();else{e.split(",").forEach((e=>{this.channels.delete(e)}))}let t=yt.encode(e);if(t.byteLength>ne.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+ne.TAG_LEN1);this.send_enc_mode(gt.concat([J.NB("8",se.UNSUBSCRIBE),J.NB("8",t.byteLength),t]))}listen(e,t){if("string"!=typeof e)throw TypeError("tag should be string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof t)throw TypeError("handler is not a function.");0!==e.indexOf("@")&&this.channels.add(e),this.on(e,t)}link(e,t,r){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if("string"!=typeof t)throw TypeError("tag is not a string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==t.indexOf("@")&&this.channels.add(t),n=this.linkMap.has(e)?this.linkMap.get(e):new Set,n.add(t),this.linkMap.set(e,n),this.on(t,r),this.subscribe(t)}unlink(e,t){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if("string"!=typeof t)throw TypeError("tag is not a string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if(!this.linkMap.has(e))return;let r=this.linkMap.get(e),n=Array.from(r);for(let i=0;i<n.length;i++)if(n[i]==t){this.unsubscribe(t),this.removeAllListeners(t),r.delete(t),this.linkMap.set(e,r);break}}unlinkAll(e){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if(!this.linkMap.has(e))return;let t=this.linkMap.get(e),r=Array.from(t);for(let e=0;e<r.length;e++)this.unsubscribe(r[e]),this.removeAllListeners(r[e]),t.delete(r[e]);this.linkMap.delete(e)}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 ee[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(e,t){let r=e.toLowerCase();this.state=ee[e.toUpperCase()],t&&this.emit(r,t),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const bt=1,Et=2,wt=3,Bt=4;function vt(e){if(e.byteLength<256)return J.pack(J.MB("#type","8",bt),J.MB("#payloadLen1","8",e.byteLength),J.MB("#payload",e));if(e.byteLength<65536)return J.pack(J.MB("#type","8",Et),J.MB("#payloadLen2","16L",e.byteLength),J.MB("#payload",e));if(e.byteLength<2**24){let t=Buffer.alloc(4);t.writeUint32LE(e.byteLength);let r=t.subarray(0,3);return J.pack(J.MB("#type","8",wt),J.MB("#payloadLen3",r),J.MB("#payload",e))}return J.pack(J.MB("#type","8",Bt),J.MB("#payloadLen4","32L",e.byteLength),J.MB("#payload",e))}class St extends e.Transform{constructor(e){super(e),this.buffer=Buffer.alloc(0),this.frames=[],this.rxi=0,this.rxi_zero=0}_transform(e,t,r){this.addData(e),this.frames.length>0&&(this.frames.forEach((e=>{this.push(e)})),this.frames=[]),r()}addData(e){let t=e.byteLength,r=0;for(;t--;)this.rxi++,0==e[r++]&&this.rxi_zero++;this.buffer.byteLength>0?this.buffer=Buffer.concat([this.buffer,e]):this.buffer=e,this.parse()}parse(){let e,t,r=this.buffer[0];if(r==bt){if(e=2,this.buffer.byteLength<e)return;t=this.buffer.readUint8(1)}else if(r==Et){if(e=3,this.buffer.byteLength<e)return;t=this.buffer.readUint16LE(1)}else if(r==wt){if(e=4,this.buffer.byteLength<e)return;t=this.buffer.readUint16LE(1)+65536*this.buffer.readUint8(3)}else if(r==Bt){if(e=5,this.buffer.byteLength<e)return;t=this.buffer.readUint32LE(1)}else this.emit("wrong",this.buffer),this.buffer=Buffer.alloc(0);if(t==this.buffer.byteLength-e)return this.frames.push(this.buffer.subarray(e)),void(this.buffer=Buffer.alloc(0));t<this.buffer.byteLength-e&&(this.frames.push(this.buffer.subarray(e,e+t)),this.buffer=this.buffer.subarray(e+t),this.parse())}}var At={exports:{}};const kt=["nodebuffer","arraybuffer","fragments"],Lt="undefined"!=typeof Blob;Lt&&kt.push("blob");var It={BINARY_TYPES:kt,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Lt,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}},Tt={exports:{}};function xt(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Ut,Ot,Ct,Rt,Nt,Mt,Pt={exports:{}};function Dt(){if(Ct)return Pt.exports;Ct=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:xt;return"function"==typeof e.addon?Pt.exports=e.addon.bind(e):Pt.exports=function(){if(Ot)return Ut;Ot=1;var e=n,t=i,r=s,o="function"==typeof __webpack_require__?__non_webpack_require__:xt,a=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(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(l)?"musl":"glibc"),d=process.env.ARM_VERSION||("arm64"===u?"8":a.arm_version)||"",g=(process.versions.uv||"").split(".")[0];function y(e){return o(y.resolve(e))}function m(t){try{return e.readdirSync(t)}catch(e){return[]}}function _(e,r){var n=m(e).filter(r);return n[0]&&t.join(e,n[0])}function b(e){return/\.node$/.test(e)}function E(e){var t=e.split("-");if(2===t.length){var r=t[0],n=t[1].split("+");if(r&&n.length&&n.every(Boolean))return{name:e,platform:r,architectures:n}}}function w(e,t){return function(r){return null!=r&&r.platform===e&&r.architectures.includes(t)}}function B(e,t){return e.architectures.length-t.architectures.length}function v(e){var t=e.split("."),r={file:e,specificity:0};if("node"===t.pop()){for(var n=0;n<t.length;n++){var i=t[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(e,t){return function(r){return!(null==r||r.runtime&&r.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(r)||r.abi&&r.abi!==t&&!r.napi||r.uv&&r.uv!==g||r.armv&&r.armv!==d||r.libc&&r.libc!==p)}}function A(e){return function(t,r){return t.runtime!==r.runtime?t.runtime===e?-1:1:t.abi!==r.abi?t.abi?-1:1:t.specificity!==r.specificity?t.specificity>r.specificity?-1:1:0}}return Ut=y,y.resolve=y.path=function(e){e=t.resolve(e||".");try{var r=o(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[r+"_PREBUILD"]&&(e=process.env[r+"_PREBUILD"])}catch(e){}if(!h){var n=_(t.join(e,"build/Release"),b);if(n)return n;var i=_(t.join(e,"build/Debug"),b);if(i)return i}var s=k(e);if(s)return s;var a=k(t.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: "+e+"\n");function k(e){var r=m(t.join(e,"prebuilds")).map(E).filter(w(l,u)).sort(B)[0];if(r){var n=t.join(e,"prebuilds",r.name),i=m(n).map(v).filter(S(c,f)).sort(A(c))[0];return i?t.join(n,i.file):void 0}}},y.parseTags=v,y.matchTags=S,y.compareTags=A,y.parseTuple=E,y.matchTuple=w,y.compareTuples=B,Ut}(),Pt.exports}const{EMPTY_BUFFER:$t}=It,Ft=Buffer[Symbol.species];function Ht(e,t,r,n,i){for(let s=0;s<i;s++)r[n+s]=e[s]^t[3&s]}function jt(e,t){for(let r=0;r<e.length;r++)e[r]^=t[3&r]}if(At.exports={concat:function(e,t){if(0===e.length)return $t;if(1===e.length)return e[0];const r=Buffer.allocUnsafe(t);let n=0;for(let t=0;t<e.length;t++){const i=e[t];r.set(i,n),n+=i.length}return n<t?new Ft(r.buffer,r.byteOffset,n):r},mask:Ht,toArrayBuffer:function(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)},toBuffer:function e(t){if(e.readOnly=!0,Buffer.isBuffer(t))return t;let r;return t instanceof ArrayBuffer?r=new Ft(t):ArrayBuffer.isView(t)?r=new Ft(t.buffer,t.byteOffset,t.byteLength):(r=Buffer.from(t),e.readOnly=!1),r},unmask:jt},!process.env.WS_NO_BUFFER_UTIL)try{const e=function(){if(Mt)return Tt.exports;Mt=1;try{Tt.exports=Dt()(__dirname)}catch(e){Tt.exports=(Nt||(Nt=1,Rt={mask:(e,t,r,n,i)=>{for(var s=0;s<i;s++)r[n+s]=e[s]^t[3&s]},unmask:(e,t)=>{const r=e.length;for(var n=0;n<r;n++)e[n]^=t[3&n]}}),Rt)}return Tt.exports}();At.exports.mask=function(t,r,n,i,s){s<48?Ht(t,r,n,i,s):e.mask(t,r,n,i,s)},At.exports.unmask=function(t,r){t.length<32?jt(t,r):e.unmask(t,r)}}catch(ue){}var zt=At.exports;const Wt=Symbol("kDone"),Gt=Symbol("kRun");const Vt=r,qt=zt,Yt=class{constructor(e){this[Wt]=()=>{this.pending--,this[Gt]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Gt]()}[Gt](){if(this.pending!==this.concurrency&&this.jobs.length){const e=this.jobs.shift();this.pending++,e(this[Wt])}}},{kStatusCode:Qt}=It,Jt=Buffer[Symbol.species],Xt=Buffer.from([0,0,255,255]),Kt=Symbol("permessage-deflate"),Zt=Symbol("total-length"),er=Symbol("callback"),tr=Symbol("buffers"),rr=Symbol("error");let nr;var ir=class{constructor(e,t,r){if(this._maxPayload=0|r,this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!t,this._deflate=null,this._inflate=null,this.params=null,!nr){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;nr=new Yt(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[er];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,r=e.find((e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&!e.client_max_window_bits)));if(!r)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(r.server_no_context_takeover=!0),t.clientNoContextTakeover&&(r.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(r.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?r.client_max_window_bits=t.clientMaxWindowBits:!0!==r.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete r.client_max_window_bits,r}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach((e=>{Object.keys(e).forEach((t=>{let r=e[t];if(r.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(r=r[0],"client_max_window_bits"===t){if(!0!==r){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}else if("server_max_window_bits"===t){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==r)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}e[t]=r}))})),e}decompress(e,t,r){nr.add((n=>{this._decompress(e,t,((e,t)=>{n(),r(e,t)}))}))}compress(e,t,r){nr.add((n=>{this._compress(e,t,((e,t)=>{n(),r(e,t)}))}))}_decompress(e,t,r){const n=this._isServer?"client":"server";if(!this._inflate){const e=`${n}_max_window_bits`,t="number"!=typeof this.params[e]?Vt.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=Vt.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t}),this._inflate[Kt]=this,this._inflate[Zt]=0,this._inflate[tr]=[],this._inflate.on("error",ar),this._inflate.on("data",or)}this._inflate[er]=r,this._inflate.write(e),t&&this._inflate.write(Xt),this._inflate.flush((()=>{const e=this._inflate[rr];if(e)return this._inflate.close(),this._inflate=null,void r(e);const i=qt.concat(this._inflate[tr],this._inflate[Zt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Zt]=0,this._inflate[tr]=[],t&&this.params[`${n}_no_context_takeover`]&&this._inflate.reset()),r(null,i)}))}_compress(e,t,r){const n=this._isServer?"server":"client";if(!this._deflate){const e=`${n}_max_window_bits`,t="number"!=typeof this.params[e]?Vt.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=Vt.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t}),this._deflate[Zt]=0,this._deflate[tr]=[],this._deflate.on("data",sr)}this._deflate[er]=r,this._deflate.write(e),this._deflate.flush(Vt.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=qt.concat(this._deflate[tr],this._deflate[Zt]);t&&(e=new Jt(e.buffer,e.byteOffset,e.length-4)),this._deflate[er]=null,this._deflate[Zt]=0,this._deflate[tr]=[],t&&this.params[`${n}_no_context_takeover`]&&this._deflate.reset(),r(null,e)}))}};function sr(e){this[tr].push(e),this[Zt]+=e.length}function or(e){this[Zt]+=e.length,this[Kt]._maxPayload<1||this[Zt]<=this[Kt]._maxPayload?this[tr].push(e):(this[rr]=new RangeError("Max payload size exceeded"),this[rr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[rr][Qt]=1009,this.removeListener("data",or),this.reset())}function ar(e){this[Kt]._inflate=null,e[Qt]=1007,this[er](e)}var hr,fr,cr,ur={exports:{}},lr={exports:{}};const{isUtf8:pr}=o,{hasBlob:dr}=It;function gr(e){const t=e.length;let r=0;for(;r<t;)if(128&e[r])if(192==(224&e[r])){if(r+1===t||128!=(192&e[r+1])||192==(254&e[r]))return!1;r+=2}else if(224==(240&e[r])){if(r+2>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||224===e[r]&&128==(224&e[r+1])||237===e[r]&&160==(224&e[r+1]))return!1;r+=3}else{if(240!=(248&e[r]))return!1;if(r+3>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||128!=(192&e[r+3])||240===e[r]&&128==(240&e[r+1])||244===e[r]&&e[r+1]>143||e[r]>244)return!1;r+=4}else r++;return!0}if(ur.exports={isBlob:function(e){return dr&&"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&("Blob"===e[Symbol.toStringTag]||"File"===e[Symbol.toStringTag])},isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999},isValidUTF8:gr,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]},pr)ur.exports.isValidUTF8=function(e){return e.length<24?gr(e):pr(e)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=function(){if(cr)return lr.exports;cr=1;try{lr.exports=Dt()(__dirname)}catch(e){lr.exports=(fr||(fr=1,hr=function(e){const t=e.length;let r=0;for(;r<t;)if(128&e[r])if(192==(224&e[r])){if(r+1===t||128!=(192&e[r+1])||192==(254&e[r]))return!1;r+=2}else if(224==(240&e[r])){if(r+2>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||224===e[r]&&128==(224&e[r+1])||237===e[r]&&160==(224&e[r+1]))return!1;r+=3}else{if(240!=(248&e[r]))return!1;if(r+3>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||128!=(192&e[r+3])||240===e[r]&&128==(240&e[r+1])||244===e[r]&&e[r+1]>143||e[r]>244)return!1;r+=4}else r++;return!0}),hr)}return lr.exports}();ur.exports.isValidUTF8=function(t){return t.length<32?gr(t):e(t)}}catch(ue){}var yr=ur.exports;const{Writable:mr}=e,_r=ir,{BINARY_TYPES:br,EMPTY_BUFFER:Er,kStatusCode:wr,kWebSocket:Br}=It,{concat:vr,toArrayBuffer:Sr,unmask:Ar}=zt,{isValidStatusCode:kr,isValidUTF8:Lr}=yr,Ir=Buffer[Symbol.species];var Tr=class extends mr{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||br[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Br]=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(e,t,r){if(8===this._opcode&&0==this._state)return r();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];return this._buffers[0]=new Ir(t.buffer,t.byteOffset+e,t.length-e),new Ir(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const r=this._buffers[0],n=t.length-e;e>=r.length?t.set(this._buffers.shift(),n):(t.set(new Uint8Array(r.buffer,r.byteOffset,e),n),this._buffers[0]=new Ir(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return t}startLoop(e){this._loop=!0;do{switch(this._state){case 0:this.getInfo(e);break;case 1:this.getPayloadLength16(e);break;case 2:this.getPayloadLength64(e);break;case 3:this.getMask();break;case 4:this.getData(e);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2)return void(this._loop=!1);const t=this.consume(2);if(48&t[0]){return void e(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const r=!(64&~t[0]);if(!r||this._extensions[_r.extensionName]){if(this._fin=!(128&~t[0]),this._opcode=15&t[0],this._payloadLength=127&t[1],0===this._opcode){if(r){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void e(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 e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}this._compressed=r}else{if(!(this._opcode>7&&this._opcode<11)){return void e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void e(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(r){return void e(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 e(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&~t[1]),this._isServer){if(!this._masked){return void e(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void e(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(e)}else{e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}}getPayloadLength16(e){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e))}getPayloadLength64(e){if(this._bufferedBytes<8)return void(this._loop=!1);const t=this.consume(8),r=t.readUInt32BE(0);if(r>Math.pow(2,21)-1){e(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)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){e(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(e){let t=Er;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);t=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&Ar(t,this._mask)}if(this._opcode>7)this.controlMessage(t,e);else{if(this._compressed)return this._state=5,void this.decompress(t,e);t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}}decompress(e,t){this._extensions[_r.extensionName].decompress(e,this._fin,((e,r)=>{if(e)return t(e);if(r.length){if(this._messageLength+=r.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void t(e)}this._fragments.push(r)}this.dataMessage(t),0===this._state&&this.startLoop(t)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=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?vr(r,t):"arraybuffer"===this._binaryType?Sr(vr(r,t)):"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(e)})))}else{const n=vr(r,t);if(!this._skipUTF8Validation&&!Lr(n)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}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(e)})))}}controlMessage(e,t){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",e),this._state=0):(this._state=6,setImmediate((()=>{this.emit(9===this._opcode?"ping":"pong",e),this._state=0,this.startLoop(t)})));else{if(0===e.length)this._loop=!1,this.emit("conclude",1005,Er),this.end();else{const r=e.readUInt16BE(0);if(!kr(r)){const e=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const n=new Ir(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Lr(n)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}this._loop=!1,this.emit("conclude",r,n),this.end()}this._state=0}}createError(e,t,r,n,i){this._loop=!1,this._errored=!0;const s=new e(r?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(s,this.createError),s.code=i,s[wr]=n,s}};const{randomFillSync:xr}=a,Ur=ir,{EMPTY_BUFFER:Or,kWebSocket:Cr,NOOP:Rr}=It,{isBlob:Nr,isValidStatusCode:Mr}=yr,{mask:Pr,toBuffer:Dr}=zt,$r=Symbol("kByteLength"),Fr=Buffer.alloc(4),Hr=8192;let jr,zr=Hr;var Wr=class e{constructor(e,t,r){this._extensions=t||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=Rr,this[Cr]=void 0}static frame(e,t){let r,n,i=!1,s=2,o=!1;t.mask&&(r=t.maskBuffer||Fr,t.generateMask?t.generateMask(r):(zr===Hr&&(void 0===jr&&(jr=Buffer.alloc(Hr)),xr(jr,0,Hr),zr=0),r[0]=jr[zr++],r[1]=jr[zr++],r[2]=jr[zr++],r[3]=jr[zr++]),o=!(r[0]|r[1]|r[2]|r[3]),s=6),"string"==typeof e?n=t.mask&&!o||void 0===t[$r]?(e=Buffer.from(e)).length:t[$r]:(n=e.length,i=t.mask&&t.readOnly&&!o);let a=n;n>=65536?(s+=8,a=127):n>125&&(s+=2,a=126);const h=Buffer.allocUnsafe(i?n+s:s);return h[0]=t.fin?128|t.opcode:t.opcode,t.rsv1&&(h[0]|=64),h[1]=a,126===a?h.writeUInt16BE(n,2):127===a&&(h[2]=h[3]=0,h.writeUIntBE(n,4,6)),t.mask?(h[1]|=128,h[s-4]=r[0],h[s-3]=r[1],h[s-2]=r[2],h[s-1]=r[3],o?[h,e]:i?(Pr(e,r,h,s,n),[h]):(Pr(e,r,e,0,n),[h,e])):[h,e]}close(t,r,n,i){let s;if(void 0===t)s=Or;else{if("number"!=typeof t||!Mr(t))throw new TypeError("First argument must be a valid error code number");if(void 0!==r&&r.length){const e=Buffer.byteLength(r);if(e>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+e),s.writeUInt16BE(t,0),"string"==typeof r?s.write(r,2):s.set(r,2)}else s=Buffer.allocUnsafe(2),s.writeUInt16BE(t,0)}const o={[$r]: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,o,i]):this.sendFrame(e.frame(s,o),i)}ping(t,r,n){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):Nr(t)?(i=t.size,s=!1):(i=(t=Dr(t)).length,s=Dr.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[$r]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:s,rsv1:!1};Nr(t)?0!==this._state?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):0!==this._state?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}pong(t,r,n){let i,s;if("string"==typeof t?(i=Buffer.byteLength(t),s=!1):Nr(t)?(i=t.size,s=!1):(i=(t=Dr(t)).length,s=Dr.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");const o={[$r]:i,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:s,rsv1:!1};Nr(t)?0!==this._state?this.enqueue([this.getBlobData,t,!1,o,n]):this.getBlobData(t,!1,o,n):0!==this._state?this.enqueue([this.dispatch,t,!1,o,n]):this.sendFrame(e.frame(t,o),n)}send(e,t,r){const n=this._extensions[Ur.extensionName];let i,s,o=t.binary?2:1,a=t.compress;"string"==typeof e?(i=Buffer.byteLength(e),s=!1):Nr(e)?(i=e.size,s=!1):(i=(e=Dr(e)).length,s=Dr.readOnly),this._firstFragment?(this._firstFragment=!1,a&&n&&n.params[n._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(a=i>=n._threshold),this._compress=a):(a=!1,o=0),t.fin&&(this._firstFragment=!0);const h={[$r]:i,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:o,readOnly:s,rsv1:a};Nr(e)?0!==this._state?this.enqueue([this.getBlobData,e,this._compress,h,r]):this.getBlobData(e,this._compress,h,r):0!==this._state?this.enqueue([this.dispatch,e,this._compress,h,r]):this.dispatch(e,this._compress,h,r)}getBlobData(t,r,n,i){this._bufferedBytes+=n[$r],this._state=2,t.arrayBuffer().then((t=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");return void process.nextTick(Gr,this,e,i)}this._bufferedBytes-=n[$r];const s=Dr(t);r?this.dispatch(s,r,n,i):(this._state=0,this.sendFrame(e.frame(s,n),i),this.dequeue())})).catch((e=>{process.nextTick(Vr,this,e,i)}))}dispatch(t,r,n,i){if(!r)return void this.sendFrame(e.frame(t,n),i);const s=this._extensions[Ur.extensionName];this._bufferedBytes+=n[$r],this._state=1,s.compress(t,n.fin,((t,r)=>{if(this._socket.destroyed){Gr(this,new Error("The socket was closed while data was being compressed"),i)}else this._bufferedBytes-=n[$r],this._state=0,n.readOnly=!1,this.sendFrame(e.frame(r,n),i),this.dequeue()}))}dequeue(){for(;0===this._state&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][$r],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][$r],this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}};function Gr(e,t,r){"function"==typeof r&&r(t);for(let r=0;r<e._queue.length;r++){const n=e._queue[r],i=n[n.length-1];"function"==typeof i&&i(t)}}function Vr(e,t,r){Gr(e,t,r),e.onerror(t)}const{kForOnEventAttribute:qr,kListener:Yr}=It,Qr=Symbol("kCode"),Jr=Symbol("kData"),Xr=Symbol("kError"),Kr=Symbol("kMessage"),Zr=Symbol("kReason"),en=Symbol("kTarget"),tn=Symbol("kType"),rn=Symbol("kWasClean");class nn{constructor(e){this[en]=null,this[tn]=e}get target(){return this[en]}get type(){return this[tn]}}Object.defineProperty(nn.prototype,"target",{enumerable:!0}),Object.defineProperty(nn.prototype,"type",{enumerable:!0});class sn extends nn{constructor(e,t={}){super(e),this[Qr]=void 0===t.code?0:t.code,this[Zr]=void 0===t.reason?"":t.reason,this[rn]=void 0!==t.wasClean&&t.wasClean}get code(){return this[Qr]}get reason(){return this[Zr]}get wasClean(){return this[rn]}}Object.defineProperty(sn.prototype,"code",{enumerable:!0}),Object.defineProperty(sn.prototype,"reason",{enumerable:!0}),Object.defineProperty(sn.prototype,"wasClean",{enumerable:!0});class on extends nn{constructor(e,t={}){super(e),this[Xr]=void 0===t.error?null:t.error,this[Kr]=void 0===t.message?"":t.message}get error(){return this[Xr]}get message(){return this[Kr]}}Object.defineProperty(on.prototype,"error",{enumerable:!0}),Object.defineProperty(on.prototype,"message",{enumerable:!0});class an extends nn{constructor(e,t={}){super(e),this[Jr]=void 0===t.data?null:t.data}get data(){return this[Jr]}}Object.defineProperty(an.prototype,"data",{enumerable:!0});const hn={addEventListener(e,t,r={}){for(const n of this.listeners(e))if(!r[qr]&&n[Yr]===t&&!n[qr])return;let n;if("message"===e)n=function(e,r){const n=new an("message",{data:r?e:e.toString()});n[en]=this,cn(t,this,n)};else if("close"===e)n=function(e,r){const n=new sn("close",{code:e,reason:r.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});n[en]=this,cn(t,this,n)};else if("error"===e)n=function(e){const r=new on("error",{error:e,message:e.message});r[en]=this,cn(t,this,r)};else{if("open"!==e)return;n=function(){const e=new nn("open");e[en]=this,cn(t,this,e)}}n[qr]=!!r[qr],n[Yr]=t,r.once?this.once(e,n):this.on(e,n)},removeEventListener(e,t){for(const r of this.listeners(e))if(r[Yr]===t&&!r[qr]){this.removeListener(e,r);break}}};var fn={CloseEvent:sn,ErrorEvent:on,Event:nn,EventTarget:hn,MessageEvent:an};function cn(e,t,r){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}const{tokenChars:un}=yr;function ln(e,t,r){void 0===e[t]?e[t]=[r]:e[t].push(r)}var pn={format:function(e){return Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>[t].concat(Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>!0===e?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")},parse:function(e){const t=Object.create(null);let r,n,i=Object.create(null),s=!1,o=!1,a=!1,h=-1,f=-1,c=-1,u=0;for(;u<e.length;u++)if(f=e.charCodeAt(u),void 0===r)if(-1===c&&1===un[f])-1===h&&(h=u);else if(0===u||32!==f&&9!==f){if(59!==f&&44!==f)throw new SyntaxError(`Unexpected character at index ${u}`);{if(-1===h)throw new SyntaxError(`Unexpected character at index ${u}`);-1===c&&(c=u);const n=e.slice(h,c);44===f?(ln(t,n,i),i=Object.create(null)):r=n,h=c=-1}}else-1===c&&-1!==h&&(c=u);else if(void 0===n)if(-1===c&&1===un[f])-1===h&&(h=u);else if(32===f||9===f)-1===c&&-1!==h&&(c=u);else if(59===f||44===f){if(-1===h)throw new SyntaxError(`Unexpected character at index ${u}`);-1===c&&(c=u),ln(i,e.slice(h,c),!0),44===f&&(ln(t,r,i),i=Object.create(null),r=void 0),h=c=-1}else{if(61!==f||-1===h||-1!==c)throw new SyntaxError(`Unexpected character at index ${u}`);n=e.slice(h,u),h=c=-1}else if(o){if(1!==un[f])throw new SyntaxError(`Unexpected character at index ${u}`);-1===h?h=u:s||(s=!0),o=!1}else if(a)if(1===un[f])-1===h&&(h=u);else if(34===f&&-1!==h)a=!1,c=u;else{if(92!==f)throw new SyntaxError(`Unexpected character at index ${u}`);o=!0}else if(34===f&&61===e.charCodeAt(u-1))a=!0;else if(-1===c&&1===un[f])-1===h&&(h=u);else if(-1===h||32!==f&&9!==f){if(59!==f&&44!==f)throw new SyntaxError(`Unexpected character at index ${u}`);{if(-1===h)throw new SyntaxError(`Unexpected character at index ${u}`);-1===c&&(c=u);let o=e.slice(h,c);s&&(o=o.replace(/\\/g,""),s=!1),ln(i,n,o),44===f&&(ln(t,r,i),i=Object.create(null),r=void 0),n=void 0,h=c=-1}}else-1===c&&(c=u);if(-1===h||a||32===f||9===f)throw new SyntaxError("Unexpected end of input");-1===c&&(c=u);const l=e.slice(h,c);return void 0===r?ln(t,l,i):(void 0===n?ln(i,l,!0):ln(i,n,s?l.replace(/\\/g,""):l),ln(t,r,i)),t}};const dn=h,gn=f,yn=c,mn=t,_n=u,{randomBytes:bn,createHash:En}=a,{URL:wn}=l,Bn=ir,vn=Tr,Sn=Wr,{isBlob:An}=yr,{BINARY_TYPES:kn,EMPTY_BUFFER:Ln,GUID:In,kForOnEventAttribute:Tn,kListener:xn,kStatusCode:Un,kWebSocket:On,NOOP:Cn}=It,{EventTarget:{addEventListener:Rn,removeEventListener:Nn}}=fn,{format:Mn,parse:Pn}=pn,{toBuffer:Dn}=zt,$n=3e4,Fn=Symbol("kAborted"),Hn=[8,13],jn=["CONNECTING","OPEN","CLOSING","CLOSED"],zn=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;let Wn=class e extends dn{constructor(t,r,n){super(),this._binaryType=kn[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Ln,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=e.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==t?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===r?r=[]:Array.isArray(r)||("object"==typeof r&&null!==r?(n=r,r=[]):r=[r]),Vn(this,t,r,n)):(this._autoPong=n.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){kn.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}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,r,n){const i=new vn({allowSynchronousEvents:n.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:n.maxPayload,skipUTF8Validation:n.skipUTF8Validation}),s=new Sn(t,this._extensions,n.generateMask);this._receiver=i,this._sender=s,this._socket=t,i[On]=this,s[On]=this,t[On]=this,i.on("conclude",Kn),i.on("drain",Zn),i.on("error",ei),i.on("message",ri),i.on("ping",ni),i.on("pong",ii),s.onerror=oi,t.setTimeout&&t.setTimeout(0),t.setNoDelay&&t.setNoDelay(),r.length>0&&t.unshift(r),t.on("close",hi),t.on("data",fi),t.on("end",ci),t.on("error",ui),this._readyState=e.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=e.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[Bn.extensionName]&&this._extensions[Bn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=e.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(t,r){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this.readyState!==e.CLOSING?(this._readyState=e.CLOSING,this._sender.close(t,r,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),ai(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";Jn(this,this._req,e)}}pause(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!0,this._socket.pause())}ping(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(n=t,t=r=void 0):"function"==typeof r&&(n=r,r=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===r&&(r=!this._isServer),this._sender.ping(t||Ln,r,n)):Xn(this,t,n)}pong(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof t?(n=t,t=r=void 0):"function"==typeof r&&(n=r,r=void 0),"number"==typeof t&&(t=t.toString()),this.readyState===e.OPEN?(void 0===r&&(r=!this._isServer),this._sender.pong(t||Ln,r,n)):Xn(this,t,n)}resume(){this.readyState!==e.CONNECTING&&this.readyState!==e.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(t,r,n){if(this.readyState===e.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof r&&(n=r,r={}),"number"==typeof t&&(t=t.toString()),this.readyState!==e.OPEN)return void Xn(this,t,n);const i={binary:"string"!=typeof t,mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Bn.extensionName]||(i.compress=!1),this._sender.send(t||Ln,i,n)}terminate(){if(this.readyState!==e.CLOSED)if(this.readyState!==e.CONNECTING)this._socket&&(this._readyState=e.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";Jn(this,this._req,e)}}};Object.defineProperty(Wn,"CONNECTING",{enumerable:!0,value:jn.indexOf("CONNECTING")}),Object.defineProperty(Wn.prototype,"CONNECTING",{enumerable:!0,value:jn.indexOf("CONNECTING")}),Object.defineProperty(Wn,"OPEN",{enumerable:!0,value:jn.indexOf("OPEN")}),Object.defineProperty(Wn.prototype,"OPEN",{enumerable:!0,value:jn.indexOf("OPEN")}),Object.defineProperty(Wn,"CLOSING",{enumerable:!0,value:jn.indexOf("CLOSING")}),Object.defineProperty(Wn.prototype,"CLOSING",{enumerable:!0,value:jn.indexOf("CLOSING")}),Object.defineProperty(Wn,"CLOSED",{enumerable:!0,value:jn.indexOf("CLOSED")}),Object.defineProperty(Wn.prototype,"CLOSED",{enumerable:!0,value:jn.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(Wn.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(Wn.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[Tn])return t[xn];return null},set(t){for(const t of this.listeners(e))if(t[Tn]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[Tn]:!0})}})})),Wn.prototype.addEventListener=Rn,Wn.prototype.removeEventListener=Nn;var Gn=Wn;function Vn(e,t,r,n){const i={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:Hn[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...n,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(e._autoPong=i.autoPong,!Hn.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Hn.join(", ")})`);let s;if(t instanceof wn)s=t;else try{s=new wn(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}"http:"===s.protocol?s.protocol="ws:":"https:"===s.protocol&&(s.protocol="wss:"),e._url=s.href;const o="wss:"===s.protocol,a="ws+unix:"===s.protocol;let h;if("ws:"===s.protocol||o||a?a&&!s.pathname?h="The URL's pathname is empty":s.hash&&(h="The URL contains a fragment identifier"):h='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"',h){const t=new SyntaxError(h);if(0===e._redirects)throw t;return void qn(e,t)}const f=o?443:80,c=bn(16).toString("base64"),u=o?gn.request:yn.request,l=new Set;let p,d;if(i.createConnection=i.createConnection||(o?Qn:Yn),i.defaultPort=i.defaultPort||f,i.port=s.port||f,i.host=s.hostname.startsWith("[")?s.hostname.slice(1,-1):s.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":c,Connection:"Upgrade",Upgrade:"websocket"},i.path=s.pathname+s.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(p=new Bn(!0!==i.perMessageDeflate?i.perMessageDeflate:{},!1,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=Mn({[Bn.extensionName]:p.offer()})),r.length){for(const e of r){if("string"!=typeof e||!zn.test(e)||l.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");l.add(e)}i.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(s.username||s.password)&&(i.auth=`${s.username}:${s.password}`),a){const e=i.path.split(":");i.socketPath=e[0],i.path=e[1]}if(i.followRedirects){if(0===e._redirects){e._originalIpc=a,e._originalSecure=o,e._originalHostOrSocketPath=a?i.socketPath:s.host;const t=n&&n.headers;if(n={...n,headers:{}},t)for(const[e,r]of Object.entries(t))n.headers[e.toLowerCase()]=r}else if(0===e.listenerCount("redirect")){const t=a?!!e._originalIpc&&i.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&s.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,t||delete i.headers.host,i.auth=void 0)}i.auth&&!n.headers.authorization&&(n.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),d=e._req=u(i),e._redirects&&e.emit("redirect",e.url,d)}else d=e._req=u(i);i.timeout&&d.on("timeout",(()=>{Jn(e,d,"Opening handshake has timed out")})),d.on("error",(t=>{null===d||d[Fn]||(d=e._req=null,qn(e,t))})),d.on("response",(s=>{const o=s.headers.location,a=s.statusCode;if(o&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects)return void Jn(e,d,"Maximum redirects exceeded");let s;d.abort();try{s=new wn(o,t)}catch(t){const r=new SyntaxError(`Invalid URL: ${o}`);return void qn(e,r)}Vn(e,s,r,n)}else e.emit("unexpected-response",d,s)||Jn(e,d,`Unexpected server response: ${s.statusCode}`)})),d.on("upgrade",((t,r,n)=>{if(e.emit("upgrade",t),e.readyState!==Wn.CONNECTING)return;d=e._req=null;const s=t.headers.upgrade;if(void 0===s||"websocket"!==s.toLowerCase())return void Jn(e,r,"Invalid Upgrade header");const o=En("sha1").update(c+In).digest("base64");if(t.headers["sec-websocket-accept"]!==o)return void Jn(e,r,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let h;if(void 0!==a?l.size?l.has(a)||(h="Server sent an invalid subprotocol"):h="Server sent a subprotocol but none was requested":l.size&&(h="Server sent no subprotocol"),h)return void Jn(e,r,h);a&&(e._protocol=a);const f=t.headers["sec-websocket-extensions"];if(void 0!==f){if(!p){return void Jn(e,r,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=Pn(f)}catch(t){return void Jn(e,r,"Invalid Sec-WebSocket-Extensions header")}const n=Object.keys(t);if(1!==n.length||n[0]!==Bn.extensionName){return void Jn(e,r,"Server indicated an extension that was not requested")}try{p.accept(t[Bn.extensionName])}catch(t){return void Jn(e,r,"Invalid Sec-WebSocket-Extensions header")}e._extensions[Bn.extensionName]=p}e.setSocket(r,n,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})})),i.finishRequest?i.finishRequest(d,e):d.end()}function qn(e,t){e._readyState=Wn.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function Yn(e){return e.path=e.socketPath,mn.connect(e)}function Qn(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=mn.isIP(e.host)?"":e.host),_n.connect(e)}function Jn(e,t,r){e._readyState=Wn.CLOSING;const n=new Error(r);Error.captureStackTrace(n,Jn),t.setHeader?(t[Fn]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(qn,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function Xn(e,t,r){if(t){const r=An(t)?t.size:Dn(t).length;e._socket?e._sender._bufferedBytes+=r:e._bufferedAmount+=r}if(r){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${jn[e.readyState]})`);process.nextTick(r,t)}}function Kn(e,t){const r=this[On];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,void 0!==r._socket[On]&&(r._socket.removeListener("data",fi),process.nextTick(si,r._socket),1005===e?r.close():r.close(e,t))}function Zn(){const e=this[On];e.isPaused||e._socket.resume()}function ei(e){const t=this[On];void 0!==t._socket[On]&&(t._socket.removeListener("data",fi),process.nextTick(si,t._socket),t.close(e[Un])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function ti(){this[On].emitClose()}function ri(e,t){this[On].emit("message",e,t)}function ni(e){const t=this[On];t._autoPong&&t.pong(e,!this._isServer,Cn),t.emit("ping",e)}function ii(e){this[On].emit("pong",e)}function si(e){e.resume()}function oi(e){const t=this[On];t.readyState!==Wn.CLOSED&&(t.readyState===Wn.OPEN&&(t._readyState=Wn.CLOSING,ai(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function ai(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),$n)}function hi(){const e=this[On];let t;this.removeListener("close",hi),this.removeListener("data",fi),this.removeListener("end",ci),e._readyState=Wn.CLOSING,this._readableState.endEmitted||e._closeFrameReceived||e._receiver._writableState.errorEmitted||null===(t=e._socket.read())||e._receiver.write(t),e._receiver.end(),this[On]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",ti),e._receiver.on("finish",ti))}function fi(e){this[On]._receiver.write(e)||this.pause()}function ci(){const e=this[On];e._readyState=Wn.CLOSING,e._receiver.end(),this.end()}function ui(){const e=this[On];this.removeListener("error",ui),this.on("error",Cn),e&&(e._readyState=Wn.CLOSING,this.destroy())}var li=X(Gn);const{tokenChars:pi}=yr;var di={parse:function(e){const t=new Set;let r=-1,n=-1,i=0;for(;i<e.length;i++){const s=e.charCodeAt(i);if(-1===n&&1===pi[s])-1===r&&(r=i);else if(0===i||32!==s&&9!==s){if(44!==s)throw new SyntaxError(`Unexpected character at index ${i}`);{if(-1===r)throw new SyntaxError(`Unexpected character at index ${i}`);-1===n&&(n=i);const s=e.slice(r,n);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);t.add(s),r=n=-1}}else-1===n&&-1!==r&&(n=i)}if(-1===r||-1!==n)throw new SyntaxError("Unexpected end of input");const s=e.slice(r,i);if(t.has(s))throw new SyntaxError(`The "${s}" subprotocol is duplicated`);return t.add(s),t}};const gi=h,yi=c,{createHash:mi}=a,_i=pn,bi=ir,Ei=di,wi=Gn,{GUID:Bi,kWebSocket:vi}=It,Si=/^[+/0-9A-Za-z]{22}==$/;var Ai=class extends gi{constructor(e,t){if(super(),null==(e={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:wi,...e}).port&&!e.server&&!e.noServer||null!=e.port&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=e.port?(this._server=yi.createServer(((e,t)=>{const r=yi.STATUS_CODES[426];t.writeHead(426,{"Content-Length":r.length,"Content-Type":"text/plain"}),t.end(r)})),this._server.listen(e.port,e.host,e.backlog,t)):e.server&&(this._server=e.server),this._server){const e=this.emit.bind(this,"connection");this._removeListeners=function(e,t){for(const r of Object.keys(t))e.on(r,t[r]);return function(){for(const r of Object.keys(t))e.removeListener(r,t[r])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,r,n)=>{this.handleUpgrade(t,r,n,e)}})}!0===e.perMessageDeflate&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,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(e){if(2===this._state)return e&&this.once("close",(()=>{e(new Error("The server is not running"))})),void process.nextTick(ki,this);if(e&&this.once("close",e),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(ki,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{ki(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");if((-1!==t?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,r,n){t.on("error",Li);const i=e.headers["sec-websocket-key"],s=e.headers.upgrade,o=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void Ti(this,e,t,405,"Invalid HTTP method")}if(void 0===s||"websocket"!==s.toLowerCase()){return void Ti(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!Si.test(i)){return void Ti(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==o&&13!==o){return void Ti(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(e))return void Ii(t,400);const a=e.headers["sec-websocket-protocol"];let h=new Set;if(void 0!==a)try{h=Ei.parse(a)}catch(r){return void Ti(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const f=e.headers["sec-websocket-extensions"],c={};if(this.options.perMessageDeflate&&void 0!==f){const r=new bi(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const e=_i.parse(f);e[bi.extensionName]&&(r.accept(e[bi.extensionName]),c[bi.extensionName]=r)}catch(r){return void Ti(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const s={origin:e.headers[""+(8===o?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(s,((s,o,a,f)=>{if(!s)return Ii(t,o||401,a,f);this.completeUpgrade(c,i,h,e,t,r,n)}));if(!this.options.verifyClient(s))return Ii(t,401)}this.completeUpgrade(c,i,h,e,t,r,n)}completeUpgrade(e,t,r,n,i,s,o){if(!i.readable||!i.writable)return i.destroy();if(i[vi])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return Ii(i,503);const a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${mi("sha1").update(t+Bi).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(r.size){const e=this.options.handleProtocols?this.options.handleProtocols(r,n):r.values().next().value;e&&(a.push(`Sec-WebSocket-Protocol: ${e}`),h._protocol=e)}if(e[bi.extensionName]){const t=e[bi.extensionName].params,r=_i.format({[bi.extensionName]:[t]});a.push(`Sec-WebSocket-Extensions: ${r}`),h._extensions=e}this.emit("headers",a,n),i.write(a.concat("\r\n").join("\r\n")),i.removeListener("error",Li),h.setSocket(i,s,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(h),h.on("close",(()=>{this.clients.delete(h),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ki,this)}))),o(h,n)}};function ki(e){e._state=2,e.emit("close")}function Li(){this.destroy()}function Ii(e,t,r,n){r=r||yi.STATUS_CODES[t],n={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...n},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${t} ${yi.STATUS_CODES[t]}\r\n`+Object.keys(n).map((e=>`${e}: ${n[e]}`)).join("\r\n")+"\r\n\r\n"+r)}function Ti(e,t,r,n,i){if(e.listenerCount("wsClientError")){const n=new Error(i);Error.captureStackTrace(n,Ti),e.emit("wsClientError",n,r,t)}else Ii(r,n,i)}var xi=X(Ai);let Ui={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 Oi=new TextDecoder;J.NB;const Ci=J.MB;class Ri{constructor(e,t){this.socket=e,e.isAlive=!0,e.txCounter=0,e.rxCounter=0,e.openTime=Date.now(),this.boho=new dt,this.encMode=re.AUTO,this.channels=new Set,this.retain_signal=new Map,this.ssid=Ri.ssid++,this.manager=t,this.cid,this.did,this.uid,this.nick="",this.lastEchoMessage="N",this.privateNode=!1,this.HOME_CHANNEL="",this.level=Ui.defaultQuotaIndex,this.quota=oe[this.level],this.isAdmin=!1,this.state,this.stateLog=[],this.setState(te.INIT)}static ssid=1;setState(e){this.state=e,Ui.debug.showAuthInfo&&(this.stateLog.push(e),console.log(this.stateLog.join(">")))}getState(){return this.state}getStateName(){return te[this.state].toLowerCase()}showMessageLog(e,t){let r=this.boho.isAuthorized?`did: ${this.did} ${this.cid}@`:`${this.cid}@`;if(t){let t=se[e[0]];t||(t=dt.BohoMsg[e[0]]),t=" ["+t+"]",e.byteLength>40?console.log(r+t+" LEN:",e.length):console.log(r+t,e)}else console.log(r+" [TEXT] %s",e)}rxQuotaChecker(e){let t=e.byteLength;return this.manager.rxBytes+=t,!(Ui.useQuota.signalSize&&t>this.quota.signalSize)||(console.log("## quota: size over"),this.send(Buffer.from([se.OVER_SIZE])),Ui.useQuota.disconnect&&this.close(),!1)}onTimeDelayMessage(e,t=!0){setTimeout((()=>{this.onSocketMessage(e,t)}),Ui.debug.delay)}onSocketMessage(e,t=!0){if(this.receiveMonitor(),!this.rxQuotaChecker(e))return;let r,n;if("message"===Ui.showMessage&&this.showMessageLog(e,t),t){if(r=e[0],r===dt.BohoMsg.ENC_488){try{n=this.boho.decrypt_488(e)}catch(e){return void console.log("-- E488 DEC_FAIL",e)}if(!n)return;r=n[0],e=n}else if(r===dt.BohoMsg.ENC_E2E){try{n=this.boho.decrypt_488(e)}catch(e){return}if(!n)return;r=n[0],e.set(n,dt.MetaSize.ENC_488),e=e.subarray(dt.MetaSize.ENC_488)}switch(r){case se.PING:this.pong();break;case se.PONG:break;case se.CID_REQ:this.state<te.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(J.pack(Ci("#cid_ack","8",se.CID_RES),Ci("#cid",this.cid))),this.setState(te.CID_READY);break;case se.ECHO:try{let t=Oi.decode(e.subarray(1));this.lastEchoMessage=t}catch(e){}this.send(e,t);break;case se.IAM:if(e.byteLength>1){let t=e.subarray(1);this.nick=Oi.decode(t),console.log("iam nick reset",this.nick)}this.iamResponse();break;case se.SIGNAL_E2E:case se.SIGNAL:if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength>=t+2){let r=e.subarray(2,2+t);r=Oi.decode(r),this.manager.sender(r,this,e)}}break;case se.UNSUBSCRIBE:if(2==e.byteLength)this.manager.unsubscribe([""],this);else if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength==t+2){let r=e.subarray(2,2+t);r=Oi.decode(r);let n=r.split(",");this.manager.unsubscribe(n,this)}}break;case se.SUBSCRIBE:if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength==t+2){let r=e.subarray(2,2+t);r=Oi.decode(r);let n=r.split(",");this.manager.subscribe(n,this)}}break;case se.SUBSCRIBE_REQ:if(e.byteLength>=6){let t=e.readUInt16BE(1),r=e.readUInt16BE(3);if(e.byteLength==r+5){let n=e.subarray(5,5+r);n=Oi.decode(n);let i=n.split(",");this.manager.subscribe(i,this),this.response(t,0)}else this.response(t,255)}break;case se.REQUEST:try{let t=J.unpack(e);if(t){if(!t.target||!t.topic)return;this.manager.server.apiNames.has(t.target)&&this.manager.server.emit(t.target,this,t)}}catch(e){console.log("request catch error",e)}break;case se.CLOSE:if(e.byteLength>1){let t=Oi.decode(e.subarray(1));console.log(">> CLOSE reason:",t),this.close()}break;case dt.BohoMsg.AUTH_REQ:if(!this.manager.authManager)return;this.state<te.SENT_SERVER_READY&&this.close(),this.setState(te.RECV_AUTH_REQ);let r=this.boho.auth_nonce();this.send(r),this.setState(te.SENT_SERVER_NONCE);break;case dt.BohoMsg.AUTH_HMAC:if(!this.manager.authManager)return;return this.state<te.SENT_SERVER_NONCE&&this.close(),this.setState(te.RECV_AUTH_HMAC),void this.manager.authManager.verify_auth_hmac(e,this).then((e=>{e&&this.manager.deligateSignal(remote,"@$name",e.name)})).catch((e=>{}))}}else try{let t=Oi.decode(e);this.manager.server.emit("text_message",t,this)}catch(e){}}response(e,t,r){r?this.send_enc_mode(J.pack(Ci("#type","8",se.RESPONSE_MBP),Ci("status","8",t),Ci("mid","16",e),Ci("body",r))):this.send_enc_mode(J.pack(Ci("#type","8",se.RESPONSE_MBP),Ci("status","8",t),Ci("mid","16",e)))}send_enc_mode(e,t=!1){if((this.encMode===re.YES||this.encMode===re.AUTO&&!this.TLS&&this.boho.isAuthorized)&&(t=!0),t&&e[0]==se.SIGNAL_E2E){let t=e[1],r=this.boho.encrypt_488(e.subarray(0,3+t));r[0]=dt.BohoMsg.ENC_E2E;let n=Buffer.concat([r,e.subarray(3+t)]);this.send(n)}else if(t){let t=this.boho.encrypt_488(e);t&&this.send(t)}else this.send(e)}iamResponse(e=""){if(""==e){let t=[];for(let e of this.channels.keys())t.push(e);e={ssid:this.ssid,uid:this.uid,cid:this.cid,did:this.did,nick:this.nick,ip:this.ip,tag:t}}let t=J.pack(Ci("#MsgType","8",se.IAM_RES),Ci("#info",e));this.send_enc_mode(t)}}const Ni=new TextDecoder;class Mi extends Ri{constructor(e,t,r){super(e,r),this.socketType=e.socketType,"websocket"===this.socketType?(this.TLS="https"===t.headers["x-forwarded-proto"],this.ip=this.getRemoteIP(t)):(this.TLS=!1,this.ip=this.getRemoteIP(e.remoteAddress)),!function(e){if(0===e.indexOf("0.0.0.0"))return!0;if(0===e.indexOf("127.0.0.1"))return!0;if(0===e.indexOf("192.168."))return!0;if(0===e.indexOf("10."))return!0;if(0===e.indexOf("172.")){if(0===e.indexOf("172.16."))return!0;if(0===e.indexOf("172.17."))return!0;if(0===e.indexOf("172.18."))return!0;if(0===e.indexOf("172.19."))return!0;if(0===e.indexOf("172.20."))return!0;if(0===e.indexOf("172.21."))return!0;if(0===e.indexOf("172.22."))return!0;if(0===e.indexOf("172.23."))return!0;if(0===e.indexOf("172.24."))return!0;if(0===e.indexOf("172.25."))return!0;if(0===e.indexOf("172.26."))return!0;if(0===e.indexOf("172.27."))return!0;if(0===e.indexOf("172.28."))return!0;if(0===e.indexOf("172.29."))return!0;if(0===e.indexOf("172.30."))return!0;if(0===e.indexOf("172.31."))return!0}return!1}(this.ip)?this.HOME_CHANNEL="IP:"+function(e){let t=e.split(".");return Buffer.from(t).toString("hex")}(this.ip):(this.HOME_CHANNEL="PRIVATE:",this.privateNode=!0),"websocket"===this.socketType?(Ui.debug.slow?e.on("message",this.onTimeDelayMessage.bind(this)):e.on("message",this.onSocketMessage.bind(this)),e.on("pong",this.receiveMonitor.bind(this)),e.on("ping",this.receiveMonitor.bind(this)),e.on("error",(e=>{console.log("Websocket error",e,e.code)})),e.onclose=e=>{this.manager.removeRemote(this)}):(this.congRx=new St,e.on("data",(e=>{this.congRx.write(e)})),this.congRx.on("wrong",this.onWrongCongPacketMessage.bind(this)),Ui.debug.slow?this.congRx.on("data",this.onTimeDelayMessage.bind(this)):this.congRx.on("data",this.onSocketMessage.bind(this)),e.on("error",(e=>{console.log("TCP Socket error",e)})),e.on("close",(e=>{this.manager.removeRemote(this)})))}onWrongCongPacketMessage(e){if(this.cid);else{let t="";try{t=Ni.decode(e)}catch(r){t+="Len: "+e.byteLength}if(this.manager.attackLogger){let e=`> ${this.ssid} ${this.ip} ${t}`;this.manager.attackLogger.log(e)}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(e){return e.headers["x-forwarded-proto"]}getRemoteIP(e){let t;return e&&e.headers?(t=e.headers["x-forwarded-for"],null==t&&(t=e.socket.remoteAddress)):t=e,t?(0==t.indexOf("::ffff:")&&(t=t.substring(7)),"::1"==t&&(t="127.0.0.1")):t="0.0.0.0",t}ping(){"websocket"===this.socketType?(this.socket.ping(),this.socket.txCounter++):this.send(Buffer.from([se.PING]))}pong(){"websocket"===this.socketType?(this.socket.pong(),this.socket.txCounter++):this.send(Buffer.from([se.PONG]))}getTraffic(){this.socket.bytesWritten||this.socket._socket,this.socket.bytesRead||this.socket._socket,this.socket.txCounter,this.socket.rxCounter}close(e=!1){this.getTraffic(),"websocket"===this.socketType?e?this.socket.terminate():this.socket.close():e?this.socket.destroy():this.socket.end()}send(e,t){this.manager.txBytes+=e.byteLength,this.socket.txCounter++,"websocket"===this.socketType?1===this.socket.readyState?null!=t?this.socket.send(e,{binary:t}):this.socket.send(e):this.close(!0):"open"==this.socket.readyState?this.socket.write(vt(e)):this.close(!0)}}const Pi=new Intl.DateTimeFormat("ko-KR",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",hour12:!1,timeZone:"Asia/Seoul"});class Di{constructor(e){this.file=n.openSync(e,"a+"),console.log("new FileLogger logFile: ",e,this.file)}log(e){let t=Pi.format(new Date)+" "+e+"\n";n.write(this.file,t,(e=>{if(e)throw e}))}}class $i{constructor(e){this.manager=e,this.metricsPack={remotes:[0],channels:[0],txBytes:[0],rxBytes:[0],unixTime:[Math.floor(Date.now()/1e3)],period:0},this.tickId=setInterval((e=>{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(e){let t=[{...p.memoryUsage()}];e&&console.table(t,["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 e&&console.table(r,["lastSSID","remotes","channels","txBytes","rxBytes"]),r[0]}getRemotes(e){let t=Array.from(this.manager.remotes.values()).map((e=>"#"+e.ssid+":"+e.cid+"("+e.state+")"));return e&&console.table(t),t}getCIdList(e){let t=Array.from(this.manager.cid2remote.keys());return e&&console.table(t),t}getChannelList(e){let t=Array.from(this.manager.channel_map.keys());return e&&console.table(t),t}getSubscribers(e){let t=[];if(this.manager.channel_map.has(e)){this.manager.channel_map.get(e).forEach((e=>{t.push(e.cid)}))}return t}getRemoteByCId(e,t=1){if(!this.manager.cid2remote.has(e))return{result:"nop"};{let r=this.manager.cid2remote.get(e);if(1==t)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==t)return{ip:r.ip,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),nick:r.nick,ssid:r.ssid,echo:r.lastEchoMessage};if(3==t)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:re[r.encMode]};if(4==t){let e=Array.from(r.channels.keys()),t=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:e,set:t,retain:n}}}}}const Fi=new TextEncoder,Hi=new TextDecoder;class ji{constructor(e,t){this.server=e,this.txBytes=0,this.rxBytes=0,this.authManager=t,this.connectionLogger,Ui.fileLogger.connection.use&&(this.connectionLogger=new Di(Ui.fileLogger.connection.path)),this.attackLogger,Ui.fileLogger.attack.use&&(this.attackLogger=new Di(Ui.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 $i(this),this.lastSSID=0,this.pingIntervalID=setInterval((e=>{this.remotes.forEach((function(e){let t=e.socket;!1===t.isAlive&&(console.log("## timeout. cid:",e.cid),e.close()),t.txCounter++,t.isAlive=!1,"websocket"===e.socketType?t.ping():e.ping()}))}),Ui.timeout),Ui.showMetric&&(this.monitIntervalID=setInterval((e=>{this.monitor()}),Ui.monitorPeriod))}addRemote(e,t){e.isAlive=!0;let r=new Mi(e,t,this);this.remotes.add(r),r.send(Buffer.from([se.SERVER_READY])),r.setState(te.SENT_SERVER_READY),this.lastSSID=r.ssid;let n=`+ IP:${r.ip} #${r.ssid} ${"websocket"===e.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(n)}removeRemote(e){let t=`- IP:${e.ip} #${e.ssid} cid:${e.cid} ${"websocket"===e?.socket.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(t),this.deligateSignal(e,"@state","close"),this.deligateSignal(e,"@$state","close");for(let t of e.channels.keys())if(this.channel_map.has(t)){const r=this.channel_map.get(t);r.delete(e),0==r.size&&this.channel_map.delete(t)}if(e.boho.isAuthorized);else for(let t of e.retain_signal.keys())t=this.CID_PREFIX+e.cid+"@"+t,this.channel_map.has(t)&&this.channel_map.delete(t);if(e.uid&&this.server.apiNames.has("account")){let t={topic:"detachUserRemote",args:["caller:manager.removeRemote"]};this.server.emit("account",e,t)}this.remotes.delete(e),this.cid2remote.delete(e.cid),e=null}serverSignal(e){let t=J.pack(J.MB("#MsgType","8",se.SERVER_SIGNAL),J.MB("#signalObject",e));this.remotes.forEach((e=>{e.send_enc_mode(t)}))}getSignalTag(e){let t=e.readUint8(1),r=e.subarray(2,2+t);return Hi.decode(r)}getNewSignalTagMessage(e,t){let r=e[0],n=e.readUint8(1),i=Fi.encode(t),s=i.byteLength,o=e.subarray(2+n);return Buffer.concat([Buffer.from([r,s]),i,o])}deligateSignal(e,t,...r){let n=he(t,...r);this.sender(t,e,n)}adminSignal(e,t){return this.cid2remote.has(e)?void this.cid2remote.get(e).send_enc_mode(t):"no cid"}serverSignalTo(e,...t){let r=e.split("@")[0],n=he("@"+e.split("@")[1],...t);if(r&&this.cid2remote.has(r)){let e=this.cid2remote.get(r);return console.log("target",e.state,e.cid),void e.send_enc_mode(n)}return"no cid"}sender(e,t,r){if(Ui.memberOnly&&!t.boho.isAuthorized)return t.send(Buffer.from([se.SERVER_CLEAR_AUTH])),t.close(),["err","not autrized"];if(0==e.indexOf("$"))return["err","prefix $ is reserved for userSet tag."];let n=e.indexOf("@");if(0===n)e=t.cid+e,r=this.getNewSignalTagMessage(r,e);else if(n>0){let t=e.split("@")[0];if(this.cid2remote.has(t)){let n="@"+e.split("@")[1];return r=this.getNewSignalTagMessage(r,n),this.cid2remote.get(t).send_enc_mode(r),["ok",1]}return["err","Invalid cid"]}if((e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e).includes("$")&&Ui.retain.isAvailable&&Ui.retain.limitCounter>this.retain_messages.size&&Ui.retain.limitSize>r.byteLength)if(e.includes("@")){let n=e.split("@")[1];t.retain_signal.set(n,r)}else this.retain_messages.set(e,r);let i=0;if(this.channel_map.has(e)){let n=this.channel_map.get(e);if(n.size>=1){let e;e=Ui.useQuota.publishCounter?Math.min(t.quota.publishCounter,n.size):n.size;let s=n.values();for(;i<e;){let e=s.next().value;if(!e)break;e!==t&&(e.send_enc_mode(r),i++)}return Ui.useQuota.publishCounter,["ok",i]}}return["err","No subscriber."]}subscribe(e,t){return e.forEach((e=>{if(e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e,this.channel_map.has(e)?this.channel_map.get(e).add(t):this.channel_map.set(e,new Set([t])),t.channels.add(e),e.includes("$")&&Ui.retain.isAvailable){let r;if(e.includes("@")){let t=e.split("@")[0];t=t.split(this.CID_PREFIX)[1];let n=e.split("@")[1];if(!this.cid2remote.has(t))return;r=this.cid2remote.get(t).retain_signal.get(n)}else this.retain_messages.has(e)&&(r=this.retain_messages.get(e));r&&t.send_enc_mode(r)}})),t.channels.size}unsubscribe(e,t){1==e.length&&""==e[0]?(t.channels.forEach((e=>{if(this.channel_map.has(e)){let r=this.channel_map.get(e);r.delete(t),0==r.size&&this.channel_map.delete(e)}})),t.channels.clear()):e.forEach((e=>{if(e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e,this.channel_map.has(e)){let r=this.channel_map.get(e);r.delete(t),0==r.size&&this.channel_map.delete(e)}t.channels.delete(e)}))}monitor(){switch(process.stdout.isTTY&&(process.stdout.cursorTo(0,0),process.stdout.clearScreenDown()),Ui.showChannel>0&&this.metric.channels(Ui.showChannel),parseInt(Ui.showMetric)){case 1:this.metric.oneline(!0);break;case 2:this.metric.getRemotes(!0);break;case 3:this.metric.getChannelList(!0)}}closeRemoteByCId(e){return this.cid2remote.has(e)?(this.cid2remote.get(e).close(),1):0}}const zi=0,Wi=255;const Gi=new TextDecoder;class Vi{constructor(){this.authLogger,Ui.fileLogger.auth.use&&(this.authLogger=new Di(Ui.fileLogger.auth.path),console.log("Auth: begin file logger.[auth]"))}send_auth_fail(e,t){if(this.authLogger){let r=`FAIL #${e.ssid} reason:${t} `;this.authLogger.log(r)}console.log("## AUTH_FAIL reason:",t),e.setState(te.AUTH_FAIL),setTimeout((t=>{e.send(Buffer.from([dt.BohoMsg.AUTH_FAIL]))}),Ui.auth.delay_auth_fail)}async verify_auth_hmac(e,t){try{let r=J.unpack(e,dt.Meta.AUTH_HMAC);if(!r)return void this.send_auth_fail(t,"unpack auth_pack fail");let n="";n=r.id8.includes(0)?Gi.decode(r.id8.subarray(0,r.id8.indexOf(0))):Gi.decode(r.id8);let i,s=await this.getAuth(n);if(Ui.debug.showAuthInfo,!s)return void this.send_auth_fail(t,"NO ID:"+n);t.boho.copy_id8(r.id8);const o=44;s.key.length==o?(i=Buffer.from(s.key,"base64"),t.boho.copy_key(i)):t.boho.set_key(s.key);let a=t.boho.check_auth_hmac(r);if(!a)return void this.send_auth_fail(t,"hmac dismatched");if(t.manager.cid2remote.has(s.cid)){let e=t.manager.cid2remote.get(s.cid);return e==t?void console.log("## trying RELOGIN with SAME ID. ignored."):(console.log("### clear_auth and close old connection:",e.cid),e.send(Buffer.from([se.SERVER_CLEAR_AUTH])),e.close(),void t.close())}t.cid&&t.manager.cid2remote.delete(t.cid),t.did=n,t.cid=s.cid,t.nick=s.cid;let h=Ui.defaultQuotaIndex;s.level&&(h=s.level),h=parseInt(h);let f=oe[h];if(!f){let e="no index quotaTable for auth.level: "+h;return console.log("##AUTH:DATA ERROR##",e),void this.send_auth_fail(t,e)}if(t.level=h,t.quota=f,t.level===Ui.adminLevel&&(console.log("## LOGIN ADMIN CID:",t.cid),t.isAdmin=!0),t.send(Buffer.from([se.QUOTA_LEVEL,h])),t.manager.cid2remote.set(t.cid,t),t.send(a),t.setState(te.AUTH_READY),this.authLogger){let e=`OK #${t.ssid} cid: ${t.cid} did:${t.did}`;t.isAdmin&&(e="#ADMIN# "+e),this.authLogger.log(e)}return s}catch(e){this.send_auth_fail(t,"caught: unknown error"+e)}}}const qi="device:";var Yi=Object.freeze({__proto__:null,checkPermission:function(e){return e.level>=0},date:async function(e,t){let r=(new Date).toUTCString();e.response(t.mid,zi,r)},echo:async function(e,t){t.args?e.response(t.mid,zi,t.args):e.response(t.mid,Wi,"no message to echo")},unixtime:async function(e,t){let r=Math.floor(Date.now()/1e3);e.response(t.mid,zi,r)}});var Qi=Object.freeze({__proto__:null,checkPermission:function(e){return e.level>=255},commands:["cid","remotes","clients","channels","subscribers","remote","client","close","addauth","getauth","delauth","getauthidlist","getdevicelist","adddevice","getdevice","deldevice"],request:async function(e,t){let r,n=0;try{let i=t.topic;if(i=i.toLowerCase(),"cid"==i)r=e.manager.metric.getCIdList();else if("remotes"==i||"clients"==i)r=e.manager.metric.getRemotes();else if("channels"==i)r=e.manager.metric.getChannelList();else if("subscribers"==i){let n=t.$[0];n&&(r=e.manager.metric.getSubscribers(n))}else if("remote"==i||"client"==i){let n=t.$[0],i=t.$[1];n&&(r=e.manager.metric.getRemoteByCId(n,i))}else if("close"==i)t.$[0]&&(r=e.manager.closeRemoteByCId(t.$[0]));else if("addauth"==i||"adddevice"==i){if(e.manager.authManager&&4==t.$.length&&e.manager.authManager.addAuth){let n=t.$[0],i=t.$[1],s=t.$[2],o=t.$[3];r=await e.manager.authManager.addAuth(n,i,s,o)}}else if("delauth"==i||"deldevice"==i){if(e.manager.authManager&&1==t.$.length&&e.manager.authManager.delAuth){let n=t.$[0];r=await e.manager.authManager.delAuth(n)}}else if("getauth"==i||"getdevice"==i){if(e.manager.authManager&&1==t.$.length&&e.manager.authManager.getAuth){let n=t.$[0];r=await e.manager.authManager.getAuth(n)}}else"getauthidlist"==i||"getdevicelist"==i?e.manager.authManager&&e.manager.authManager.getAuthIdList&&(r=await e.manager.authManager.getAuthIdList()):(n=Wi,r="api sudo: no such a cmd: "+i);e.response(t.mid,n,r)}catch(r){e.response(t.mid,Wi,r.message)}}});const Ji=["GET","SET","HGETALL","HGET","HSET","SADD","SISMEMBER","SMEMBERS","EXISTS","SREM","DEL","KEYS","SAVE"];exports.API_TYPE={REQUEST_RESPONSE:"requet_response",ONE_WAY:"one_way"},exports.Auth_Env=class extends Vi{constructor(e){let t;super(),e?t=e.split(","):process.env.BOHO_AUTH?(e=process.env.BOHO_AUTH,t=process.env.BOHO_AUTH.split(",")):(console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo"),process.exit()),this.AUTH=new Map,t.length>=1?t.forEach((e=>{let t=e.split(".")[0],r=e.split(".")[1],n=e.split(".")[2];if(n=parseInt(n),t&&r&&"number"==typeof n){let e=t;this.addAuth(t,r,e,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(e){return this.AUTH.get(e)}async getAuthIdList(){return Array.from(this.AUTH.keys())}addAuth(e,t,r,n=0){let i=Buffer.from(dt.sha256.hash(t)).toString("base64");this.AUTH.set(e,{key:i,cid:r,level:n})}},exports.Auth_File=class extends Vi{constructor(e){super(),this.AUTH=new Map;let t=i.parse(e);this.path=i.resolve(e),console.log("auth from file path:",this.path);let r=t.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(e){return this.AUTH.get(e)}async getAuthIdList(){return Array.from(this.AUTH.keys())}loadAuthInfoFile_JS(e){import(e).then((e=>{console.log(e.authInfo),e.authInfo.forEach((e=>{this.addAuth(...e)})),console.log("total AUTH INFO size: ",this.AUTH.size)})).catch((e=>{console.log(e)}))}loadAuthInfoFile_JSON(e){let t=n.readFileSync(e);t=(new TextDecoder).decode(t),JSON.parse(t).forEach((e=>{this.addAuth(...e)})),console.log("total AUTH INFO size: ",this.AUTH.size)}addAuth(e,t,r,n=0){let i=Buffer.from(dt.sha256.hash(t)).toString("base64");this.AUTH.set(e,{key:i,cid:r,level:n})}},exports.Auth_Redis=class extends Vi{constructor(e){if(super(),!e)throw new Error("AuthRedis constructor: no redisClient");this.redis=e}async getAuth(e){let t=await this.redis.hGetAll(qi+e);if(t.key)return t}async getAuthIdList(){let e=await this.redis.keys(qi+"*");if(e=e.map((e=>e.split(":")[1])),e)return e}async addAuth(e,t,r="",n=0){let i=Buffer.from(dt.sha256.hash(t)).toString("base64");return this.redis.hSet(qi+e,{key:i,cid:r,level:n})}async delAuth(e){return this.redis.del(qi+e)}async save(e){return this.redis.save()}},exports.Boho=dt,exports.BohoAuth=Vi,exports.CLIENT_STATE=te,exports.CongRx=St,exports.ENC_MODE=re,exports.FileLogger=Di,exports.IOCongSocket=class extends _t{constructor(e){super(e),e&&this.open()}close(){this.socket?.end(),this.socket=null}stop(){this.close(),clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null}keepAlive(){let e=this.socket?.readyState;(!this.socket||"open"!==e&&"opening"!==e)&&this.open()}createConnection(e){let r=new URL(e);"cong:"!=r.protocol&&(r=new URL("cong://"+e)),this.socket=t.createConnection(r.port,r.hostname),this.stateChange("opening"),this.socket.on("connect",(()=>{this.congRx=new St,this.socket.pipe(this.congRx),this.congRx.on("data",this.onTCPSocketMessage.bind(this)),this.emit("open")})),this.socket.on("error",(e=>{this.emit("error",e)})),this.socket.on("close",(()=>{this.emit("close")}))}onTCPSocketMessage(e){this.rxCounter++,this.rxBytes+=e.byteLength,this.lastTxRxTime=Date.now(),this.emit("socket_data",e)}socket_send(e){if("open"===this.socket?.readyState){let t=vt(e);this.socket.write(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()}else console.log(".")}},exports.IOMsg=se,exports.IOWS=class extends _t{constructor(e){super(e),e&&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(e){this.socket=new li(e),this.stateChange("opening"),this.socket.onopen=()=>{this.socket.on("message",this.onWebSocketMessage.bind(this)),this.emit("open")},this.socket.onerror=e=>{this.emit("error",e)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(e){this.rxCounter++,this.lastTxRxTime=Date.now(),this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(e){1===this.socket?.readyState?(this.socket.send(e),this.txCounter++,this.txBytes+=e.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}},exports.MBP=J,exports.PAYLOAD_TYPE=ie,exports.RedisAPI=class{constructor(e,t){if(!e)throw new Error("RedisAPI constructor: no redisClient");this.redisClient=e,this.minLevel=t||200,this.commands=Ji}checkPermission(e,t){return console.log("checkPermission",e.level,"vs",this.minLevel),e.level>=this.minLevel}async request(e,t){let r,n=zi;try{let i=t.topic;i=i.toUpperCase(),Ji.includes(i)?(console.log("RedisAPI call:",i,t.args),r=t.args.length>0?await this.redisClient[i](...t.args):await this.redisClient[i]()):n=Wi,e.response(t.mid,n,r)}catch(r){e.response(t.mid,Wi,r.message)}}},exports.SIZE_LIMIT=ne,exports.STATES=ee,exports.STATUS={OK:0,ERROR:255},exports.Server=class extends h{constructor(e,t){if(super(),this.apiNames=new Set,this.wss={},e.timeout){let t=parseInt(e.timeout);t&&t>=1e3&&(Ui.timeout=t)}if(e.monitorPeriod){let t=parseInt(e.monitorPeriod);t&&t>=1e3&&(Ui.monitorPeriod=t)}e.showMessage&&(Ui.showMessage=e.showMessage),e.showMetric&&(Ui.showMetric=e.showMetric),e.timeout&&(Ui.timeout=e.timeout),e.port&&(Ui.port=parseInt(e.port)),e.httpServer&&(Ui.httpServer=e.httpServer),e.congPort&&(Ui.congPort=parseInt(e.congPort)),this.manager=new ji(this,t),(Ui.port||Ui.httpServer)&&this.startWSServer(Ui),Ui.congPort&&this.startCongServer(Ui.congPort)}startWSServer(e){if(e.port)console.log("opening WebSocket Server port:",e.port),this.wss=new xi({port:e.port});else{if(!e.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 xi({server:e.httpServer})}this.wss.on("error",(e=>{console.error("### ws server error:",e.message),"EADDRINUSE"==e.code&&process.exit()})),this.wss.on("close",(e=>{console.log("### WS server closed.",e)})),this.wss.on("connection",((e,t)=>{e.socketType="websocket",this.manager.addRemote(e,t)}))}startCongServer(e){console.log("opening CongSocket Server:",e),this.congServer=t.createServer((e=>{this.manager.addRemote(e)})).on("error",(e=>{console.log("### cong server error:",e.message),"EADDRINUSE"==e.code&&process.exit()})).listen(e,(()=>{}))}api(e,t){if(this.apiNames.add(e),!t.checkPermission||"function"!=typeof t.checkPermission)throw new Error("wrong api interface. no checkPermission function.");if("function"==typeof t.request&&Array.isArray(t.commands))console.log(`API TYPE1. A Class with one request function. target: ${e} list: ${t.commands}`),this.on(e,((e,r)=>{t.checkPermission(e,r)?t.request(e,r):e.response(r.mid,Wi,"NO_PERMISSION.")}));else{let r=[];Object.keys(t).forEach((e=>{"function"==typeof t[e]&&r.push(e),console.log("api list",typeof t[e],e)})),console.log(`API TYPE2. Multiple function list. target: ${e} list:${r}`),this.on(e,((r,n)=>{let i;if(t.checkPermission(r,n)){if(t[n.topic])return console.log(`API TYPE2. request target: ${e} has topic:${n.topic}`),void t[n.topic](r,n);i=`target: ${n.target} has not topic name: ${n.topic}`}else i="NO_PERMISSION.";r.response(n.mid,Wi,i)}))}return this}},exports.api_reply=Yi,exports.api_sudo=Qi,exports.getPayloadFromSignalPack=function(e){let t=e.readUint8(1);return e.subarray(3+t)},exports.getSignalPack=he,exports.pack=vt,exports.parsePayload=fe,exports.serverOption=Ui,exports.version="2.1.0";
23
+ */!function(e){const t=Xe,r=st,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|p(e,t);let n=s(r);const i=n.write(e,t);return i!==r&&(n=n.slice(0,i)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(q(e,Uint8Array)){const t=new Uint8Array(e);return u(t.buffer,t.byteOffset,t.byteLength)}return c(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(q(e,ArrayBuffer)||e&&q(e.buffer,ArrayBuffer))return u(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(q(e,SharedArrayBuffer)||e&&q(e.buffer,SharedArrayBuffer)))return u(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);const i=function(e){if(o.isBuffer(e)){const t=0|l(e.length),r=s(t);return 0===r.length||e.copy(r,0,0,t),r}return void 0!==e.length?"number"!=typeof e.length||Y(e.length)?s(0):c(e):"Buffer"===e.type&&Array.isArray(e.data)?c(e.data):void 0}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function h(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return h(e),s(e<0?0:0|l(e))}function c(e){const t=e.length<0?0:0|l(e.length),r=s(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function u(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function l(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||q(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return G(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(e).length;default:if(i)return n?-1:G(e).length;t=(""+t).toLowerCase(),i=!0}}function d(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return k(this,t,r);case"latin1":case"binary":return L(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.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:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){let s,o=1,a=e.length,h=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,a/=2,h/=2,r/=2}function f(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){let n=-1;for(s=r;s<a;s++)if(f(e,s)===f(t,-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(e,s+n)!==f(t,n)){r=!1;break}if(r)return s}return-1}function _(e,t,r,n){r=Number(r)||0;const i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;const s=t.length;let o;for(n>s/2&&(n=s/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(Y(n))return o;e[r+o]=n}return o}function b(e,t,r,n){return V(G(t,e.length-r),e,r,n)}function w(e,t,r,n){return V(function(e){const t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function E(e,t,r,n){return V(W(t),e,r,n)}function B(e,t,r,n){return V(function(e,t){let r,n,i;const s=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,s.push(i),s.push(n);return s}(t,e.length-r),e,r,n)}function v(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);const n=[];let i=t;for(;i<r;){const t=e[i];let s=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=r){let r,n,a,h;switch(o){case 1:t<128&&(s=t);break;case 2:r=e[i+1],128==(192&r)&&(h=(31&t)<<6|63&r,h>127&&(s=h));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(h=(15&t)<<12|(63&r)<<6|63&n,h>2047&&(h<55296||h>57343)&&(s=h));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(h=(15&t)<<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(e){const t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}e.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,r){return a(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return h(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},o.allocUnsafe=function(e){return f(e)},o.allocUnsafeSlow=function(e){return f(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),q(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,s=Math.min(r,n);i<s;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;const n=o.allocUnsafe(t);let i=0;for(r=0;r<e.length;++r){let t=e[r];if(q(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(q(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const h=Math.min(s,a),f=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<h;++e)if(f[e]!==c[e]){s=f[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return y(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return y(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let s=!1;for(;;)switch(n){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":case"latin1":case"binary":return w(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,e,t,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(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function L(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function T(e,t,r){const n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=Q[e[n]];return i}function I(e,t,r){const n=e.slice(t,r);let i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function x(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,r}function C(e,t,r,n,i){F(t,n,i,e,r,7);let s=Number(t&BigInt(4294967295));e[r+7]=s,s>>=8,e[r+6]=s,s>>=8,e[r+5]=s,s>>=8,e[r+4]=s;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=o,o>>=8,e[r+2]=o,o>>=8,e[r+1]=o,o>>=8,e[r]=o,r+8}function R(e,t,r,n,i,s){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,4),r.write(e,t,n,i,23,4),n+4}function M(e,t,n,i,s){return t=+t,n>>>=0,s||R(e,0,n,8),r.write(e,t,n,i,52,8),n+8}o.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))})),o.prototype.readBigUInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)})),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,s=0;for(;++s<t&&(i*=256);)n+=this[e+s]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=t,i=1,s=this[e+--n];for(;n>0&&(i*=256);)s+=this[e+--n]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*t)),s},o.prototype.readInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||x(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=J((function(e){H(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||j(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||x(e,4,this.length),r.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||x(e,8,this.length),r.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=1,s=0;for(this[t]=255&e;++s<r&&(i*=256);)this[t+s]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||U(this,e,t,r,Math.pow(2,8*r)-1,0);let i=r-1,s=1;for(this[t+i]=255&e;--i>=0&&(s*=256);)this[t+i]=e/s&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=J((function(e,t=0){return O(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=J((function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=0,s=1,o=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===o&&0!==this[t+i-1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);U(this,e,t,r,n-1,-n)}let i=r-1,s=1,o=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===o&&0!==this[t+i+1]&&(o=1),this[t+i]=(e/s|0)-o&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=J((function(e,t=0){return O(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=J((function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,r){return N(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return N(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return M(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return M(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<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),e.length-t<n-r&&(n=e.length-t+r);const i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=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===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};const P={};function D(e,t,r){P[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function $(e){let t="",r=e.length;const n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,i,s){if(e>r||e<t){const r="bigint"==typeof t?"n":"";let n;throw n=0===t||t===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,e)}!function(e,t,r){H(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||j(t,e.length-(r+1))}(n,i,s)}function H(e,t){if("number"!=typeof e)throw new P.ERR_INVALID_ARG_TYPE(t,"number",e)}function j(e,t,r){if(Math.floor(e)!==e)throw H(e,r),new P.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),D("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" 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 ${t}. Received ${i}`,n}),RangeError);const z=/[^+/0-9A-Za-z-_]/g;function G(e,t){let r;t=t||1/0;const n=e.length;let i=null;const s=[];for(let o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=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((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function W(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function V(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function q(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function J(e){return"undefined"==typeof BigInt?X:e}function X(){throw new Error("BigInt not supported")}}(Je);let ot={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 e in ot)ot[ot[e]]=e;const at={AUTH_REQ:Ye.meta(Ye.MB("header","8",0),Ye.MB("reserved","8",0)),AUTH_NONCE:Ye.meta(Ye.MB("header","8",0),Ye.MB("unixTime","32L",0),Ye.MB("milTime","32L",0),Ye.MB("nonce",Je.Buffer.alloc(4))),AUTH_HMAC:Ye.meta(Ye.MB("header","8",0),Ye.MB("id8",Je.Buffer.alloc(8)),Ye.MB("nonce",Je.Buffer.alloc(4)),Ye.MB("hmac32",Je.Buffer.alloc(32))),AUTH_ACK:Ye.meta(Ye.MB("header","8",0),Ye.MB("hmac32",Je.Buffer.alloc(32))),ENC_PACK:Ye.meta(Ye.MB("type","8",0),Ye.MB("len","32L",0),Ye.MB("salt12",Je.Buffer.alloc(12)),Ye.MB("hmac",8,0)),ENC_488:Ye.meta(Ye.MB("type","8",0),Ye.MB("len","32L",0),Ye.MB("otpSrc8",Je.Buffer.alloc(8)),Ye.MB("hmac8",Je.Buffer.alloc(8)))};function ht(e){let t=e[e.length-1];return t[2]+t[3]}const ft={AUTH_REQ:ht(at.AUTH_REQ),AUTH_NONCE:ht(at.AUTH_NONCE),AUTH_HMAC:ht(at.AUTH_HMAC),AUTH_ACK:ht(at.AUTH_ACK),ENC_PACK:ht(at.ENC_PACK),ENC_488:ht(at.ENC_488)};function ct(e){return globalThis.crypto.getRandomValues(Je.Buffer.alloc(e))}class ut{constructor(){this._id8=Je.Buffer.alloc(8),this._otpSrc44=Je.Buffer.alloc(44),this._otp36=Je.Buffer.alloc(36),this._hmac=Je.Buffer.alloc(32),this.auth_salt12=Je.Buffer.alloc(12),this.localNonce=Je.Buffer.alloc(4),this.remoteNonce=Je.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(e){Ye.B8(Qe.hash(e)).copy(this._id8,0,0,8)}set_id8(e){let t=Ye.B8(e);this._id8.fill(0),t.copy(this._id8,0,0,8)}set_key(e){Ye.B8(Qe.hash(e)).copy(this._otpSrc44,0,0,32)}set_id_key(e){let t=e.indexOf(".");if(-1==t)return;let r=e.substring(0,t),n=e.substring(t+1);this.set_id8(r),this.set_key(n)}copy_id8(e){e.copy(this._id8,0,0,8)}copy_key(e){e.copy(this._otpSrc44,0,0,32)}sha256_n(e,t){let r=Qe.hash(e);for(let e=0;e<t;e++)r=Qe.hash(r);return r}set_clock_rand(){let e=Date.now(),t=parseInt(e/1e3);e%=4294967295,Je.Buffer.concat([Ye.NB("32L",t),Ye.NB("32L",e),ct(4)]).copy(this._otpSrc44,32)}set_clock_nonce(e){let t=Date.now(),r=parseInt(t/1e3);t%=4294967295,Je.Buffer.concat([Ye.NB("32L",r),Ye.NB("32L",t),e]).copy(this._otpSrc44,32)}set_salt12(e){e.copy(this._otpSrc44,32)}resetOTP(){Ye.B8(Qe.hash(this._otpSrc44)).copy(this._otp36,0,0,32)}getIndexOTP(e){return this._otp36.writeUInt32LE(e,32),Qe.hash(this._otp36)}generateHMAC(e){let t=Je.Buffer.concat([this._otpSrc44,e]);this._hmac=Ye.B8(Qe.hash(t))}getHMAC8(e){let t=Je.Buffer.concat([this._otpSrc44,e]);return this._hmac=Ye.B8(Qe.hash(t)),this._hmac.subarray(0,8)}xotp(e,t=0,r=!1){let n=(e=Ye.B8(e,r)).byteLength,i=t,s=0,o=0;for(;n>0;){o=n<32?n:32;let t=this.getIndexOTP(++i);for(let r=0;r<o;r++)e[s++]^=t[r];n-=32}return e}auth_req(){return Ye.pack(Ye.MB("#type","8",ot.AUTH_REQ),Ye.MB("#reserved","8",0))}auth_nonce(){let e=Date.now(),t=Math.floor(e/1e3),r=e%1e3;return this.localNonce=ct(4),this.auth_salt12=Je.Buffer.concat([Ye.NB("32L",t),Ye.NB("32L",r),this.localNonce]),Je.Buffer.concat([Ye.NB("8",ot.AUTH_NONCE),this.auth_salt12])}auth_hmac(e){let t=Ye.unpack(e,at.AUTH_NONCE);if(t){let e=Je.Buffer.concat([Ye.NB("32L",t.unixTime),Ye.NB("32L",t.milTime),t.nonce]);return this.set_salt12(e),this.localNonce=ct(4),this.generateHMAC(this.localNonce),this.remoteNonce=t.nonce,Ye.pack(Ye.MB("#header","8",ot.AUTH_HMAC),Ye.MB("#id8",this._id8),Ye.MB("#nonce",this.localNonce),Ye.MB("#hmac32",this._hmac))}return!1}check_auth_hmac(e){let t;if(e instanceof Uint8Array){if(t=Ye.unpack(e,at.AUTH_HMAC),!t)return}else t=e;this.set_salt12(this.auth_salt12),this.generateHMAC(t.nonce);let r=this._hmac;if(Ye.equal(t.hmac32,r)){this.remoteNonce=t.nonce;let e=Je.Buffer.concat([this.localNonce,this.remoteNonce,this.localNonce]);this.set_salt12(e),this.generateHMAC(t.nonce);let r=this._hmac,n=Ye.rawPack(Ye.MB("header","8",ot.AUTH_ACK),Ye.MB("hmac32",r));return this.isAuthorized=!0,n}return!1}check_auth_ack_hmac(e){let t=Ye.unpack(e,at.AUTH_ACK);if(t){let e=Je.Buffer.concat([this.remoteNonce,this.localNonce,this.remoteNonce]);this.set_salt12(e),this.generateHMAC(this.localNonce);let r=this._hmac;if(Ye.equal(r,t.hmac32))return this.isAuthorized=!0,!0}}encrypt_488(e){if(!this.isAuthorized)return;e=Ye.B8(e),this.set_clock_nonce(this.remoteNonce),this.resetOTP();let t=this.getHMAC8(e),r=this.xotp(e);return Ye.pack(Ye.MB("#type","8",ot.ENC_488),Ye.MB("#len","32L",e.byteLength),Ye.MB("#otpSrc8",this._otpSrc44.subarray(32,40)),Ye.MB("#hmac8",t),Ye.MB("#xdata",r))}decrypt_488(e){e=Ye.B8(e);let t=Ye.unpack(e,at.ENC_488);if(t){let e=Je.Buffer.concat([t.otpSrc8,this.localNonce]);this.set_salt12(e),this.resetOTP();let r=t.$OTHERS.subarray(0,t.len),n=this.xotp(r),i=this.getHMAC8(n);if(Ye.equal(i,t.hmac8))return n}}encryptPack(e){e=Ye.B8(e),this.set_clock_rand(),this.resetOTP();let t=this.getHMAC8(e),r=this.xotp(e);return Ye.pack(Ye.MB("#type","8",ot.ENC_PACK),Ye.MB("#len","32L",e.byteLength),Ye.MB("#salt12",this._otpSrc44.subarray(32)),Ye.MB("#hmac8",t),Ye.MB("#xdata",r))}decryptPack(e){if(e[0]===ot.ENC_PACK&&e.readUint32LE(1)==e.byteLength-ft.ENC_PACK)try{let t=Ye.unpack(e,at.ENC_PACK);if(!t)return;this.set_salt12(t.salt12),this.resetOTP();let r=t.$OTHERS,n=this.xotp(r),i=this.getHMAC8(n);if(Ye.equal(t.hmac,i))return t.data=n,t}catch(e){}}encrypt_e2e(e,t){let r=Je.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(t);let n=this.encryptPack(e);return this._otpSrc44.set(r),n}decrypt_e2e(e,t){let r=Je.Buffer.alloc(32);r.set(this._otpSrc44.subarray(0,32)),this.set_key(t);let n=this.decryptPack(e);return this._otpSrc44.set(r),n}}ut.RAND=ct,ut.BohoMsg=ot,ut.Meta=at,ut.MetaSize=ft,ut.sha256=Qe,ut.MBP=Ye,ut.Buffer=Je.Buffer;const lt=q.Buffer,pt=new TextEncoder,dt=new TextDecoder;class gt extends K{constructor(e){super(),this.cid="",this.ip="",this.socket=null,this.url=e,this.state=Z.CLOSED,this.stateName=this.getStateName(),this.txCounter=0,this.rxCounter=0,this.txBytes=0,this.rxBytes=0,this.lastTxRxTime=Date.now(),this.connectionCheckerPeriod=re.CONNECTION_CHECKER_PERIOD,this.connectionCheckerIntervalID=null,this.boho=new ut,this.TLS=!1,this.encMode=te.AUTO,this.useAuth=!1,this.nick="",this.channels=new Set,this.promiseMap=new Map,this.promiseTimeOut=re.PROMISE_TIMEOUT,this.mid=0,this.level=3,this.quota=se[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(e){this.close(),this.stateChange("redirecting"),this.createConnection(e)}open(e){if(e||this.url){if(e)if(this.url){if(e!==this.url&&(this.url=e,this.socket))return void this.close()}else this.url=e;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(e,t){if(!e&&!t)return void console.log("no id and key.");if(console.log("manual login: ",e),!t&&e.includes("."))this.boho.set_id_key(e);else{if(!e||!t)return void console.log("no id or key.");this.boho.set_id8(e),this.boho.set_key(t)}this.useAuth=!0;let r=this.boho.auth_req();this.send(r)}auth(e,t){if(e||t){if(!t&&e.includes("."))this.boho.set_id_key(e);else{if(!e||!t)return void console.log("no id or key.");this.boho.set_id8(e),this.boho.set_key(t)}this.useAuth=!0}else console.log("no id and key.")}onData(e){let t,r=e[0];if(r===ut.BohoMsg.ENC_488)t=this.boho.decrypt_488(e),t&&(r=t[0],e=t);else if(r===ut.BohoMsg.ENC_E2E)try{if(t=this.boho.decrypt_488(e),!t)return;r=t[0],e.set(t,ut.MetaSize.ENC_488),e=e.subarray(ut.MetaSize.ENC_488)}catch(e){return}let n=ie[r];switch(n||(n=ut.BohoMsg[r]),r){case ie.OVER_SIZE:console.log("## server sent: over_size event."),this.emit("over_size","over_size");break;case ie.PING:this.pong();break;case ie.PONG:break;case ie.IAM_RES:try{let t=dt.decode(e.subarray(1)),r=JSON.parse(t);r.ip&&(this.ip=r.ip),console.log("<IAM_RES>",JSON.stringify(r))}catch(e){}break;case ie.CID_RES:let r=dt.decode(e.subarray(1));this.cid=r,this.stateChange("ready","cid_ready"),this.subscribe_memory_channels();break;case ie.QUOTA_LEVEL:let n=e[1];this.level=n,this.quota=se[n],console.log("## QUOTA:",n,JSON.stringify(this.quota));break;case ie.SERVER_CLEAR_AUTH:this.useAuth=!1,this.boho.clearAuth(),this.stop();break;case ie.SERVER_REDIRECT:let i,s,o;7==e.byteLength?(i=function(e){if(6!=e.byteLength)return;return e[0].toString()+"."+e[1].toString()+"."+e[2].toString()+"."+e[3].toString()+":"+((e[4]<<8)+e[5]).toString()}(e.subarray(1)),o="cong://"):(i=dt.decode(e.subarray(1)),o=""),s=o+i,this.redirect(s);break;case ie.SERVER_READY:this.stateChange("server_ready","server_ready"),this.useAuth?this.send(this.boho.auth_req()):this.send(lt.from([ie.CID_REQ]));break;case ie.SERVER_SIGNAL:try{let t=dt.decode(e.subarray(1)),r=JSON.parse(t);r.event&&r.data&&(this.serverSet=r.data,this.emit(r.event,r.data))}catch(e){}break;case ie.SET:try{let t=q.unpack(e);t&&this.emit(t.topic,...t.args)}catch(e){}break;case ie.SIGNAL_E2E:case ie.SIGNAL:try{let t=e.readUint8(1),r=e.subarray(2,2+t),n=dt.decode(r),i=e.readUint8(2+t),s=e.subarray(3+t);switch(i){case ne.EMPTY:0===n.indexOf("@")?this.emit("@",null,n):this.emit(n,null,n);break;case ne.TEXT:let e=s.subarray(0,s.byteLength-1),t=dt.decode(e);0===n.indexOf("@")&&this.emit("@",t,n),"@"!==n&&this.emit(n,t,n);break;case ne.BINARY:0===n.indexOf("@")&&this.emit("@",s,n),"@"!==n&&this.emit(n,s,n);break;case ne.OBJECT:let r=dt.decode(s),i=JSON.parse(r);0===n.indexOf("@")&&this.emit("@",i,n),"@"!==n&&this.emit(n,i,n);break;case ne.MJSON:let o=dt.decode(s),a=JSON.parse(o);0===n.indexOf("@")&&this.emit("@",...a,n),"@"!==n&&this.emit(n,...a,n);break;case ne.MBA:let h=q.unpack(s);0===n.indexOf("@")&&this.emit("@",...h.args,n),"@"!==n&&this.emit(n,...h.args,n)}}catch(e){}break;case ie.RESPONSE_MBP:this.testPromise(e);break;case ut.BohoMsg.AUTH_NONCE:let a=this.boho.auth_hmac(e);a?this.send(a):this.stateChange("auth_fail","Invalid local auth_hmac.");break;case ut.BohoMsg.AUTH_FAIL:this.stateChange("auth_fail","server reject auth.");break;case ut.BohoMsg.AUTH_ACK:this.boho.check_auth_ack_hmac(e)?(this.stateChange("auth_ready","server sent auth_ack"),this.send(lt.from([ie.CID_REQ]))):this.stateChange("auth_fail","invalid server_hmac");break;default:try{t=dt.decode(e),this.emit("text_message",t)}catch(e){}}}iam(e){e?this.send_enc_mode(q.pack(q.MB("#MsgType","8",ie.IAM),q.MB("#",e))):this.send_enc_mode(q.pack(q.MB("#MsgType","8",ie.IAM)))}ping(){this.send(lt.from([ie.PING]))}pong(){this.send(lt.from([ie.PONG]))}echo(e){e?(console.log("echo args:",e),this.send_enc_mode(q.pack(q.MB("#MsgType","8",ie.ECHO),q.MB("#msg",e)))):this.send(lt.from([ie.ECHO]))}bin(...e){this.send(q.U8pack(...e))}send(e){if(e.byteLength>this.quota.signalSize)return this.emit("over_size"),console.log("## QUOTA LIMIT OVER!! \nsignal message.byteLength: ",e.byteLength),void console.log("## your maximum signalSize(bytes) is:",this.quota.signalSize);this.socket_send(e)}getEncryptionMode(){return!(this.encMode!==te.YES&&(this.encMode!==te.AUTO||this.TLS||!this.boho.isAuthorized))}send_enc_mode(e,t){if(void 0===t&&(t=this.getEncryptionMode()),e[0]==ie.SIGNAL_E2E&&t){let t=e[1],r=this.boho.encrypt_488(e.subarray(0,3+t));r[0]=ut.BohoMsg.ENC_E2E,this.send(lt.concat([r,e.subarray(3+t)]))}else if(t){let t=this.boho.encrypt_488(e);this.send(t)}else this.send(e)}setMsgPromise(e){return new Promise(((t,r)=>{this.promiseMap.set(e,[t,r]),setTimeout((t=>{this.promiseMap.has(e)&&(r("timeout"),this.promiseMap.delete(e))}),this.promiseTimeOut)}))}testPromise(e){let t=q.unpack(e);if(t)if(this.promiseMap.has(t.mid)){let[e,r]=this.promiseMap.get(t.mid);this.promiseMap.delete(t.mid),t.status<128?(t.ok=!0,e(t)):(t.ok=!1,r(t))}else console.log("no promise id")}publish(...e){this.signal(...e)}signal(e,...t){if("string"!=typeof e)throw TypeError("tag should be string.");let r=ae(e,...t);this.send_enc_mode(r)}decrypt_e2e(e,t){return this.boho.decrypt_e2e(e,t)}signal_e2e(e,t,r){if("string"!=typeof e)throw TypeError("tag should be string.");let n=pt.encode(e),i=q.B8(t),s=this.boho.encrypt_e2e(i,r),o=q.pack(q.MB("#MsgType","8",ie.SIGNAL_E2E),q.MB("#tagLen","8",n.byteLength),q.MB("#tag",n),q.MB("#payloadType","8",ne.BINARY),q.MB("#payload",s));this.send_enc_mode(o)}set(e,...t){return e&&0!=t.length?this.req("store","set",e,...t):Promise.reject(new Error("set need storeName and value)"))}async get(e){if(!e)return Promise.reject(new Error("store get need storeName)"));let t=await this.req("store","get",e),{$:r}=q.unpack(t.body);return r}req(e,t,...r){if(!e||!t)return Promise.reject(new Error("request need target and topic)"));let n;return n=r.length>0?q.pack(q.MB("#MsgType","8",ie.REQUEST),q.MB("mid","16",++this.mid),q.MB("target",e),q.MB("topic",t),q.MBA(...r)):q.pack(q.MB("#MsgType","8",ie.REQUEST),q.MB("mid","16",++this.mid),q.MB("target",e),q.MB("topic",t)),this.send_enc_mode(n),this.setMsgPromise(this.mid)}subscribe(e){if("string"!=typeof e)throw TypeError("tag should be string.");if(this.state!==Z.READY)return;e.split(",").forEach((e=>{this.channels.add(e)}));let t=pt.encode(e);if(t.byteLength>re.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+re.TAG_LEN1);this.send_enc_mode(lt.concat([q.NB("8",ie.SUBSCRIBE),q.NB("8",t.byteLength),t]))}subscribe_promise(e){if("string"!=typeof e)throw TypeError("tag should be string.");if(this.state!==Z.READY)return Promise.reject("subscribe_promise:: connection is not ready");let t=pt.encode(e);if(t.byteLength>re.TAG_LEN2)throw TypeError("please use tag string bytelength: "+re.TAG_LEN2);return this.send_enc_mode(lt.concat([q.NB("8",ie.SUBSCRIBE_REQ),q.NB("16",++this.mid),q.NB("16",t.byteLength),t])),this.setMsgPromise(this.mid)}subscribe_memory_channels(){if(0==this.channels.size)return;let e=Array.from(this.channels).join(",");this.subscribe_promise(e).then((e=>{})).catch((e=>{console.log(">> SUBSCRIBE FAIL:",e)}))}unsubscribe(e=""){if("string"!=typeof e)throw TypeError("tag should be string.");if(""==e)this.channels.clear();else{e.split(",").forEach((e=>{this.channels.delete(e)}))}let t=pt.encode(e);if(t.byteLength>re.TAG_LEN1)throw TypeError("please use tag string bytelength below:"+re.TAG_LEN1);this.send_enc_mode(lt.concat([q.NB("8",ie.UNSUBSCRIBE),q.NB("8",t.byteLength),t]))}listen(e,t){if("string"!=typeof e)throw TypeError("tag should be string.");if(e.length>255||0==e.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof t)throw TypeError("handler is not a function.");0!==e.indexOf("@")&&this.channels.add(e),this.on(e,t)}link(e,t,r){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if("string"!=typeof t)throw TypeError("tag is not a string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if("function"!=typeof r)throw TypeError("handler is not a function.");let n;0!==t.indexOf("@")&&this.channels.add(t),n=this.linkMap.has(e)?this.linkMap.get(e):new Set,n.add(t),this.linkMap.set(e,n),this.on(t,r),this.subscribe(t)}unlink(e,t){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if("string"!=typeof t)throw TypeError("tag is not a string.");if(t.length>255||0==t.length)throw TypeError("tag string length range: 1~255");if(!this.linkMap.has(e))return;let r=this.linkMap.get(e),n=Array.from(r);for(let i=0;i<n.length;i++)if(n[i]==t){this.unsubscribe(t),this.removeAllListeners(t),r.delete(t),this.linkMap.set(e,r);break}}unlinkAll(e){if("string"!=typeof e)throw TypeError("to(local link target) is not a string.");if(!this.linkMap.has(e))return;let t=this.linkMap.get(e),r=Array.from(t);for(let e=0;e<r.length;e++)this.unsubscribe(r[e]),this.removeAllListeners(r[e]),t.delete(r[e]);this.linkMap.delete(e)}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 Z[this.state].toLowerCase()}getSecurity(){return{useAuth:this.useAuth,isTLS:this.TLS,isAuthorized:this.boho.isAuthorized,encMode:this.encMode,usingEncryption:this.getEncryptionMode()}}stateChange(e,t){let r=e.toLowerCase();this.state=Z[e.toUpperCase()],t&&this.emit(r,t),this.stateName!==r&&(this.stateName=r,this.emit("change",r))}}const yt=1,mt=2,_t=3,bt=4;function wt(e){if(e.byteLength<256)return q.pack(q.MB("#type","8",yt),q.MB("#payloadLen1","8",e.byteLength),q.MB("#payload",e));if(e.byteLength<65536)return q.pack(q.MB("#type","8",mt),q.MB("#payloadLen2","16L",e.byteLength),q.MB("#payload",e));if(e.byteLength<2**24){let t=Buffer.alloc(4);t.writeUint32LE(e.byteLength);let r=t.subarray(0,3);return q.pack(q.MB("#type","8",_t),q.MB("#payloadLen3",r),q.MB("#payload",e))}return q.pack(q.MB("#type","8",bt),q.MB("#payloadLen4","32L",e.byteLength),q.MB("#payload",e))}class Et extends n.Transform{constructor(e){super(e),this.buffer=Buffer.alloc(0),this.frames=[],this.rxi=0,this.rxi_zero=0}_transform(e,t,r){this.addData(e),this.frames.length>0&&(this.frames.forEach((e=>{this.push(e)})),this.frames=[]),r()}addData(e){let t=e.byteLength,r=0;for(;t--;)this.rxi++,0==e[r++]&&this.rxi_zero++;this.buffer.byteLength>0?this.buffer=Buffer.concat([this.buffer,e]):this.buffer=e,this.parse()}parse(){let e,t,r=this.buffer[0];if(r==yt){if(e=2,this.buffer.byteLength<e)return;t=this.buffer.readUint8(1)}else if(r==mt){if(e=3,this.buffer.byteLength<e)return;t=this.buffer.readUint16LE(1)}else if(r==_t){if(e=4,this.buffer.byteLength<e)return;t=this.buffer.readUint16LE(1)+65536*this.buffer.readUint8(3)}else if(r==bt){if(e=5,this.buffer.byteLength<e)return;t=this.buffer.readUint32LE(1)}else this.emit("wrong",this.buffer),this.buffer=Buffer.alloc(0);if(t==this.buffer.byteLength-e)return this.frames.push(this.buffer.subarray(e)),void(this.buffer=Buffer.alloc(0));t<this.buffer.byteLength-e&&(this.frames.push(this.buffer.subarray(e,e+t)),this.buffer=this.buffer.subarray(e+t),this.parse())}}var Bt,vt,St={exports:{}};function At(){if(vt)return Bt;vt=1;const e=["nodebuffer","arraybuffer","fragments"],t="undefined"!=typeof Blob;return t&&e.push("blob"),Bt={BINARY_TYPES:e,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:t,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}}var kt={exports:{}};function Lt(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Tt,It,xt,Ut,Ot,Ct,Rt,Nt,Mt,Pt,Dt,$t={exports:{}};function Ft(){if(xt)return $t.exports;xt=1;const e="function"==typeof __webpack_require__?__non_webpack_require__:Lt;return"function"==typeof e.addon?$t.exports=e.addon.bind(e):$t.exports=function(){if(It)return Tt;It=1;var e=l,t=p,r=d,n="function"==typeof __webpack_require__?__non_webpack_require__:Lt,i=process.config&&process.config.variables||{},s=!!process.env.PREBUILDS_ONLY,o=process.versions.modules,a=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",h=process.env.npm_config_arch||r.arch(),f=process.env.npm_config_platform||r.platform(),c=process.env.LIBC||(function(t){return"linux"===t&&e.existsSync("/etc/alpine-release")}(f)?"musl":"glibc"),u=process.env.ARM_VERSION||("arm64"===h?"8":i.arm_version)||"",g=(process.versions.uv||"").split(".")[0];function y(e){return n(y.resolve(e))}function m(t){try{return e.readdirSync(t)}catch(e){return[]}}function _(e,r){var n=m(e).filter(r);return n[0]&&t.join(e,n[0])}function b(e){return/\.node$/.test(e)}function w(e){var t=e.split("-");if(2===t.length){var r=t[0],n=t[1].split("+");if(r&&n.length&&n.every(Boolean))return{name:e,platform:r,architectures:n}}}function E(e,t){return function(r){return null!=r&&r.platform===e&&r.architectures.includes(t)}}function B(e,t){return e.architectures.length-t.architectures.length}function v(e){var t=e.split("."),r={file:e,specificity:0};if("node"===t.pop()){for(var n=0;n<t.length;n++){var i=t[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(e,t){return function(r){return!(null==r||r.runtime&&r.runtime!==e&&!function(e){return"node"===e.runtime&&e.napi}(r)||r.abi&&r.abi!==t&&!r.napi||r.uv&&r.uv!==g||r.armv&&r.armv!==u||r.libc&&r.libc!==c)}}function A(e){return function(t,r){return t.runtime!==r.runtime?t.runtime===e?-1:1:t.abi!==r.abi?t.abi?-1:1:t.specificity!==r.specificity?t.specificity>r.specificity?-1:1:0}}return Tt=y,y.resolve=y.path=function(e){e=t.resolve(e||".");try{var r=n(t.join(e,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[r+"_PREBUILD"]&&(e=process.env[r+"_PREBUILD"])}catch(e){}if(!s){var i=_(t.join(e,"build/Release"),b);if(i)return i;var l=_(t.join(e,"build/Debug"),b);if(l)return l}var p=k(e);if(p)return p;var d=k(t.dirname(process.execPath));if(d)return d;var y=["platform="+f,"arch="+h,"runtime="+a,"abi="+o,"uv="+g,u?"armv="+u:"","libc="+c,"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: "+e+"\n");function k(e){var r=m(t.join(e,"prebuilds")).map(w).filter(E(f,h)).sort(B)[0];if(r){var n=t.join(e,"prebuilds",r.name),i=m(n).map(v).filter(S(a,o)).sort(A(a))[0];return i?t.join(n,i.file):void 0}}},y.parseTags=v,y.matchTags=S,y.compareTags=A,y.parseTuple=w,y.matchTuple=E,y.compareTuples=B,Tt}(),$t.exports}function Ht(){if(Ct)return kt.exports;Ct=1;try{kt.exports=Ft()(__dirname)}catch(e){kt.exports=(Ot||(Ot=1,Ut={mask:(e,t,r,n,i)=>{for(var s=0;s<i;s++)r[n+s]=e[s]^t[3&s]},unmask:(e,t)=>{const r=e.length;for(var n=0;n<r;n++)e[n]^=t[3&n]}}),Ut)}return kt.exports}function jt(){if(Rt)return St.exports;Rt=1;const{EMPTY_BUFFER:e}=At(),t=Buffer[Symbol.species];function r(e,t,r,n,i){for(let s=0;s<i;s++)r[n+s]=e[s]^t[3&s]}function n(e,t){for(let r=0;r<e.length;r++)e[r]^=t[3&r]}if(St.exports={concat:function(r,n){if(0===r.length)return e;if(1===r.length)return r[0];const i=Buffer.allocUnsafe(n);let s=0;for(let e=0;e<r.length;e++){const t=r[e];i.set(t,s),s+=t.length}return s<n?new t(i.buffer,i.byteOffset,s):i},mask:r,toArrayBuffer:function(e){return e.length===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.length)},toBuffer:function e(r){if(e.readOnly=!0,Buffer.isBuffer(r))return r;let n;return r instanceof ArrayBuffer?n=new t(r):ArrayBuffer.isView(r)?n=new t(r.buffer,r.byteOffset,r.byteLength):(n=Buffer.from(r),e.readOnly=!1),n},unmask:n},!process.env.WS_NO_BUFFER_UTIL)try{const e=Ht();St.exports.mask=function(t,n,i,s,o){o<48?r(t,n,i,s,o):e.mask(t,n,i,s,o)},St.exports.unmask=function(t,r){t.length<32?n(t,r):e.unmask(t,r)}}catch(e){}return St.exports}function zt(){if(Dt)return Pt;Dt=1;const e=u,t=jt(),r=function(){if(Mt)return Nt;Mt=1;const e=Symbol("kDone"),t=Symbol("kRun");return Nt=class{constructor(r){this[e]=()=>{this.pending--,this[t]()},this.concurrency=r||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[t]()}[t](){if(this.pending!==this.concurrency&&this.jobs.length){const t=this.jobs.shift();this.pending++,t(this[e])}}}}(),{kStatusCode:n}=At(),i=Buffer[Symbol.species],s=Buffer.from([0,0,255,255]),o=Symbol("permessage-deflate"),a=Symbol("total-length"),h=Symbol("callback"),f=Symbol("buffers"),c=Symbol("error");let l;function p(e){this[f].push(e),this[a]+=e.length}function d(e){this[a]+=e.length,this[o]._maxPayload<1||this[a]<=this[o]._maxPayload?this[f].push(e):(this[c]=new RangeError("Max payload size exceeded"),this[c].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[c][n]=1009,this.removeListener("data",d),this.reset())}function g(e){this[o]._inflate=null,e[n]=1007,this[h](e)}return Pt=class{constructor(e,t,n){if(this._maxPayload=0|n,this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!t,this._deflate=null,this._inflate=null,this.params=null,!l){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;l=new r(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[h];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,r=e.find((e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&!e.client_max_window_bits)));if(!r)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(r.server_no_context_takeover=!0),t.clientNoContextTakeover&&(r.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(r.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?r.client_max_window_bits=t.clientMaxWindowBits:!0!==r.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete r.client_max_window_bits,r}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach((e=>{Object.keys(e).forEach((t=>{let r=e[t];if(r.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(r=r[0],"client_max_window_bits"===t){if(!0!==r){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}else if("server_max_window_bits"===t){const e=+r;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${r}`);r=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==r)throw new TypeError(`Invalid value for parameter "${t}": ${r}`)}e[t]=r}))})),e}decompress(e,t,r){l.add((n=>{this._decompress(e,t,((e,t)=>{n(),r(e,t)}))}))}compress(e,t,r){l.add((n=>{this._compress(e,t,((e,t)=>{n(),r(e,t)}))}))}_decompress(r,n,i){const u=this._isServer?"client":"server";if(!this._inflate){const t=`${u}_max_window_bits`,r="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._inflate=e.createInflateRaw({...this._options.zlibInflateOptions,windowBits:r}),this._inflate[o]=this,this._inflate[a]=0,this._inflate[f]=[],this._inflate.on("error",g),this._inflate.on("data",d)}this._inflate[h]=i,this._inflate.write(r),n&&this._inflate.write(s),this._inflate.flush((()=>{const e=this._inflate[c];if(e)return this._inflate.close(),this._inflate=null,void i(e);const r=t.concat(this._inflate[f],this._inflate[a]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[a]=0,this._inflate[f]=[],n&&this.params[`${u}_no_context_takeover`]&&this._inflate.reset()),i(null,r)}))}_compress(r,n,s){const o=this._isServer?"server":"client";if(!this._deflate){const t=`${o}_max_window_bits`,r="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._deflate=e.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:r}),this._deflate[a]=0,this._deflate[f]=[],this._deflate.on("data",p)}this._deflate[h]=s,this._deflate.write(r),this._deflate.flush(e.Z_SYNC_FLUSH,(()=>{if(!this._deflate)return;let e=t.concat(this._deflate[f],this._deflate[a]);n&&(e=new i(e.buffer,e.byteOffset,e.length-4)),this._deflate[h]=null,this._deflate[a]=0,this._deflate[f]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),s(null,e)}))}}}var Gt,Wt,Vt,qt,Yt,Qt,Jt,Xt,Kt,Zt,er,tr,rr,nr,ir,sr,or={exports:{}},ar={exports:{}};function hr(){if(Vt)return ar.exports;Vt=1;try{ar.exports=Ft()(__dirname)}catch(e){ar.exports=(Wt||(Wt=1,Gt=function(e){const t=e.length;let r=0;for(;r<t;)if(128&e[r])if(192==(224&e[r])){if(r+1===t||128!=(192&e[r+1])||192==(254&e[r]))return!1;r+=2}else if(224==(240&e[r])){if(r+2>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||224===e[r]&&128==(224&e[r+1])||237===e[r]&&160==(224&e[r+1]))return!1;r+=3}else{if(240!=(248&e[r]))return!1;if(r+3>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||128!=(192&e[r+3])||240===e[r]&&128==(240&e[r+1])||244===e[r]&&e[r+1]>143||e[r]>244)return!1;r+=4}else r++;return!0}),Gt)}return ar.exports}function fr(){if(qt)return or.exports;qt=1;const{isUtf8:e}=g,{hasBlob:t}=At();function r(e){const t=e.length;let r=0;for(;r<t;)if(128&e[r])if(192==(224&e[r])){if(r+1===t||128!=(192&e[r+1])||192==(254&e[r]))return!1;r+=2}else if(224==(240&e[r])){if(r+2>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||224===e[r]&&128==(224&e[r+1])||237===e[r]&&160==(224&e[r+1]))return!1;r+=3}else{if(240!=(248&e[r]))return!1;if(r+3>=t||128!=(192&e[r+1])||128!=(192&e[r+2])||128!=(192&e[r+3])||240===e[r]&&128==(240&e[r+1])||244===e[r]&&e[r+1]>143||e[r]>244)return!1;r+=4}else r++;return!0}if(or.exports={isBlob:function(e){return t&&"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&("Blob"===e[Symbol.toStringTag]||"File"===e[Symbol.toStringTag])},isValidStatusCode:function(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=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]},e)or.exports.isValidUTF8=function(t){return t.length<24?r(t):e(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{const e=hr();or.exports.isValidUTF8=function(t){return t.length<32?r(t):e(t)}}catch(e){}return or.exports}function cr(){if(Qt)return Yt;Qt=1;const{Writable:e}=n,t=zt(),{BINARY_TYPES:r,EMPTY_BUFFER:i,kStatusCode:s,kWebSocket:o}=At(),{concat:a,toArrayBuffer:h,unmask:f}=jt(),{isValidStatusCode:c,isValidUTF8:u}=fr(),l=Buffer[Symbol.species];return Yt=class extends e{constructor(e={}){super(),this._allowSynchronousEvents=void 0===e.allowSynchronousEvents||e.allowSynchronousEvents,this._binaryType=e.binaryType||r[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=0|e.maxPayload,this._skipUTF8Validation=!!e.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(e,t,r){if(8===this._opcode&&0==this._state)return r();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];return this._buffers[0]=new l(t.buffer,t.byteOffset+e,t.length-e),new l(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const r=this._buffers[0],n=t.length-e;e>=r.length?t.set(this._buffers.shift(),n):(t.set(new Uint8Array(r.buffer,r.byteOffset,e),n),this._buffers[0]=new l(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return t}startLoop(e){this._loop=!0;do{switch(this._state){case 0:this.getInfo(e);break;case 1:this.getPayloadLength16(e);break;case 2:this.getPayloadLength64(e);break;case 3:this.getMask();break;case 4:this.getData(e);break;case 5:case 6:return void(this._loop=!1)}}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2)return void(this._loop=!1);const r=this.consume(2);if(48&r[0]){return void e(this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3"))}const n=!(64&~r[0]);if(!n||this._extensions[t.extensionName]){if(this._fin=!(128&~r[0]),this._opcode=15&r[0],this._payloadLength=127&r[1],0===this._opcode){if(n){return void e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}if(!this._fragmented){return void e(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 e(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 e(this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE"))}if(!this._fin){return void e(this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN"))}if(n){return void e(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 e(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&~r[1]),this._isServer){if(!this._masked){return void e(this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK"))}}else if(this._masked){return void e(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(e)}else{e(this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1"))}}getPayloadLength16(e){this._bufferedBytes<2?this._loop=!1:(this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e))}getPayloadLength64(e){if(this._bufferedBytes<8)return void(this._loop=!1);const t=this.consume(8),r=t.readUInt32BE(0);if(r>Math.pow(2,21)-1){e(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)+t.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){e(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(e){let t=i;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);t=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&f(t,this._mask)}if(this._opcode>7)this.controlMessage(t,e);else{if(this._compressed)return this._state=5,void this.decompress(t,e);t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage(e)}}decompress(e,r){this._extensions[t.extensionName].decompress(e,this._fin,((e,t)=>{if(e)return r(e);if(t.length){if(this._messageLength+=t.length,this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");return void r(e)}this._fragments.push(t)}this.dataMessage(r),0===this._state&&this.startLoop(r)}))}dataMessage(e){if(!this._fin)return void(this._state=0);const t=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,t):"arraybuffer"===this._binaryType?h(a(r,t)):"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(e)})))}else{const n=a(r,t);if(!this._skipUTF8Validation&&!u(n)){const t=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void e(t)}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(e)})))}}controlMessage(e,t){if(8!==this._opcode)this._allowSynchronousEvents?(this.emit(9===this._opcode?"ping":"pong",e),this._state=0):(this._state=6,setImmediate((()=>{this.emit(9===this._opcode?"ping":"pong",e),this._state=0,this.startLoop(t)})));else{if(0===e.length)this._loop=!1,this.emit("conclude",1005,i),this.end();else{const r=e.readUInt16BE(0);if(!c(r)){const e=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");return void t(e)}const n=new l(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!u(n)){const e=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");return void t(e)}this._loop=!1,this.emit("conclude",r,n),this.end()}this._state=0}}createError(e,t,r,n,i){this._loop=!1,this._errored=!0;const o=new e(r?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(o,this.createError),o.code=i,o[s]=n,o}},Yt}function ur(){if(Xt)return Jt;Xt=1;const{Duplex:e}=n,{randomFillSync:t}=f,r=zt(),{EMPTY_BUFFER:i,kWebSocket:s,NOOP:o}=At(),{isBlob:a,isValidStatusCode:h}=fr(),{mask:c,toBuffer:u}=jt(),l=Symbol("kByteLength"),p=Buffer.alloc(4),d=8192;let g,y=d;class m{constructor(e,t,r){this._extensions=t||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=0,this.onerror=o,this[s]=void 0}static frame(e,r){let n,i,s=!1,o=2,a=!1;r.mask&&(n=r.maskBuffer||p,r.generateMask?r.generateMask(n):(y===d&&(void 0===g&&(g=Buffer.alloc(d)),t(g,0,d),y=0),n[0]=g[y++],n[1]=g[y++],n[2]=g[y++],n[3]=g[y++]),a=!(n[0]|n[1]|n[2]|n[3]),o=6),"string"==typeof e?i=r.mask&&!a||void 0===r[l]?(e=Buffer.from(e)).length:r[l]:(i=e.length,s=r.mask&&r.readOnly&&!a);let h=i;i>=65536?(o+=8,h=127):i>125&&(o+=2,h=126);const f=Buffer.allocUnsafe(s?i+o:o);return f[0]=r.fin?128|r.opcode:r.opcode,r.rsv1&&(f[0]|=64),f[1]=h,126===h?f.writeUInt16BE(i,2):127===h&&(f[2]=f[3]=0,f.writeUIntBE(i,4,6)),r.mask?(f[1]|=128,f[o-4]=n[0],f[o-3]=n[1],f[o-2]=n[2],f[o-1]=n[3],a?[f,e]:s?(c(e,n,f,o,i),[f]):(c(e,n,e,0,i),[f,e])):[f,e]}close(e,t,r,n){let s;if(void 0===e)s=i;else{if("number"!=typeof e||!h(e))throw new TypeError("First argument must be a valid error code number");if(void 0!==t&&t.length){const r=Buffer.byteLength(t);if(r>123)throw new RangeError("The message must not be greater than 123 bytes");s=Buffer.allocUnsafe(2+r),s.writeUInt16BE(e,0),"string"==typeof t?s.write(t,2):s.set(t,2)}else s=Buffer.allocUnsafe(2),s.writeUInt16BE(e,0)}const o={[l]:s.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};0!==this._state?this.enqueue([this.dispatch,s,!1,o,n]):this.sendFrame(m.frame(s,o),n)}ping(e,t,r){let n,i;if("string"==typeof e?(n=Buffer.byteLength(e),i=!1):a(e)?(n=e.size,i=!1):(n=(e=u(e)).length,i=u.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const s={[l]:n,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};a(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,s,r]):this.getBlobData(e,!1,s,r):0!==this._state?this.enqueue([this.dispatch,e,!1,s,r]):this.sendFrame(m.frame(e,s),r)}pong(e,t,r){let n,i;if("string"==typeof e?(n=Buffer.byteLength(e),i=!1):a(e)?(n=e.size,i=!1):(n=(e=u(e)).length,i=u.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");const s={[l]:n,fin:!0,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};a(e)?0!==this._state?this.enqueue([this.getBlobData,e,!1,s,r]):this.getBlobData(e,!1,s,r):0!==this._state?this.enqueue([this.dispatch,e,!1,s,r]):this.sendFrame(m.frame(e,s),r)}send(e,t,n){const i=this._extensions[r.extensionName];let s,o,h=t.binary?2:1,f=t.compress;"string"==typeof e?(s=Buffer.byteLength(e),o=!1):a(e)?(s=e.size,o=!1):(s=(e=u(e)).length,o=u.readOnly),this._firstFragment?(this._firstFragment=!1,f&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(f=s>=i._threshold),this._compress=f):(f=!1,h=0),t.fin&&(this._firstFragment=!0);const c={[l]:s,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:h,readOnly:o,rsv1:f};a(e)?0!==this._state?this.enqueue([this.getBlobData,e,this._compress,c,n]):this.getBlobData(e,this._compress,c,n):0!==this._state?this.enqueue([this.dispatch,e,this._compress,c,n]):this.dispatch(e,this._compress,c,n)}getBlobData(e,t,r,n){this._bufferedBytes+=r[l],this._state=2,e.arrayBuffer().then((e=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");return void process.nextTick(_,this,e,n)}this._bufferedBytes-=r[l];const i=u(e);t?this.dispatch(i,t,r,n):(this._state=0,this.sendFrame(m.frame(i,r),n),this.dequeue())})).catch((e=>{process.nextTick(b,this,e,n)}))}dispatch(e,t,n,i){if(!t)return void this.sendFrame(m.frame(e,n),i);const s=this._extensions[r.extensionName];this._bufferedBytes+=n[l],this._state=1,s.compress(e,n.fin,((e,t)=>{if(this._socket.destroyed){_(this,new Error("The socket was closed while data was being compressed"),i)}else this._bufferedBytes-=n[l],this._state=0,n.readOnly=!1,this.sendFrame(m.frame(t,n),i),this.dequeue()}))}dequeue(){for(;0===this._state&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[3][l],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][l],this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}}function _(e,t,r){"function"==typeof r&&r(t);for(let r=0;r<e._queue.length;r++){const n=e._queue[r],i=n[n.length-1];"function"==typeof i&&i(t)}}function b(e,t,r){_(e,t,r),e.onerror(t)}return Jt=m}function lr(){if(tr)return er;tr=1;const{tokenChars:e}=fr();function t(e,t,r){void 0===e[t]?e[t]=[r]:e[t].push(r)}return er={format:function(e){return Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>[t].concat(Object.keys(e).map((t=>{let r=e[t];return Array.isArray(r)||(r=[r]),r.map((e=>!0===e?t:`${t}=${e}`)).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===e[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 e=r.slice(c,l);44===u?(t(n,e,o),o=Object.create(null)):i=e,c=l=-1}}else-1===l&&-1!==c&&(l=p);else if(void 0===s)if(-1===l&&1===e[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),t(o,r.slice(c,l),!0),44===u&&(t(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!==e[u])throw new SyntaxError(`Unexpected character at index ${p}`);-1===c?c=p:a||(a=!0),h=!1}else if(f)if(1===e[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===e[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 e=r.slice(c,l);a&&(e=e.replace(/\\/g,""),a=!1),t(o,s,e),44===u&&(t(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?t(n,d,o):(void 0===s?t(o,d,!0):t(o,s,a?d.replace(/\\/g,""):d),t(n,i,o)),n}},er}function pr(){if(nr)return rr;nr=1;const e=s,t=o,r=a,u=i,l=h,{randomBytes:p,createHash:d}=f,{Duplex:g,Readable:y}=n,{URL:m}=c,_=zt(),b=cr(),w=ur(),{isBlob:E}=fr(),{BINARY_TYPES:B,EMPTY_BUFFER:v,GUID:S,kForOnEventAttribute:A,kListener:k,kStatusCode:L,kWebSocket:T,NOOP:I}=At(),{EventTarget:{addEventListener:x,removeEventListener:U}}=function(){if(Zt)return Kt;Zt=1;const{kForOnEventAttribute:e,kListener:t}=At(),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(e){this[a]=null,this[h]=e}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(e,t={}){super(e),this[r]=void 0===t.code?0:t.code,this[o]=void 0===t.reason?"":t.reason,this[f]=void 0!==t.wasClean&&t.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(e,t={}){super(e),this[i]=void 0===t.error?null:t.error,this[s]=void 0===t.message?"":t.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(e,t={}){super(e),this[n]=void 0===t.data?null:t.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[e]&&s[t]===n&&!s[e])return;let s;if("message"===r)s=function(e,t){const r=new p("message",{data:t?e:e.toString()});r[a]=this,g(n,this,r)};else if("close"===r)s=function(e,t){const r=new u("close",{code:e,reason:t.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[a]=this,g(n,this,r)};else if("error"===r)s=function(e){const t=new l("error",{error:e,message:e.message});t[a]=this,g(n,this,t)};else{if("open"!==r)return;s=function(){const e=new c("open");e[a]=this,g(n,this,e)}}s[e]=!!i[e],s[t]=n,i.once?this.once(r,s):this.on(r,s)},removeEventListener(r,n){for(const i of this.listeners(r))if(i[t]===n&&!i[e]){this.removeListener(r,i);break}}};function g(e,t,r){"object"==typeof e&&e.handleEvent?e.handleEvent.call(e,r):e.call(t,r)}return Kt={CloseEvent:u,ErrorEvent:l,Event:c,EventTarget:d,MessageEvent:p}}(),{format:O,parse:C}=lr(),{toBuffer:R}=jt(),N=3e4,M=Symbol("kAborted"),P=[8,13],D=["CONNECTING","OPEN","CLOSING","CLOSED"],$=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class F extends e{constructor(e,t,r){super(),this._binaryType=B[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=v,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=F.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==e?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,void 0===t?t=[]:Array.isArray(t)||("object"==typeof t&&null!==t?(r=t,t=[]):t=[t]),H(this,e,t,r)):(this._autoPong=r.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){B.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}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(e,t,r){const n=new b({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),i=new w(e,this._extensions,r.generateMask);this._receiver=n,this._sender=i,this._socket=e,n[T]=this,i[T]=this,e[T]=this,n.on("conclude",q),n.on("drain",Y),n.on("error",Q),n.on("message",X),n.on("ping",K),n.on("pong",Z),i.onerror=te,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),t.length>0&&e.unshift(t),e.on("close",ne),e.on("data",ie),e.on("end",se),e.on("error",oe),this._readyState=F.OPEN,this.emit("open")}emitClose(){if(!this._socket)return this._readyState=F.CLOSED,void this.emit("close",this._closeCode,this._closeMessage);this._extensions[_.extensionName]&&this._extensions[_.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=F.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState!==F.CLOSED)if(this.readyState!==F.CONNECTING)this.readyState!==F.CLOSING?(this._readyState=F.CLOSING,this._sender.close(e,t,!this._isServer,(e=>{e||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())})),re(this)):this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();else{const e="WebSocket was closed before the connection was established";W(this,this._req,e)}}pause(){this.readyState!==F.CONNECTING&&this.readyState!==F.CLOSED&&(this._paused=!0,this._socket.pause())}ping(e,t,r){if(this.readyState===F.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(r=e,e=t=void 0):"function"==typeof t&&(r=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===F.OPEN?(void 0===t&&(t=!this._isServer),this._sender.ping(e||v,t,r)):V(this,e,r)}pong(e,t,r){if(this.readyState===F.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");"function"==typeof e?(r=e,e=t=void 0):"function"==typeof t&&(r=t,t=void 0),"number"==typeof e&&(e=e.toString()),this.readyState===F.OPEN?(void 0===t&&(t=!this._isServer),this._sender.pong(e||v,t,r)):V(this,e,r)}resume(){this.readyState!==F.CONNECTING&&this.readyState!==F.CLOSED&&(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,t,r){if(this.readyState===F.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if("function"==typeof t&&(r=t,t={}),"number"==typeof e&&(e=e.toString()),this.readyState!==F.OPEN)return void V(this,e,r);const n={binary:"string"!=typeof e,mask:!this._isServer,compress:!0,fin:!0,...t};this._extensions[_.extensionName]||(n.compress=!1),this._sender.send(e||v,n,r)}terminate(){if(this.readyState!==F.CLOSED)if(this.readyState!==F.CONNECTING)this._socket&&(this._readyState=F.CLOSING,this._socket.destroy());else{const e="WebSocket was closed before the connection was established";W(this,this._req,e)}}}function H(e,n,i,s){const o={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:P[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(e._autoPong=o.autoPong,!P.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${P.join(", ")})`);let a;if(n instanceof m)a=n;else try{a=new m(n)}catch(e){throw new SyntaxError(`Invalid URL: ${n}`)}"http:"===a.protocol?a.protocol="ws:":"https:"===a.protocol&&(a.protocol="wss:"),e._url=a.href;const h="wss:"===a.protocol,f="ws+unix:"===a.protocol;let c;if("ws:"===a.protocol||h||f?f&&!a.pathname?c="The URL's pathname is empty":a.hash&&(c="The URL contains a fragment identifier"):c='The URL\'s protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"',c){const t=new SyntaxError(c);if(0===e._redirects)throw t;return void j(e,t)}const u=h?443:80,l=p(16).toString("base64"),g=h?t.request:r.request,y=new Set;let b,w;if(o.createConnection=o.createConnection||(h?G:z),o.defaultPort=o.defaultPort||u,o.port=a.port||u,o.host=a.hostname.startsWith("[")?a.hostname.slice(1,-1):a.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":l,Connection:"Upgrade",Upgrade:"websocket"},o.path=a.pathname+a.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(b=new _(!0!==o.perMessageDeflate?o.perMessageDeflate:{},!1,o.maxPayload),o.headers["Sec-WebSocket-Extensions"]=O({[_.extensionName]:b.offer()})),i.length){for(const e of i){if("string"!=typeof e||!$.test(e)||y.has(e))throw new SyntaxError("An invalid or duplicated subprotocol was specified");y.add(e)}o.headers["Sec-WebSocket-Protocol"]=i.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(a.username||a.password)&&(o.auth=`${a.username}:${a.password}`),f){const e=o.path.split(":");o.socketPath=e[0],o.path=e[1]}if(o.followRedirects){if(0===e._redirects){e._originalIpc=f,e._originalSecure=h,e._originalHostOrSocketPath=f?o.socketPath:a.host;const t=s&&s.headers;if(s={...s,headers:{}},t)for(const[e,r]of Object.entries(t))s.headers[e.toLowerCase()]=r}else if(0===e.listenerCount("redirect")){const t=f?!!e._originalIpc&&o.socketPath===e._originalHostOrSocketPath:!e._originalIpc&&a.host===e._originalHostOrSocketPath;(!t||e._originalSecure&&!h)&&(delete o.headers.authorization,delete o.headers.cookie,t||delete o.headers.host,o.auth=void 0)}o.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),w=e._req=g(o),e._redirects&&e.emit("redirect",e.url,w)}else w=e._req=g(o);o.timeout&&w.on("timeout",(()=>{W(e,w,"Opening handshake has timed out")})),w.on("error",(t=>{null===w||w[M]||(w=e._req=null,j(e,t))})),w.on("response",(t=>{const r=t.headers.location,a=t.statusCode;if(r&&o.followRedirects&&a>=300&&a<400){if(++e._redirects>o.maxRedirects)return void W(e,w,"Maximum redirects exceeded");let t;w.abort();try{t=new m(r,n)}catch(t){const n=new SyntaxError(`Invalid URL: ${r}`);return void j(e,n)}H(e,t,i,s)}else e.emit("unexpected-response",w,t)||W(e,w,`Unexpected server response: ${t.statusCode}`)})),w.on("upgrade",((t,r,n)=>{if(e.emit("upgrade",t),e.readyState!==F.CONNECTING)return;w=e._req=null;const i=t.headers.upgrade;if(void 0===i||"websocket"!==i.toLowerCase())return void W(e,r,"Invalid Upgrade header");const s=d("sha1").update(l+S).digest("base64");if(t.headers["sec-websocket-accept"]!==s)return void W(e,r,"Invalid Sec-WebSocket-Accept header");const a=t.headers["sec-websocket-protocol"];let h;if(void 0!==a?y.size?y.has(a)||(h="Server sent an invalid subprotocol"):h="Server sent a subprotocol but none was requested":y.size&&(h="Server sent no subprotocol"),h)return void W(e,r,h);a&&(e._protocol=a);const f=t.headers["sec-websocket-extensions"];if(void 0!==f){if(!b){return void W(e,r,"Server sent a Sec-WebSocket-Extensions header but no extension was requested")}let t;try{t=C(f)}catch(t){return void W(e,r,"Invalid Sec-WebSocket-Extensions header")}const n=Object.keys(t);if(1!==n.length||n[0]!==_.extensionName){return void W(e,r,"Server indicated an extension that was not requested")}try{b.accept(t[_.extensionName])}catch(t){return void W(e,r,"Invalid Sec-WebSocket-Extensions header")}e._extensions[_.extensionName]=b}e.setSocket(r,n,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})})),o.finishRequest?o.finishRequest(w,e):w.end()}function j(e,t){e._readyState=F.CLOSING,e._errorEmitted=!0,e.emit("error",t),e.emitClose()}function z(e){return e.path=e.socketPath,u.connect(e)}function G(e){return e.path=void 0,e.servername||""===e.servername||(e.servername=u.isIP(e.host)?"":e.host),l.connect(e)}function W(e,t,r){e._readyState=F.CLOSING;const n=new Error(r);Error.captureStackTrace(n,W),t.setHeader?(t[M]=!0,t.abort(),t.socket&&!t.socket.destroyed&&t.socket.destroy(),process.nextTick(j,e,n)):(t.destroy(n),t.once("error",e.emit.bind(e,"error")),t.once("close",e.emitClose.bind(e)))}function V(e,t,r){if(t){const r=E(t)?t.size:R(t).length;e._socket?e._sender._bufferedBytes+=r:e._bufferedAmount+=r}if(r){const t=new Error(`WebSocket is not open: readyState ${e.readyState} (${D[e.readyState]})`);process.nextTick(r,t)}}function q(e,t){const r=this[T];r._closeFrameReceived=!0,r._closeMessage=t,r._closeCode=e,void 0!==r._socket[T]&&(r._socket.removeListener("data",ie),process.nextTick(ee,r._socket),1005===e?r.close():r.close(e,t))}function Y(){const e=this[T];e.isPaused||e._socket.resume()}function Q(e){const t=this[T];void 0!==t._socket[T]&&(t._socket.removeListener("data",ie),process.nextTick(ee,t._socket),t.close(e[L])),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e))}function J(){this[T].emitClose()}function X(e,t){this[T].emit("message",e,t)}function K(e){const t=this[T];t._autoPong&&t.pong(e,!this._isServer,I),t.emit("ping",e)}function Z(e){this[T].emit("pong",e)}function ee(e){e.resume()}function te(e){const t=this[T];t.readyState!==F.CLOSED&&(t.readyState===F.OPEN&&(t._readyState=F.CLOSING,re(t)),this._socket.end(),t._errorEmitted||(t._errorEmitted=!0,t.emit("error",e)))}function re(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),N)}function ne(){const e=this[T];let t;this.removeListener("close",ne),this.removeListener("data",ie),this.removeListener("end",se),e._readyState=F.CLOSING,this._readableState.endEmitted||e._closeFrameReceived||e._receiver._writableState.errorEmitted||null===(t=e._socket.read())||e._receiver.write(t),e._receiver.end(),this[T]=void 0,clearTimeout(e._closeTimer),e._receiver._writableState.finished||e._receiver._writableState.errorEmitted?e.emitClose():(e._receiver.on("error",J),e._receiver.on("finish",J))}function ie(e){this[T]._receiver.write(e)||this.pause()}function se(){const e=this[T];e._readyState=F.CLOSING,e._receiver.end(),this.end()}function oe(){const e=this[T];this.removeListener("error",oe),this.on("error",I),e&&(e._readyState=F.CLOSING,this.destroy())}return Object.defineProperty(F,"CONNECTING",{enumerable:!0,value:D.indexOf("CONNECTING")}),Object.defineProperty(F.prototype,"CONNECTING",{enumerable:!0,value:D.indexOf("CONNECTING")}),Object.defineProperty(F,"OPEN",{enumerable:!0,value:D.indexOf("OPEN")}),Object.defineProperty(F.prototype,"OPEN",{enumerable:!0,value:D.indexOf("OPEN")}),Object.defineProperty(F,"CLOSING",{enumerable:!0,value:D.indexOf("CLOSING")}),Object.defineProperty(F.prototype,"CLOSING",{enumerable:!0,value:D.indexOf("CLOSING")}),Object.defineProperty(F,"CLOSED",{enumerable:!0,value:D.indexOf("CLOSED")}),Object.defineProperty(F.prototype,"CLOSED",{enumerable:!0,value:D.indexOf("CLOSED")}),["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(F.prototype,e,{enumerable:!0})})),["open","error","close","message"].forEach((e=>{Object.defineProperty(F.prototype,`on${e}`,{enumerable:!0,get(){for(const t of this.listeners(e))if(t[A])return t[k];return null},set(t){for(const t of this.listeners(e))if(t[A]){this.removeListener(e,t);break}"function"==typeof t&&this.addEventListener(e,t,{[A]:!0})}})})),F.prototype.addEventListener=x,F.prototype.removeEventListener=U,rr=F}!function(){if(sr)return ir;sr=1,pr();const{Duplex:e}=n;function t(e){e.emit("close")}function r(){!this.destroyed&&this._writableState.finished&&this.destroy()}function i(e){this.removeListener("error",i),this.destroy(),0===this.listenerCount("error")&&this.emit("error",e)}ir=function(n,s){let o=!0;const a=new e({...s,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return n.on("message",(function(e,t){const r=!t&&a._readableState.objectMode?e.toString():e;a.push(r)||n.pause()})),n.once("error",(function(e){a.destroyed||(o=!1,a.destroy(e))})),n.once("close",(function(){a.destroyed||a.push(null)})),a._destroy=function(e,r){if(n.readyState===n.CLOSED)return r(e),void process.nextTick(t,a);let i=!1;n.once("error",(function(e){i=!0,r(e)})),n.once("close",(function(){i||r(e),process.nextTick(t,a)})),o&&n.terminate()},a._final=function(e){n.readyState!==n.CONNECTING?null!==n._socket&&(n._socket._writableState.finished?(e(),a._readableState.endEmitted&&a.destroy()):(n._socket.once("finish",(function(){e()})),n.close())):n.once("open",(function(){a._final(e)}))},a._read=function(){n.isPaused&&n.resume()},a._write=function(e,t,r){n.readyState!==n.CONNECTING?n.send(e,r):n.once("open",(function(){a._write(e,t,r)}))},a.on("end",r),a.on("error",i),a}}(),cr(),ur();var dr,gr,yr,mr,_r=Y(pr());function br(){if(gr)return dr;gr=1;const{tokenChars:e}=fr();return dr={parse:function(t){const r=new Set;let n=-1,i=-1,s=0;for(;s<t.length;s++){const o=t.charCodeAt(s);if(-1===i&&1===e[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 e=t.slice(n,i);if(r.has(e))throw new SyntaxError(`The "${e}" subprotocol is duplicated`);r.add(e),n=i=-1}}else-1===i&&-1!==n&&(i=s)}if(-1===n||-1!==i)throw new SyntaxError("Unexpected end of input");const o=t.slice(n,s);if(r.has(o))throw new SyntaxError(`The "${o}" subprotocol is duplicated`);return r.add(o),r}},dr}var wr=function(){if(mr)return yr;mr=1;const e=s,t=a,{Duplex:r}=n,{createHash:i}=f,o=lr(),h=zt(),c=br(),u=pr(),{GUID:l,kWebSocket:p}=At(),d=/^[+/0-9A-Za-z]{22}==$/;function g(e){e._state=2,e.emit("close")}function y(){this.destroy()}function m(e,r,n,i){n=n||t.STATUS_CODES[r],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...i},e.once("finish",e.destroy),e.end(`HTTP/1.1 ${r} ${t.STATUS_CODES[r]}\r\n`+Object.keys(i).map((e=>`${e}: ${i[e]}`)).join("\r\n")+"\r\n\r\n"+n)}function _(e,t,r,n,i){if(e.listenerCount("wsClientError")){const n=new Error(i);Error.captureStackTrace(n,_),e.emit("wsClientError",n,r,t)}else m(r,n,i)}return yr=class extends e{constructor(e,r){if(super(),null==(e={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:u,...e}).port&&!e.server&&!e.noServer||null!=e.port&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(null!=e.port?(this._server=t.createServer(((e,r)=>{const n=t.STATUS_CODES[426];r.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),r.end(n)})),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){const e=this.emit.bind(this,"connection");this._removeListeners=function(e,t){for(const r of Object.keys(t))e.on(r,t[r]);return function(){for(const r of Object.keys(t))e.removeListener(r,t[r])}}(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,r,n)=>{this.handleUpgrade(t,r,n,e)}})}!0===e.perMessageDeflate&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,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(e){if(2===this._state)return e&&this.once("close",(()=>{e(new Error("The server is not running"))})),void process.nextTick(g,this);if(e&&this.once("close",e),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(g,this);else{const e=this._server;this._removeListeners(),this._removeListeners=this._server=null,e.close((()=>{g(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");if((-1!==t?e.url.slice(0,t):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,t,r,n){t.on("error",y);const i=e.headers["sec-websocket-key"],s=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if("GET"!==e.method){return void _(this,e,t,405,"Invalid HTTP method")}if(void 0===s||"websocket"!==s.toLowerCase()){return void _(this,e,t,400,"Invalid Upgrade header")}if(void 0===i||!d.test(i)){return void _(this,e,t,400,"Missing or invalid Sec-WebSocket-Key header")}if(8!==a&&13!==a){return void _(this,e,t,400,"Missing or invalid Sec-WebSocket-Version header")}if(!this.shouldHandle(e))return void m(t,400);const f=e.headers["sec-websocket-protocol"];let u=new Set;if(void 0!==f)try{u=c.parse(f)}catch(r){return void _(this,e,t,400,"Invalid Sec-WebSocket-Protocol header")}const l=e.headers["sec-websocket-extensions"],p={};if(this.options.perMessageDeflate&&void 0!==l){const r=new h(this.options.perMessageDeflate,!0,this.options.maxPayload);try{const e=o.parse(l);e[h.extensionName]&&(r.accept(e[h.extensionName]),p[h.extensionName]=r)}catch(r){return void _(this,e,t,400,"Invalid or unacceptable Sec-WebSocket-Extensions header")}}if(this.options.verifyClient){const s={origin:e.headers[""+(8===a?"sec-websocket-origin":"origin")],secure:!(!e.socket.authorized&&!e.socket.encrypted),req:e};if(2===this.options.verifyClient.length)return void this.options.verifyClient(s,((s,o,a,h)=>{if(!s)return m(t,o||401,a,h);this.completeUpgrade(p,i,u,e,t,r,n)}));if(!this.options.verifyClient(s))return m(t,401)}this.completeUpgrade(p,i,u,e,t,r,n)}completeUpgrade(e,t,r,n,s,a,f){if(!s.readable||!s.writable)return s.destroy();if(s[p])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>0)return m(s,503);const c=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${i("sha1").update(t+l).digest("base64")}`],u=new this.options.WebSocket(null,void 0,this.options);if(r.size){const e=this.options.handleProtocols?this.options.handleProtocols(r,n):r.values().next().value;e&&(c.push(`Sec-WebSocket-Protocol: ${e}`),u._protocol=e)}if(e[h.extensionName]){const t=e[h.extensionName].params,r=o.format({[h.extensionName]:[t]});c.push(`Sec-WebSocket-Extensions: ${r}`),u._extensions=e}this.emit("headers",c,n),s.write(c.concat("\r\n").join("\r\n")),s.removeListener("error",y),u.setSocket(s,a,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(u),u.on("close",(()=>{this.clients.delete(u),this._shouldEmitClose&&!this.clients.size&&process.nextTick(g,this)}))),f(u,n)}},yr}(),Er=Y(wr);let Br={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 vr=new TextDecoder;q.NB;const Sr=q.MB;class Ar{constructor(e,t){this.socket=e,e.isAlive=!0,e.txCounter=0,e.rxCounter=0,e.openTime=Date.now(),this.boho=new ut,this.encMode=te.AUTO,this.channels=new Set,this.retain_signal=new Map,this.ssid=Ar.ssid++,this.manager=t,this.cid,this.did,this.uid,this.nick="",this.lastEchoMessage="N",this.privateNode=!1,this.HOME_CHANNEL="",this.level=Br.defaultQuotaIndex,this.quota=se[this.level],this.isAdmin=!1,this.state,this.stateLog=[],this.setState(ee.INIT)}static ssid=1;setState(e){this.state=e,Br.debug.showAuthInfo&&(this.stateLog.push(e),console.log(this.stateLog.join(">")))}getState(){return this.state}getStateName(){return ee[this.state].toLowerCase()}showMessageLog(e,t){let r=this.boho.isAuthorized?`did: ${this.did} ${this.cid}@`:`${this.cid}@`;if(t){let t=ie[e[0]];t||(t=ut.BohoMsg[e[0]]),t=" ["+t+"]",e.byteLength>40?console.log(r+t+" LEN:",e.length):console.log(r+t,e)}else console.log(r+" [TEXT] %s",e)}rxQuotaChecker(e){let t=e.byteLength;return this.manager.rxBytes+=t,!(Br.useQuota.signalSize&&t>this.quota.signalSize)||(console.log("## quota: size over"),this.send(Buffer.from([ie.OVER_SIZE])),Br.useQuota.disconnect&&this.close(),!1)}onTimeDelayMessage(e,t=!0){setTimeout((()=>{this.onSocketMessage(e,t)}),Br.debug.delay)}onSocketMessage(e,t=!0){if(this.receiveMonitor(),!this.rxQuotaChecker(e))return;let r,n;if("message"===Br.showMessage&&this.showMessageLog(e,t),t){if(r=e[0],r===ut.BohoMsg.ENC_488){try{n=this.boho.decrypt_488(e)}catch(e){return void console.log("-- E488 DEC_FAIL",e)}if(!n)return;r=n[0],e=n}else if(r===ut.BohoMsg.ENC_E2E){try{n=this.boho.decrypt_488(e)}catch(e){return}if(!n)return;r=n[0],e.set(n,ut.MetaSize.ENC_488),e=e.subarray(ut.MetaSize.ENC_488)}switch(r){case ie.PING:this.pong();break;case ie.PONG:break;case ie.CID_REQ:this.state<ee.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(q.pack(Sr("#cid_ack","8",ie.CID_RES),Sr("#cid",this.cid))),this.setState(ee.CID_READY);break;case ie.ECHO:try{let t=vr.decode(e.subarray(1));this.lastEchoMessage=t}catch(e){}this.send(e,t);break;case ie.IAM:if(e.byteLength>1){let t=e.subarray(1);this.nick=vr.decode(t),console.log("iam nick reset",this.nick)}this.iamResponse();break;case ie.SIGNAL_E2E:case ie.SIGNAL:if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength>=t+2){let r=e.subarray(2,2+t);r=vr.decode(r),this.manager.sender(r,this,e)}}break;case ie.UNSUBSCRIBE:if(2==e.byteLength)this.manager.unsubscribe([""],this);else if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength==t+2){let r=e.subarray(2,2+t);r=vr.decode(r);let n=r.split(",");this.manager.unsubscribe(n,this)}}break;case ie.SUBSCRIBE:if(e.byteLength>=3){let t=e.readUInt8(1);if(e.byteLength==t+2){let r=e.subarray(2,2+t);r=vr.decode(r);let n=r.split(",");this.manager.subscribe(n,this)}}break;case ie.SUBSCRIBE_REQ:if(e.byteLength>=6){let t=e.readUInt16BE(1),r=e.readUInt16BE(3);if(e.byteLength==r+5){let n=e.subarray(5,5+r);n=vr.decode(n);let i=n.split(",");this.manager.subscribe(i,this),this.response(t,0)}else this.response(t,255)}break;case ie.REQUEST:try{let t=q.unpack(e);if(t){if(!t.target||!t.topic)return;this.manager.server.apiNames.has(t.target)&&this.manager.server.emit(t.target,this,t)}}catch(e){console.log("request catch error",e)}break;case ie.CLOSE:if(e.byteLength>1){let t=vr.decode(e.subarray(1));console.log(">> CLOSE reason:",t),this.close()}break;case ut.BohoMsg.AUTH_REQ:if(!this.manager.authManager)return;this.state<ee.SENT_SERVER_READY&&this.close(),this.setState(ee.RECV_AUTH_REQ);let r=this.boho.auth_nonce();this.send(r),this.setState(ee.SENT_SERVER_NONCE);break;case ut.BohoMsg.AUTH_HMAC:if(!this.manager.authManager)return;return this.state<ee.SENT_SERVER_NONCE&&this.close(),this.setState(ee.RECV_AUTH_HMAC),void this.manager.authManager.verify_auth_hmac(e,this).then((e=>{e&&this.manager.deligateSignal(remote,"@$name",e.name)})).catch((e=>{}))}}else try{let t=vr.decode(e);this.manager.server.emit("text_message",t,this)}catch(e){}}response(e,t,r){r?this.send_enc_mode(q.pack(Sr("#type","8",ie.RESPONSE_MBP),Sr("status","8",t),Sr("mid","16",e),Sr("body",r))):this.send_enc_mode(q.pack(Sr("#type","8",ie.RESPONSE_MBP),Sr("status","8",t),Sr("mid","16",e)))}send_enc_mode(e,t=!1){if((this.encMode===te.YES||this.encMode===te.AUTO&&!this.TLS&&this.boho.isAuthorized)&&(t=!0),t&&e[0]==ie.SIGNAL_E2E){let t=e[1],r=this.boho.encrypt_488(e.subarray(0,3+t));r[0]=ut.BohoMsg.ENC_E2E;let n=Buffer.concat([r,e.subarray(3+t)]);this.send(n)}else if(t){let t=this.boho.encrypt_488(e);t&&this.send(t)}else this.send(e)}iamResponse(e=""){if(""==e){let t=[];for(let e of this.channels.keys())t.push(e);e={ssid:this.ssid,uid:this.uid,cid:this.cid,did:this.did,nick:this.nick,ip:this.ip,tag:t}}let t=q.pack(Sr("#MsgType","8",ie.IAM_RES),Sr("#info",e));this.send_enc_mode(t)}}const kr=new TextDecoder;class Lr extends Ar{constructor(e,t,r){super(e,r),this.socketType=e.socketType,"websocket"===this.socketType?(this.TLS="https"===t.headers["x-forwarded-proto"],this.ip=this.getRemoteIP(t)):(this.TLS=!1,this.ip=this.getRemoteIP(e.remoteAddress)),!function(e){if(0===e.indexOf("0.0.0.0"))return!0;if(0===e.indexOf("127.0.0.1"))return!0;if(0===e.indexOf("192.168."))return!0;if(0===e.indexOf("10."))return!0;if(0===e.indexOf("172.")){if(0===e.indexOf("172.16."))return!0;if(0===e.indexOf("172.17."))return!0;if(0===e.indexOf("172.18."))return!0;if(0===e.indexOf("172.19."))return!0;if(0===e.indexOf("172.20."))return!0;if(0===e.indexOf("172.21."))return!0;if(0===e.indexOf("172.22."))return!0;if(0===e.indexOf("172.23."))return!0;if(0===e.indexOf("172.24."))return!0;if(0===e.indexOf("172.25."))return!0;if(0===e.indexOf("172.26."))return!0;if(0===e.indexOf("172.27."))return!0;if(0===e.indexOf("172.28."))return!0;if(0===e.indexOf("172.29."))return!0;if(0===e.indexOf("172.30."))return!0;if(0===e.indexOf("172.31."))return!0}return!1}(this.ip)?this.HOME_CHANNEL="IP:"+function(e){let t=e.split(".");return Buffer.from(t).toString("hex")}(this.ip):(this.HOME_CHANNEL="PRIVATE:",this.privateNode=!0),"websocket"===this.socketType?(Br.debug.slow?e.on("message",this.onTimeDelayMessage.bind(this)):e.on("message",this.onSocketMessage.bind(this)),e.on("pong",this.receiveMonitor.bind(this)),e.on("ping",this.receiveMonitor.bind(this)),e.on("error",(e=>{console.log("Websocket error",e,e.code)})),e.onclose=e=>{this.manager.removeRemote(this)}):(this.congRx=new Et,e.on("data",(e=>{this.congRx.write(e)})),this.congRx.on("wrong",this.onWrongCongPacketMessage.bind(this)),Br.debug.slow?this.congRx.on("data",this.onTimeDelayMessage.bind(this)):this.congRx.on("data",this.onSocketMessage.bind(this)),e.on("error",(e=>{console.log("TCP Socket error",e)})),e.on("close",(e=>{this.manager.removeRemote(this)})))}onWrongCongPacketMessage(e){if(this.cid);else{let t="";try{t=kr.decode(e)}catch(r){t+="Len: "+e.byteLength}if(this.manager.attackLogger){let e=`> ${this.ssid} ${this.ip} ${t}`;this.manager.attackLogger.log(e)}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(e){return e.headers["x-forwarded-proto"]}getRemoteIP(e){let t;return e&&e.headers?(t=e.headers["x-forwarded-for"],null==t&&(t=e.socket.remoteAddress)):t=e,t?(0==t.indexOf("::ffff:")&&(t=t.substring(7)),"::1"==t&&(t="127.0.0.1")):t="0.0.0.0",t}ping(){"websocket"===this.socketType?(this.socket.ping(),this.socket.txCounter++):this.send(Buffer.from([ie.PING]))}pong(){"websocket"===this.socketType?(this.socket.pong(),this.socket.txCounter++):this.send(Buffer.from([ie.PONG]))}getTraffic(){this.socket.bytesWritten||this.socket._socket,this.socket.bytesRead||this.socket._socket,this.socket.txCounter,this.socket.rxCounter}close(e=!1){this.getTraffic(),"websocket"===this.socketType?e?this.socket.terminate():this.socket.close():e?this.socket.destroy():this.socket.end()}send(e,t){this.manager.txBytes+=e.byteLength,this.socket.txCounter++,"websocket"===this.socketType?1===this.socket.readyState?null!=t?this.socket.send(e,{binary:t}):this.socket.send(e):this.close(!0):"open"==this.socket.readyState?this.socket.write(wt(e)):this.close(!0)}}const Tr=new Intl.DateTimeFormat("ko-KR",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",hour12:!1,timeZone:"Asia/Seoul"});class Ir{constructor(e){this.file=l.openSync(e,"a+"),console.log("new FileLogger logFile: ",e,this.file)}log(e){let t=Tr.format(new Date)+" "+e+"\n";l.write(this.file,t,(e=>{if(e)throw e}))}}class xr{constructor(e){this.manager=e,this.metricsPack={remotes:[0],channels:[0],txBytes:[0],rxBytes:[0],unixTime:[Math.floor(Date.now()/1e3)],period:0},this.tickId=setInterval((e=>{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(e){let t=[{...y.memoryUsage()}];e&&console.table(t,["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 e&&console.table(r,["lastSSID","remotes","channels","txBytes","rxBytes"]),r[0]}getRemotes(e){let t=Array.from(this.manager.remotes.values()).map((e=>"#"+e.ssid+":"+e.cid+"("+e.state+")"));return e&&console.table(t),t}getCIdList(e){let t=Array.from(this.manager.cid2remote.keys());return e&&console.table(t),t}getChannelList(e){let t=Array.from(this.manager.channel_map.keys());return e&&console.table(t),t}getSubscribers(e){let t=[];if(this.manager.channel_map.has(e)){this.manager.channel_map.get(e).forEach((e=>{t.push(e.cid)}))}return t}getRemoteByCId(e,t=1){if(!this.manager.cid2remote.has(e))return{result:"nop"};{let r=this.manager.cid2remote.get(e);if(1==t)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==t)return{ip:r.ip,uptime:Math.trunc((Date.now()-r.socket.openTime)/1e3),nick:r.nick,ssid:r.ssid,echo:r.lastEchoMessage};if(3==t)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:te[r.encMode]};if(4==t){let e=Array.from(r.channels.keys()),t=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:e,set:t,retain:n}}}}}const Ur=new TextEncoder,Or=new TextDecoder;class Cr{constructor(e,t){this.server=e,this.txBytes=0,this.rxBytes=0,this.authManager=t,this.connectionLogger,Br.fileLogger.connection.use&&(this.connectionLogger=new Ir(Br.fileLogger.connection.path)),this.attackLogger,Br.fileLogger.attack.use&&(this.attackLogger=new Ir(Br.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 xr(this),this.lastSSID=0,this.pingIntervalID=setInterval((e=>{this.remotes.forEach((function(e){let t=e.socket;!1===t.isAlive&&(console.log("## timeout. cid:",e.cid),e.close()),t.txCounter++,t.isAlive=!1,"websocket"===e.socketType?t.ping():e.ping()}))}),Br.timeout),Br.showMetric&&(this.monitIntervalID=setInterval((e=>{this.monitor()}),Br.monitorPeriod))}addRemote(e,t){e.isAlive=!0;let r=new Lr(e,t,this);this.remotes.add(r),r.send(Buffer.from([ie.SERVER_READY])),r.setState(ee.SENT_SERVER_READY),this.lastSSID=r.ssid;let n=`+ IP:${r.ip} #${r.ssid} ${"websocket"===e.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(n)}removeRemote(e){let t=`- IP:${e.ip} #${e.ssid} cid:${e.cid} ${"websocket"===e?.socket.socketType?"WS":"CS"} `;this.connectionLogger&&this.connectionLogger.log(t),this.deligateSignal(e,"@state","close"),this.deligateSignal(e,"@$state","close");for(let t of e.channels.keys())if(this.channel_map.has(t)){const r=this.channel_map.get(t);r.delete(e),0==r.size&&this.channel_map.delete(t)}if(e.boho.isAuthorized);else for(let t of e.retain_signal.keys())t=this.CID_PREFIX+e.cid+"@"+t,this.channel_map.has(t)&&this.channel_map.delete(t);if(e.uid&&this.server.apiNames.has("account")){let t={topic:"detachUserRemote",args:["caller:manager.removeRemote"]};this.server.emit("account",e,t)}this.remotes.delete(e),this.cid2remote.delete(e.cid),e=null}serverSignal(e){let t=q.pack(q.MB("#MsgType","8",ie.SERVER_SIGNAL),q.MB("#signalObject",e));this.remotes.forEach((e=>{e.send_enc_mode(t)}))}getSignalTag(e){let t=e.readUint8(1),r=e.subarray(2,2+t);return Or.decode(r)}getNewSignalTagMessage(e,t){let r=e[0],n=e.readUint8(1),i=Ur.encode(t),s=i.byteLength,o=e.subarray(2+n);return Buffer.concat([Buffer.from([r,s]),i,o])}deligateSignal(e,t,...r){let n=ae(t,...r);this.sender(t,e,n)}adminSignal(e,t){return this.cid2remote.has(e)?void this.cid2remote.get(e).send_enc_mode(t):"no cid"}serverSignalTo(e,...t){let r=e.split("@")[0],n=ae("@"+e.split("@")[1],...t);if(r&&this.cid2remote.has(r)){let e=this.cid2remote.get(r);return console.log("target",e.state,e.cid),void e.send_enc_mode(n)}return"no cid"}sender(e,t,r){if(Br.memberOnly&&!t.boho.isAuthorized)return t.send(Buffer.from([ie.SERVER_CLEAR_AUTH])),t.close(),["err","not autrized"];if(0==e.indexOf("$"))return["err","prefix $ is reserved for userSet tag."];let n=e.indexOf("@");if(0===n)e=t.cid+e,r=this.getNewSignalTagMessage(r,e);else if(n>0){let t=e.split("@")[0];if(this.cid2remote.has(t)){let n="@"+e.split("@")[1];return r=this.getNewSignalTagMessage(r,n),this.cid2remote.get(t).send_enc_mode(r),["ok",1]}return["err","Invalid cid"]}if((e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e).includes("$")&&Br.retain.isAvailable&&Br.retain.limitCounter>this.retain_messages.size&&Br.retain.limitSize>r.byteLength)if(e.includes("@")){let n=e.split("@")[1];t.retain_signal.set(n,r)}else this.retain_messages.set(e,r);let i=0;if(this.channel_map.has(e)){let n=this.channel_map.get(e);if(n.size>=1){let e;e=Br.useQuota.publishCounter?Math.min(t.quota.publishCounter,n.size):n.size;let s=n.values();for(;i<e;){let e=s.next().value;if(!e)break;e!==t&&(e.send_enc_mode(r),i++)}return Br.useQuota.publishCounter,["ok",i]}}return["err","No subscriber."]}subscribe(e,t){return e.forEach((e=>{if(e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e,this.channel_map.has(e)?this.channel_map.get(e).add(t):this.channel_map.set(e,new Set([t])),t.channels.add(e),e.includes("$")&&Br.retain.isAvailable){let r;if(e.includes("@")){let t=e.split("@")[0];t=t.split(this.CID_PREFIX)[1];let n=e.split("@")[1];if(!this.cid2remote.has(t))return;r=this.cid2remote.get(t).retain_signal.get(n)}else this.retain_messages.has(e)&&(r=this.retain_messages.get(e));r&&t.send_enc_mode(r)}})),t.channels.size}unsubscribe(e,t){1==e.length&&""==e[0]?(t.channels.forEach((e=>{if(this.channel_map.has(e)){let r=this.channel_map.get(e);r.delete(t),0==r.size&&this.channel_map.delete(e)}})),t.channels.clear()):e.forEach((e=>{if(e=0===e.indexOf("#")?t.HOME_CHANNEL+e:e.includes("@")?this.CID_PREFIX+e:this.CHANNEL_PREFIX+e,this.channel_map.has(e)){let r=this.channel_map.get(e);r.delete(t),0==r.size&&this.channel_map.delete(e)}t.channels.delete(e)}))}monitor(){switch(process.stdout.isTTY&&(process.stdout.cursorTo(0,0),process.stdout.clearScreenDown()),Br.showChannel>0&&this.metric.channels(Br.showChannel),parseInt(Br.showMetric)){case 1:this.metric.oneline(!0);break;case 2:this.metric.getRemotes(!0);break;case 3:this.metric.getChannelList(!0)}}closeRemoteByCId(e){return this.cid2remote.has(e)?(this.cid2remote.get(e).close(),1):0}}const Rr=0,Nr=255;const Mr=new TextDecoder;class Pr{constructor(){this.authLogger,Br.fileLogger.auth.use&&(this.authLogger=new Ir(Br.fileLogger.auth.path),console.log("Auth: begin file logger.[auth]"))}send_auth_fail(e,t){if(this.authLogger){let r=`FAIL #${e.ssid} reason:${t} `;this.authLogger.log(r)}console.log("## AUTH_FAIL reason:",t),e.setState(ee.AUTH_FAIL),setTimeout((t=>{e.send(Buffer.from([ut.BohoMsg.AUTH_FAIL]))}),Br.auth.delay_auth_fail)}async verify_auth_hmac(e,t){try{let r=q.unpack(e,ut.Meta.AUTH_HMAC);if(!r)return void this.send_auth_fail(t,"unpack auth_pack fail");let n="";n=r.id8.includes(0)?Mr.decode(r.id8.subarray(0,r.id8.indexOf(0))):Mr.decode(r.id8);let i,s=await this.getAuth(n);if(Br.debug.showAuthInfo,!s)return void this.send_auth_fail(t,"NO ID:"+n);t.boho.copy_id8(r.id8);const o=44;s.key.length==o?(i=Buffer.from(s.key,"base64"),t.boho.copy_key(i)):t.boho.set_key(s.key);let a=t.boho.check_auth_hmac(r);if(!a)return void this.send_auth_fail(t,"hmac dismatched");if(t.manager.cid2remote.has(s.cid)){let e=t.manager.cid2remote.get(s.cid);return e==t?void console.log("## trying RELOGIN with SAME ID. ignored."):(console.log("### clear_auth and close old connection:",e.cid),e.send(Buffer.from([ie.SERVER_CLEAR_AUTH])),e.close(),void t.close())}t.cid&&t.manager.cid2remote.delete(t.cid),t.did=n,t.cid=s.cid,t.nick=s.cid;let h=Br.defaultQuotaIndex;s.level&&(h=s.level),h=parseInt(h);let f=se[h];if(!f){let e="no index quotaTable for auth.level: "+h;return console.log("##AUTH:DATA ERROR##",e),void this.send_auth_fail(t,e)}if(t.level=h,t.quota=f,t.level===Br.adminLevel&&(console.log("## LOGIN ADMIN CID:",t.cid),t.isAdmin=!0),t.send(Buffer.from([ie.QUOTA_LEVEL,h])),t.manager.cid2remote.set(t.cid,t),t.send(a),t.setState(ee.AUTH_READY),this.authLogger){let e=`OK #${t.ssid} cid: ${t.cid} did:${t.did}`;t.isAdmin&&(e="#ADMIN# "+e),this.authLogger.log(e)}return s}catch(e){this.send_auth_fail(t,"caught: unknown error"+e)}}}const Dr="device:";var $r=Object.freeze({__proto__:null,checkPermission:function(e){return e.level>=0},date:async function(e,t){let r=(new Date).toUTCString();e.response(t.mid,Rr,r)},echo:async function(e,t){t.args?e.response(t.mid,Rr,t.args):e.response(t.mid,Nr,"no message to echo")},unixtime:async function(e,t){let r=Math.floor(Date.now()/1e3);e.response(t.mid,Rr,r)}});var Fr=Object.freeze({__proto__:null,checkPermission:function(e){return e.level>=255},commands:["cid","remotes","clients","channels","subscribers","remote","client","close","addauth","getauth","delauth","getauthidlist","getdevicelist","adddevice","getdevice","deldevice"],request:async function(e,t){let r,n=0;try{let i=t.topic;if(i=i.toLowerCase(),"cid"==i)r=e.manager.metric.getCIdList();else if("remotes"==i||"clients"==i)r=e.manager.metric.getRemotes();else if("channels"==i)r=e.manager.metric.getChannelList();else if("subscribers"==i){let n=t.$[0];n&&(r=e.manager.metric.getSubscribers(n))}else if("remote"==i||"client"==i){let n=t.$[0],i=t.$[1];n&&(r=e.manager.metric.getRemoteByCId(n,i))}else if("close"==i)t.$[0]&&(r=e.manager.closeRemoteByCId(t.$[0]));else if("addauth"==i||"adddevice"==i){if(e.manager.authManager&&4==t.$.length&&e.manager.authManager.addAuth){let n=t.$[0],i=t.$[1],s=t.$[2],o=t.$[3];r=await e.manager.authManager.addAuth(n,i,s,o)}}else if("delauth"==i||"deldevice"==i){if(e.manager.authManager&&1==t.$.length&&e.manager.authManager.delAuth){let n=t.$[0];r=await e.manager.authManager.delAuth(n)}}else if("getauth"==i||"getdevice"==i){if(e.manager.authManager&&1==t.$.length&&e.manager.authManager.getAuth){let n=t.$[0];r=await e.manager.authManager.getAuth(n)}}else"getauthidlist"==i||"getdevicelist"==i?e.manager.authManager&&e.manager.authManager.getAuthIdList&&(r=await e.manager.authManager.getAuthIdList()):(n=Nr,r="api sudo: no such a cmd: "+i);e.response(t.mid,n,r)}catch(r){e.response(t.mid,Nr,r.message)}}});const Hr=["GET","SET","HGETALL","HGET","HSET","SADD","SISMEMBER","SMEMBERS","EXISTS","SREM","DEL","KEYS","SAVE"];exports.API_TYPE={REQUEST_RESPONSE:"requet_response",ONE_WAY:"one_way"},exports.Auth_Env=class extends Pr{constructor(e){let t;super(),e?t=e.split(","):process.env.BOHO_AUTH?(e=process.env.BOHO_AUTH,t=process.env.BOHO_AUTH.split(",")):(console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo"),process.exit()),this.AUTH=new Map,t.length>=1?t.forEach((e=>{let t=e.split(".")[0],r=e.split(".")[1],n=e.split(".")[2];if(n=parseInt(n),t&&r&&"number"==typeof n){let e=t;this.addAuth(t,r,e,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(e){return this.AUTH.get(e)}async getAuthIdList(){return Array.from(this.AUTH.keys())}addAuth(e,t,r,n=0){let i=Buffer.from(ut.sha256.hash(t)).toString("base64");this.AUTH.set(e,{key:i,cid:r,level:n})}},exports.Auth_File=class extends Pr{constructor(e){super(),this.AUTH=new Map;let t=p.parse(e);this.path=p.resolve(e),console.log("auth from file path:",this.path);let r=t.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(e){return this.AUTH.get(e)}async getAuthIdList(){return Array.from(this.AUTH.keys())}loadAuthInfoFile_JS(e){import(e).then((e=>{console.log(e.authInfo),e.authInfo.forEach((e=>{this.addAuth(...e)})),console.log("total AUTH INFO size: ",this.AUTH.size)})).catch((e=>{console.log(e)}))}loadAuthInfoFile_JSON(e){let t=l.readFileSync(e);t=(new TextDecoder).decode(t),JSON.parse(t).forEach((e=>{this.addAuth(...e)})),console.log("total AUTH INFO size: ",this.AUTH.size)}addAuth(e,t,r,n=0){let i=Buffer.from(ut.sha256.hash(t)).toString("base64");this.AUTH.set(e,{key:i,cid:r,level:n})}},exports.Auth_Redis=class extends Pr{constructor(e){if(super(),!e)throw new Error("AuthRedis constructor: no redisClient");this.redis=e}async getAuth(e){let t=await this.redis.hGetAll(Dr+e);if(t.key)return t}async getAuthIdList(){let e=await this.redis.keys(Dr+"*");if(e=e.map((e=>e.split(":")[1])),e)return e}async addAuth(e,t,r="",n=0){let i=Buffer.from(ut.sha256.hash(t)).toString("base64");return this.redis.hSet(Dr+e,{key:i,cid:r,level:n})}async delAuth(e){return this.redis.del(Dr+e)}async save(e){return this.redis.save()}},exports.Boho=ut,exports.BohoAuth=Pr,exports.CLIENT_STATE=ee,exports.CongRx=Et,exports.ENC_MODE=te,exports.FileLogger=Ir,exports.IO=class extends gt{constructor(e){super(e),e&&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(e){this.socket=new _r(e),this.stateChange("opening"),this.socket.onopen=()=>{this.socket.on("message",this.onWebSocketMessage.bind(this)),this.emit("open")},this.socket.onerror=e=>{this.emit("error",e)},this.socket.onclose=()=>{this.emit("close")}}onWebSocketMessage(e){this.rxCounter++,this.lastTxRxTime=Date.now(),this.rxBytes+=e.byteLength,this.emit("socket_data",e)}socket_send(e){1===this.socket?.readyState?(this.socket.send(e),this.txCounter++,this.txBytes+=e.byteLength,this.lastTxRxTime=Date.now()):console.log(".")}},exports.IOCongSocket=class extends gt{constructor(e){super(e),e&&this.open()}close(){this.socket?.end(),this.socket=null}stop(){this.close(),clearInterval(this.connectionCheckerIntervalID),this.connectionCheckerIntervalID=null}keepAlive(){let e=this.socket?.readyState;(!this.socket||"open"!==e&&"opening"!==e)&&this.open()}createConnection(e){let t=new URL(e);"cong:"!=t.protocol&&(t=new URL("cong://"+e)),this.socket=i.createConnection(t.port,t.hostname),this.stateChange("opening"),this.socket.on("connect",(()=>{this.congRx=new Et,this.socket.pipe(this.congRx),this.congRx.on("data",this.onTCPSocketMessage.bind(this)),this.emit("open")})),this.socket.on("error",(e=>{this.emit("error",e)})),this.socket.on("close",(()=>{this.emit("close")}))}onTCPSocketMessage(e){this.rxCounter++,this.rxBytes+=e.byteLength,this.lastTxRxTime=Date.now(),this.emit("socket_data",e)}socket_send(e){if("open"===this.socket?.readyState){let t=wt(e);this.socket.write(t),this.txCounter++,this.txBytes+=t.byteLength,this.lastTxRxTime=Date.now()}else console.log(".")}},exports.IOMsg=ie,exports.MBP=q,exports.PAYLOAD_TYPE=ne,exports.RedisAPI=class{constructor(e,t){if(!e)throw new Error("RedisAPI constructor: no redisClient");this.redisClient=e,this.minLevel=t||200,this.commands=Hr}checkPermission(e,t){return console.log("checkPermission",e.level,"vs",this.minLevel),e.level>=this.minLevel}async request(e,t){let r,n=Rr;try{let i=t.topic;i=i.toUpperCase(),Hr.includes(i)?(console.log("RedisAPI call:",i,t.args),r=t.args.length>0?await this.redisClient[i](...t.args):await this.redisClient[i]()):n=Nr,e.response(t.mid,n,r)}catch(r){e.response(t.mid,Nr,r.message)}}},exports.SIZE_LIMIT=re,exports.STATES=Z,exports.STATUS={OK:0,ERROR:255},exports.Server=class extends s{constructor(e,t){if(super(),this.apiNames=new Set,this.wss={},e.timeout){let t=parseInt(e.timeout);t&&t>=1e3&&(Br.timeout=t)}if(e.monitorPeriod){let t=parseInt(e.monitorPeriod);t&&t>=1e3&&(Br.monitorPeriod=t)}e.showMessage&&(Br.showMessage=e.showMessage),e.showMetric&&(Br.showMetric=e.showMetric),e.timeout&&(Br.timeout=e.timeout),e.port&&(Br.port=parseInt(e.port)),e.httpServer&&(Br.httpServer=e.httpServer),e.congPort&&(Br.congPort=parseInt(e.congPort)),this.manager=new Cr(this,t),(Br.port||Br.httpServer)&&this.startWSServer(Br),Br.congPort&&this.startCongServer(Br.congPort)}startWSServer(e){if(e.port)console.log("opening WebSocket Server port:",e.port),this.wss=new Er({port:e.port});else{if(!e.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 Er({server:e.httpServer})}this.wss.on("error",(e=>{console.error("### ws server error:",e.message),"EADDRINUSE"==e.code&&process.exit()})),this.wss.on("close",(e=>{console.log("### WS server closed.",e)})),this.wss.on("connection",((e,t)=>{e.socketType="websocket",this.manager.addRemote(e,t)}))}startCongServer(e){console.log("opening CongSocket Server:",e),this.congServer=i.createServer((e=>{this.manager.addRemote(e)})).on("error",(e=>{console.log("### cong server error:",e.message),"EADDRINUSE"==e.code&&process.exit()})).listen(e,(()=>{}))}api(e,t){if(this.apiNames.add(e),!t.checkPermission||"function"!=typeof t.checkPermission)throw new Error("wrong api interface. no checkPermission function.");if("function"==typeof t.request&&Array.isArray(t.commands))console.log(`API TYPE1. A Class with one request function. target: ${e} list: ${t.commands}`),this.on(e,((e,r)=>{t.checkPermission(e,r)?t.request(e,r):e.response(r.mid,Nr,"NO_PERMISSION.")}));else{let r=[];Object.keys(t).forEach((e=>{"function"==typeof t[e]&&r.push(e),console.log("api list",typeof t[e],e)})),console.log(`API TYPE2. Multiple function list. target: ${e} list:${r}`),this.on(e,((r,n)=>{let i;if(t.checkPermission(r,n)){if(t[n.topic])return console.log(`API TYPE2. request target: ${e} has topic:${n.topic}`),void t[n.topic](r,n);i=`target: ${n.target} has not topic name: ${n.topic}`}else i="NO_PERMISSION.";r.response(n.mid,Nr,i)}))}return this}},exports.api_reply=$r,exports.api_sudo=Fr,exports.getPayloadFromSignalPack=function(e){let t=e.readUint8(1);return e.subarray(3+t)},exports.getSignalPack=ae,exports.pack=wt,exports.parsePayload=he,exports.serverOption=Br,exports.version="2.2.1";