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