From 78df62878c96c614abe54f2d88501dc65330f989 Mon Sep 17 00:00:00 2001 From: masoud13632020 Date: Tue, 24 Dec 2024 01:18:01 +0330 Subject: [PATCH 1/2] masoud --- masoud001.js | 9488 +++++++++++++++++ ...16\346\226\207\346\272\220\347\240\201.js" | 2184 ---- 2 files changed, 9488 insertions(+), 2184 deletions(-) create mode 100644 masoud001.js delete mode 100644 "\346\230\216\346\226\207\346\272\220\347\240\201.js" diff --git a/masoud001.js b/masoud001.js new file mode 100644 index 000000000..8b659e085 --- /dev/null +++ b/masoud001.js @@ -0,0 +1,9488 @@ +/*! + * v2ray Subscription Worker v2.4 + * Copyright 2024 Vahid Farid (https://twitter.com/vahidfarid) + * Licensed under GPLv3 (https://github.com/vfarid/v2ray-worker/blob/main/Licence.md) + */ + +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") + return require.apply(this, arguments); + throw new Error('Dynamic require of "' + x + '" is not supported'); +}); +var __esm = (fn, res) => function __init() { + return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; +}; +var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); + +// wrangler-modules-watch:wrangler:modules-watch +var init_wrangler_modules_watch = __esm({ + "wrangler-modules-watch:wrangler:modules-watch"() { + init_modules_watch_stub(); + } +}); + +// node_modules/wrangler/templates/modules-watch-stub.js +var init_modules_watch_stub = __esm({ + "node_modules/wrangler/templates/modules-watch-stub.js"() { + init_wrangler_modules_watch(); + } +}); + +// (disabled):crypto +var require_crypto = __commonJS({ + "(disabled):crypto"() { + init_modules_watch_stub(); + } +}); + +// node_modules/crypto-js/core.js +var require_core = __commonJS({ + "node_modules/crypto-js/core.js"(exports, module) { + init_modules_watch_stub(); + (function(root, factory) { + if (typeof exports === "object") { + module.exports = exports = factory(); + } else if (typeof define === "function" && define.amd) { + define([], factory); + } else { + root.CryptoJS = factory(); + } + })(exports, function() { + var CryptoJS = CryptoJS || function(Math2, undefined2) { + var crypto; + if (typeof window !== "undefined" && window.crypto) { + crypto = window.crypto; + } + if (typeof self !== "undefined" && self.crypto) { + crypto = self.crypto; + } + if (typeof globalThis !== "undefined" && globalThis.crypto) { + crypto = globalThis.crypto; + } + if (!crypto && typeof window !== "undefined" && window.msCrypto) { + crypto = window.msCrypto; + } + if (!crypto && typeof global !== "undefined" && global.crypto) { + crypto = global.crypto; + } + if (!crypto && typeof __require === "function") { + try { + crypto = require_crypto(); + } catch (err) { + } + } + var cryptoSecureRandomInt = function() { + if (crypto) { + if (typeof crypto.getRandomValues === "function") { + try { + return crypto.getRandomValues(new Uint32Array(1))[0]; + } catch (err) { + } + } + if (typeof crypto.randomBytes === "function") { + try { + return crypto.randomBytes(4).readInt32LE(); + } catch (err) { + } + } + } + throw new Error("Native crypto module could not be used to get secure random number."); + }; + var create = Object.create || function() { + function F() { + } + return function(obj) { + var subtype; + F.prototype = obj; + subtype = new F(); + F.prototype = null; + return subtype; + }; + }(); + var C = {}; + var C_lib = C.lib = {}; + var Base = C_lib.Base = function() { + return { + /** + * Creates a new object that inherits from this object. + * + * @param {Object} overrides Properties to copy into the new object. + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * field: 'value', + * + * method: function () { + * } + * }); + */ + extend: function(overrides) { + var subtype = create(this); + if (overrides) { + subtype.mixIn(overrides); + } + if (!subtype.hasOwnProperty("init") || this.init === subtype.init) { + subtype.init = function() { + subtype.$super.init.apply(this, arguments); + }; + } + subtype.init.prototype = subtype; + subtype.$super = this; + return subtype; + }, + /** + * Extends this object and runs the init method. + * Arguments to create() will be passed to init(). + * + * @return {Object} The new object. + * + * @static + * + * @example + * + * var instance = MyType.create(); + */ + create: function() { + var instance = this.extend(); + instance.init.apply(instance, arguments); + return instance; + }, + /** + * Initializes a newly created object. + * Override this method to add some logic when your objects are created. + * + * @example + * + * var MyType = CryptoJS.lib.Base.extend({ + * init: function () { + * // ... + * } + * }); + */ + init: function() { + }, + /** + * Copies properties into this object. + * + * @param {Object} properties The properties to mix in. + * + * @example + * + * MyType.mixIn({ + * field: 'value' + * }); + */ + mixIn: function(properties) { + for (var propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + this[propertyName] = properties[propertyName]; + } + } + if (properties.hasOwnProperty("toString")) { + this.toString = properties.toString; + } + }, + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = instance.clone(); + */ + clone: function() { + return this.init.prototype.extend(this); + } + }; + }(); + var WordArray = C_lib.WordArray = Base.extend({ + /** + * Initializes a newly created word array. + * + * @param {Array} words (Optional) An array of 32-bit words. + * @param {number} sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.create(); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); + * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); + */ + init: function(words, sigBytes) { + words = this.words = words || []; + if (sigBytes != undefined2) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 4; + } + }, + /** + * Converts this word array to a string. + * + * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return {string} The stringified word array. + * + * @example + * + * var string = wordArray + ''; + * var string = wordArray.toString(); + * var string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString: function(encoder) { + return (encoder || Hex).stringify(this); + }, + /** + * Concatenates a word array to this word array. + * + * @param {WordArray} wordArray The word array to append. + * + * @return {WordArray} This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat: function(wordArray) { + var thisWords = this.words; + var thatWords = wordArray.words; + var thisSigBytes = this.sigBytes; + var thatSigBytes = wordArray.sigBytes; + this.clamp(); + if (thisSigBytes % 4) { + for (var i = 0; i < thatSigBytes; i++) { + var thatByte = thatWords[i >>> 2] >>> 24 - i % 4 * 8 & 255; + thisWords[thisSigBytes + i >>> 2] |= thatByte << 24 - (thisSigBytes + i) % 4 * 8; + } + } else { + for (var j = 0; j < thatSigBytes; j += 4) { + thisWords[thisSigBytes + j >>> 2] = thatWords[j >>> 2]; + } + } + this.sigBytes += thatSigBytes; + return this; + }, + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp: function() { + var words = this.words; + var sigBytes = this.sigBytes; + words[sigBytes >>> 2] &= 4294967295 << 32 - sigBytes % 4 * 8; + words.length = Math2.ceil(sigBytes / 4); + }, + /** + * Creates a copy of this word array. + * + * @return {WordArray} The clone. + * + * @example + * + * var clone = wordArray.clone(); + */ + clone: function() { + var clone = Base.clone.call(this); + clone.words = this.words.slice(0); + return clone; + }, + /** + * Creates a word array filled with random bytes. + * + * @param {number} nBytes The number of random bytes to generate. + * + * @return {WordArray} The random word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.lib.WordArray.random(16); + */ + random: function(nBytes) { + var words = []; + for (var i = 0; i < nBytes; i += 4) { + words.push(cryptoSecureRandomInt()); + } + return new WordArray.init(words, nBytes); + } + }); + var C_enc = C.enc = {}; + var Hex = C_enc.Hex = { + /** + * Converts a word array to a hex string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The hex string. + * + * @static + * + * @example + * + * var hexString = CryptoJS.enc.Hex.stringify(wordArray); + */ + stringify: function(wordArray) { + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var hexChars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 15).toString(16)); + } + return hexChars.join(""); + }, + /** + * Converts a hex string to a word array. + * + * @param {string} hexStr The hex string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Hex.parse(hexString); + */ + parse: function(hexStr) { + var hexStrLength = hexStr.length; + var words = []; + for (var i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << 24 - i % 8 * 4; + } + return new WordArray.init(words, hexStrLength / 2); + } + }; + var Latin1 = C_enc.Latin1 = { + /** + * Converts a word array to a Latin1 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The Latin1 string. + * + * @static + * + * @example + * + * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); + */ + stringify: function(wordArray) { + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var latin1Chars = []; + for (var i = 0; i < sigBytes; i++) { + var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255; + latin1Chars.push(String.fromCharCode(bite)); + } + return latin1Chars.join(""); + }, + /** + * Converts a Latin1 string to a word array. + * + * @param {string} latin1Str The Latin1 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); + */ + parse: function(latin1Str) { + var latin1StrLength = latin1Str.length; + var words = []; + for (var i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8; + } + return new WordArray.init(words, latin1StrLength); + } + }; + var Utf8 = C_enc.Utf8 = { + /** + * Converts a word array to a UTF-8 string. + * + * @param {WordArray} wordArray The word array. + * + * @return {string} The UTF-8 string. + * + * @static + * + * @example + * + * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); + */ + stringify: function(wordArray) { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch (e) { + throw new Error("Malformed UTF-8 data"); + } + }, + /** + * Converts a UTF-8 string to a word array. + * + * @param {string} utf8Str The UTF-8 string. + * + * @return {WordArray} The word array. + * + * @static + * + * @example + * + * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); + */ + parse: function(utf8Str) { + return Latin1.parse(unescape(encodeURIComponent(utf8Str))); + } + }; + var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset: function() { + this._data = new WordArray.init(); + this._nDataBytes = 0; + }, + /** + * Adds new data to this block algorithm's buffer. + * + * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append: function(data) { + if (typeof data == "string") { + data = Utf8.parse(data); + } + this._data.concat(data); + this._nDataBytes += data.sigBytes; + }, + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. + * + * @return {WordArray} The processed data. + * + * @example + * + * var processedData = bufferedBlockAlgorithm._process(); + * var processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process: function(doFlush) { + var processedWords; + var data = this._data; + var dataWords = data.words; + var dataSigBytes = data.sigBytes; + var blockSize = this.blockSize; + var blockSizeBytes = blockSize * 4; + var nBlocksReady = dataSigBytes / blockSizeBytes; + if (doFlush) { + nBlocksReady = Math2.ceil(nBlocksReady); + } else { + nBlocksReady = Math2.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + var nWordsReady = nBlocksReady * blockSize; + var nBytesReady = Math2.min(nWordsReady * 4, dataSigBytes); + if (nWordsReady) { + for (var offset = 0; offset < nWordsReady; offset += blockSize) { + this._doProcessBlock(dataWords, offset); + } + processedWords = dataWords.splice(0, nWordsReady); + data.sigBytes -= nBytesReady; + } + return new WordArray.init(processedWords, nBytesReady); + }, + /** + * Creates a copy of this object. + * + * @return {Object} The clone. + * + * @example + * + * var clone = bufferedBlockAlgorithm.clone(); + */ + clone: function() { + var clone = Base.clone.call(this); + clone._data = this._data.clone(); + return clone; + }, + _minBufferSize: 0 + }); + var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ + /** + * Configuration options. + */ + cfg: Base.extend(), + /** + * Initializes a newly created hasher. + * + * @param {Object} cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * var hasher = CryptoJS.algo.SHA256.create(); + */ + init: function(cfg) { + this.cfg = this.cfg.extend(cfg); + this.reset(); + }, + /** + * Resets this hasher to its initial state. + * + * @example + * + * hasher.reset(); + */ + reset: function() { + BufferedBlockAlgorithm.reset.call(this); + this._doReset(); + }, + /** + * Updates this hasher with a message. + * + * @param {WordArray|string} messageUpdate The message to append. + * + * @return {Hasher} This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update: function(messageUpdate) { + this._append(messageUpdate); + this._process(); + return this; + }, + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The hash. + * + * @example + * + * var hash = hasher.finalize(); + * var hash = hasher.finalize('message'); + * var hash = hasher.finalize(wordArray); + */ + finalize: function(messageUpdate) { + if (messageUpdate) { + this._append(messageUpdate); + } + var hash2 = this._doFinalize(); + return hash2; + }, + blockSize: 512 / 32, + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param {Hasher} hasher The hasher to create a helper for. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); + */ + _createHelper: function(hasher) { + return function(message, cfg) { + return new hasher.init(cfg).finalize(message); + }; + }, + /** + * Creates a shortcut function to the HMAC's object interface. + * + * @param {Hasher} hasher The hasher to use in this HMAC helper. + * + * @return {Function} The shortcut function. + * + * @static + * + * @example + * + * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); + */ + _createHmacHelper: function(hasher) { + return function(message, key) { + return new C_algo.HMAC.init(hasher, key).finalize(message); + }; + } + }); + var C_algo = C.algo = {}; + return C; + }(Math); + return CryptoJS; + }); + } +}); + +// node_modules/crypto-js/sha256.js +var require_sha256 = __commonJS({ + "node_modules/crypto-js/sha256.js"(exports, module) { + init_modules_watch_stub(); + (function(root, factory) { + if (typeof exports === "object") { + module.exports = exports = factory(require_core()); + } else if (typeof define === "function" && define.amd) { + define(["./core"], factory); + } else { + factory(root.CryptoJS); + } + })(exports, function(CryptoJS) { + (function(Math2) { + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var Hasher = C_lib.Hasher; + var C_algo = C.algo; + var H = []; + var K = []; + (function() { + function isPrime(n2) { + var sqrtN = Math2.sqrt(n2); + for (var factor = 2; factor <= sqrtN; factor++) { + if (!(n2 % factor)) { + return false; + } + } + return true; + } + function getFractionalBits(n2) { + return (n2 - (n2 | 0)) * 4294967296 | 0; + } + var n = 2; + var nPrime = 0; + while (nPrime < 64) { + if (isPrime(n)) { + if (nPrime < 8) { + H[nPrime] = getFractionalBits(Math2.pow(n, 1 / 2)); + } + K[nPrime] = getFractionalBits(Math2.pow(n, 1 / 3)); + nPrime++; + } + n++; + } + })(); + var W = []; + var SHA256 = C_algo.SHA256 = Hasher.extend({ + _doReset: function() { + this._hash = new WordArray.init(H.slice(0)); + }, + _doProcessBlock: function(M, offset) { + var H2 = this._hash.words; + var a = H2[0]; + var b = H2[1]; + var c = H2[2]; + var d = H2[3]; + var e = H2[4]; + var f2 = H2[5]; + var g = H2[6]; + var h = H2[7]; + for (var i = 0; i < 64; i++) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + var gamma0x = W[i - 15]; + var gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3; + var gamma1x = W[i - 2]; + var gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10; + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; + } + var ch = e & f2 ^ ~e & g; + var maj = a & b ^ a & c ^ b & c; + var sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22); + var sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25); + var t1 = h + sigma1 + ch + K[i] + W[i]; + var t2 = sigma0 + maj; + h = g; + g = f2; + f2 = e; + e = d + t1 | 0; + d = c; + c = b; + b = a; + a = t1 + t2 | 0; + } + H2[0] = H2[0] + a | 0; + H2[1] = H2[1] + b | 0; + H2[2] = H2[2] + c | 0; + H2[3] = H2[3] + d | 0; + H2[4] = H2[4] + e | 0; + H2[5] = H2[5] + f2 | 0; + H2[6] = H2[6] + g | 0; + H2[7] = H2[7] + h | 0; + }, + _doFinalize: function() { + var data = this._data; + var dataWords = data.words; + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32; + dataWords[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math2.floor(nBitsTotal / 4294967296); + dataWords[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + this._process(); + return this._hash; + }, + clone: function() { + var clone = Hasher.clone.call(this); + clone._hash = this._hash.clone(); + return clone; + } + }); + C.SHA256 = Hasher._createHelper(SHA256); + C.HmacSHA256 = Hasher._createHmacHelper(SHA256); + })(Math); + return CryptoJS.SHA256; + }); + } +}); + +// node_modules/crypto-js/sha224.js +var require_sha224 = __commonJS({ + "node_modules/crypto-js/sha224.js"(exports, module) { + init_modules_watch_stub(); + (function(root, factory, undef) { + if (typeof exports === "object") { + module.exports = exports = factory(require_core(), require_sha256()); + } else if (typeof define === "function" && define.amd) { + define(["./core", "./sha256"], factory); + } else { + factory(root.CryptoJS); + } + })(exports, function(CryptoJS) { + (function() { + var C = CryptoJS; + var C_lib = C.lib; + var WordArray = C_lib.WordArray; + var C_algo = C.algo; + var SHA256 = C_algo.SHA256; + var SHA224 = C_algo.SHA224 = SHA256.extend({ + _doReset: function() { + this._hash = new WordArray.init([ + 3238371032, + 914150663, + 812702999, + 4144912697, + 4290775857, + 1750603025, + 1694076839, + 3204075428 + ]); + }, + _doFinalize: function() { + var hash2 = SHA256._doFinalize.call(this); + hash2.sigBytes -= 4; + return hash2; + } + }); + C.SHA224 = SHA256._createHelper(SHA224); + C.HmacSHA224 = SHA256._createHmacHelper(SHA224); + })(); + return CryptoJS.SHA224; + }); + } +}); + +// node_modules/crypto-js/enc-hex.js +var require_enc_hex = __commonJS({ + "node_modules/crypto-js/enc-hex.js"(exports, module) { + init_modules_watch_stub(); + (function(root, factory) { + if (typeof exports === "object") { + module.exports = exports = factory(require_core()); + } else if (typeof define === "function" && define.amd) { + define(["./core"], factory); + } else { + factory(root.CryptoJS); + } + })(exports, function(CryptoJS) { + return CryptoJS.enc.Hex; + }); + } +}); + +// node_modules/bcryptjs/dist/bcrypt.js +var require_bcrypt = __commonJS({ + "node_modules/bcryptjs/dist/bcrypt.js"(exports, module) { + init_modules_watch_stub(); + (function(global2, factory) { + if (typeof define === "function" && define["amd"]) + define([], factory); + else if (typeof __require === "function" && typeof module === "object" && module && module["exports"]) + module["exports"] = factory(); + else + (global2["dcodeIO"] = global2["dcodeIO"] || {})["bcrypt"] = factory(); + })(exports, function() { + "use strict"; + var bcrypt3 = {}; + var randomFallback = null; + function random(len) { + if (typeof module !== "undefined" && module && module["exports"]) + try { + return __require("crypto")["randomBytes"](len); + } catch (e) { + } + try { + var a; + (self["crypto"] || self["msCrypto"])["getRandomValues"](a = new Uint32Array(len)); + return Array.prototype.slice.call(a); + } catch (e) { + } + if (!randomFallback) + throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative"); + return randomFallback(len); + } + var randomAvailable = false; + try { + random(1); + randomAvailable = true; + } catch (e) { + } + randomFallback = null; + bcrypt3.setRandomFallback = function(random2) { + randomFallback = random2; + }; + bcrypt3.genSaltSync = function(rounds, seed_length) { + rounds = rounds || GENSALT_DEFAULT_LOG2_ROUNDS; + if (typeof rounds !== "number") + throw Error("Illegal arguments: " + typeof rounds + ", " + typeof seed_length); + if (rounds < 4) + rounds = 4; + else if (rounds > 31) + rounds = 31; + var salt = []; + salt.push("$2a$"); + if (rounds < 10) + salt.push("0"); + salt.push(rounds.toString()); + salt.push("$"); + salt.push(base64_encode(random(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); + return salt.join(""); + }; + bcrypt3.genSalt = function(rounds, seed_length, callback) { + if (typeof seed_length === "function") + callback = seed_length, seed_length = void 0; + if (typeof rounds === "function") + callback = rounds, rounds = void 0; + if (typeof rounds === "undefined") + rounds = GENSALT_DEFAULT_LOG2_ROUNDS; + else if (typeof rounds !== "number") + throw Error("illegal arguments: " + typeof rounds); + function _async(callback2) { + nextTick(function() { + try { + callback2(null, bcrypt3.genSaltSync(rounds)); + } catch (err) { + callback2(err); + } + }); + } + if (callback) { + if (typeof callback !== "function") + throw Error("Illegal callback: " + typeof callback); + _async(callback); + } else + return new Promise(function(resolve, reject) { + _async(function(err, res) { + if (err) { + reject(err); + return; + } + resolve(res); + }); + }); + }; + bcrypt3.hashSync = function(s, salt) { + if (typeof salt === "undefined") + salt = GENSALT_DEFAULT_LOG2_ROUNDS; + if (typeof salt === "number") + salt = bcrypt3.genSaltSync(salt); + if (typeof s !== "string" || typeof salt !== "string") + throw Error("Illegal arguments: " + typeof s + ", " + typeof salt); + return _hash(s, salt); + }; + bcrypt3.hash = function(s, salt, callback, progressCallback) { + function _async(callback2) { + if (typeof s === "string" && typeof salt === "number") + bcrypt3.genSalt(salt, function(err, salt2) { + _hash(s, salt2, callback2, progressCallback); + }); + else if (typeof s === "string" && typeof salt === "string") + _hash(s, salt, callback2, progressCallback); + else + nextTick(callback2.bind(this, Error("Illegal arguments: " + typeof s + ", " + typeof salt))); + } + if (callback) { + if (typeof callback !== "function") + throw Error("Illegal callback: " + typeof callback); + _async(callback); + } else + return new Promise(function(resolve, reject) { + _async(function(err, res) { + if (err) { + reject(err); + return; + } + resolve(res); + }); + }); + }; + function safeStringCompare(known, unknown) { + var right = 0, wrong = 0; + for (var i = 0, k = known.length; i < k; ++i) { + if (known.charCodeAt(i) === unknown.charCodeAt(i)) + ++right; + else + ++wrong; + } + if (right < 0) + return false; + return wrong === 0; + } + bcrypt3.compareSync = function(s, hash2) { + if (typeof s !== "string" || typeof hash2 !== "string") + throw Error("Illegal arguments: " + typeof s + ", " + typeof hash2); + if (hash2.length !== 60) + return false; + return safeStringCompare(bcrypt3.hashSync(s, hash2.substr(0, hash2.length - 31)), hash2); + }; + bcrypt3.compare = function(s, hash2, callback, progressCallback) { + function _async(callback2) { + if (typeof s !== "string" || typeof hash2 !== "string") { + nextTick(callback2.bind(this, Error("Illegal arguments: " + typeof s + ", " + typeof hash2))); + return; + } + if (hash2.length !== 60) { + nextTick(callback2.bind(this, null, false)); + return; + } + bcrypt3.hash(s, hash2.substr(0, 29), function(err, comp) { + if (err) + callback2(err); + else + callback2(null, safeStringCompare(comp, hash2)); + }, progressCallback); + } + if (callback) { + if (typeof callback !== "function") + throw Error("Illegal callback: " + typeof callback); + _async(callback); + } else + return new Promise(function(resolve, reject) { + _async(function(err, res) { + if (err) { + reject(err); + return; + } + resolve(res); + }); + }); + }; + bcrypt3.getRounds = function(hash2) { + if (typeof hash2 !== "string") + throw Error("Illegal arguments: " + typeof hash2); + return parseInt(hash2.split("$")[2], 10); + }; + bcrypt3.getSalt = function(hash2) { + if (typeof hash2 !== "string") + throw Error("Illegal arguments: " + typeof hash2); + if (hash2.length !== 60) + throw Error("Illegal hash length: " + hash2.length + " != 60"); + return hash2.substring(0, 29); + }; + var nextTick = typeof process !== "undefined" && process && typeof process.nextTick === "function" ? typeof setImmediate === "function" ? setImmediate : process.nextTick : setTimeout; + function stringToBytes2(str2) { + var out = [], i = 0; + utfx.encodeUTF16toUTF8(function() { + if (i >= str2.length) + return null; + return str2.charCodeAt(i++); + }, function(b) { + out.push(b); + }); + return out; + } + var BASE64_CODE = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""); + var BASE64_INDEX = [ + -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, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 0, + 1, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + -1, + -1, + -1, + -1, + -1, + -1, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + -1, + -1, + -1, + -1, + -1 + ]; + var stringFromCharCode = String.fromCharCode; + function base64_encode(b, len) { + var off = 0, rs = [], c1, c2; + if (len <= 0 || len > b.length) + throw Error("Illegal len: " + len); + while (off < len) { + c1 = b[off++] & 255; + rs.push(BASE64_CODE[c1 >> 2 & 63]); + c1 = (c1 & 3) << 4; + if (off >= len) { + rs.push(BASE64_CODE[c1 & 63]); + break; + } + c2 = b[off++] & 255; + c1 |= c2 >> 4 & 15; + rs.push(BASE64_CODE[c1 & 63]); + c1 = (c2 & 15) << 2; + if (off >= len) { + rs.push(BASE64_CODE[c1 & 63]); + break; + } + c2 = b[off++] & 255; + c1 |= c2 >> 6 & 3; + rs.push(BASE64_CODE[c1 & 63]); + rs.push(BASE64_CODE[c2 & 63]); + } + return rs.join(""); + } + function base64_decode(s, len) { + var off = 0, slen = s.length, olen = 0, rs = [], c1, c2, c3, c4, o, code; + if (len <= 0) + throw Error("Illegal len: " + len); + while (off < slen - 1 && olen < len) { + code = s.charCodeAt(off++); + c1 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; + code = s.charCodeAt(off++); + c2 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; + if (c1 == -1 || c2 == -1) + break; + o = c1 << 2 >>> 0; + o |= (c2 & 48) >> 4; + rs.push(stringFromCharCode(o)); + if (++olen >= len || off >= slen) + break; + code = s.charCodeAt(off++); + c3 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; + if (c3 == -1) + break; + o = (c2 & 15) << 4 >>> 0; + o |= (c3 & 60) >> 2; + rs.push(stringFromCharCode(o)); + if (++olen >= len || off >= slen) + break; + code = s.charCodeAt(off++); + c4 = code < BASE64_INDEX.length ? BASE64_INDEX[code] : -1; + o = (c3 & 3) << 6 >>> 0; + o |= c4; + rs.push(stringFromCharCode(o)); + ++olen; + } + var res = []; + for (off = 0; off < olen; off++) + res.push(rs[off].charCodeAt(0)); + return res; + } + var utfx = function() { + "use strict"; + var utfx2 = {}; + utfx2.MAX_CODEPOINT = 1114111; + utfx2.encodeUTF8 = function(src, dst) { + var cp = null; + if (typeof src === "number") + cp = src, src = function() { + return null; + }; + while (cp !== null || (cp = src()) !== null) { + if (cp < 128) + dst(cp & 127); + else if (cp < 2048) + dst(cp >> 6 & 31 | 192), dst(cp & 63 | 128); + else if (cp < 65536) + dst(cp >> 12 & 15 | 224), dst(cp >> 6 & 63 | 128), dst(cp & 63 | 128); + else + dst(cp >> 18 & 7 | 240), dst(cp >> 12 & 63 | 128), dst(cp >> 6 & 63 | 128), dst(cp & 63 | 128); + cp = null; + } + }; + utfx2.decodeUTF8 = function(src, dst) { + var a, b, c, d, fail = function(b2) { + b2 = b2.slice(0, b2.indexOf(null)); + var err = Error(b2.toString()); + err.name = "TruncatedError"; + err["bytes"] = b2; + throw err; + }; + while ((a = src()) !== null) { + if ((a & 128) === 0) + dst(a); + else if ((a & 224) === 192) + (b = src()) === null && fail([a, b]), dst((a & 31) << 6 | b & 63); + else if ((a & 240) === 224) + ((b = src()) === null || (c = src()) === null) && fail([a, b, c]), dst((a & 15) << 12 | (b & 63) << 6 | c & 63); + else if ((a & 248) === 240) + ((b = src()) === null || (c = src()) === null || (d = src()) === null) && fail([a, b, c, d]), dst((a & 7) << 18 | (b & 63) << 12 | (c & 63) << 6 | d & 63); + else + throw RangeError("Illegal starting byte: " + a); + } + }; + utfx2.UTF16toUTF8 = function(src, dst) { + var c1, c2 = null; + while (true) { + if ((c1 = c2 !== null ? c2 : src()) === null) + break; + if (c1 >= 55296 && c1 <= 57343) { + if ((c2 = src()) !== null) { + if (c2 >= 56320 && c2 <= 57343) { + dst((c1 - 55296) * 1024 + c2 - 56320 + 65536); + c2 = null; + continue; + } + } + } + dst(c1); + } + if (c2 !== null) + dst(c2); + }; + utfx2.UTF8toUTF16 = function(src, dst) { + var cp = null; + if (typeof src === "number") + cp = src, src = function() { + return null; + }; + while (cp !== null || (cp = src()) !== null) { + if (cp <= 65535) + dst(cp); + else + cp -= 65536, dst((cp >> 10) + 55296), dst(cp % 1024 + 56320); + cp = null; + } + }; + utfx2.encodeUTF16toUTF8 = function(src, dst) { + utfx2.UTF16toUTF8(src, function(cp) { + utfx2.encodeUTF8(cp, dst); + }); + }; + utfx2.decodeUTF8toUTF16 = function(src, dst) { + utfx2.decodeUTF8(src, function(cp) { + utfx2.UTF8toUTF16(cp, dst); + }); + }; + utfx2.calculateCodePoint = function(cp) { + return cp < 128 ? 1 : cp < 2048 ? 2 : cp < 65536 ? 3 : 4; + }; + utfx2.calculateUTF8 = function(src) { + var cp, l = 0; + while ((cp = src()) !== null) + l += utfx2.calculateCodePoint(cp); + return l; + }; + utfx2.calculateUTF16asUTF8 = function(src) { + var n = 0, l = 0; + utfx2.UTF16toUTF8(src, function(cp) { + ++n; + l += utfx2.calculateCodePoint(cp); + }); + return [n, l]; + }; + return utfx2; + }(); + Date.now = Date.now || function() { + return +/* @__PURE__ */ new Date(); + }; + var BCRYPT_SALT_LEN = 16; + var GENSALT_DEFAULT_LOG2_ROUNDS = 10; + var BLOWFISH_NUM_ROUNDS = 16; + var MAX_EXECUTION_TIME = 100; + var P_ORIG = [ + 608135816, + 2242054355, + 320440878, + 57701188, + 2752067618, + 698298832, + 137296536, + 3964562569, + 1160258022, + 953160567, + 3193202383, + 887688300, + 3232508343, + 3380367581, + 1065670069, + 3041331479, + 2450970073, + 2306472731 + ]; + var S_ORIG = [ + 3509652390, + 2564797868, + 805139163, + 3491422135, + 3101798381, + 1780907670, + 3128725573, + 4046225305, + 614570311, + 3012652279, + 134345442, + 2240740374, + 1667834072, + 1901547113, + 2757295779, + 4103290238, + 227898511, + 1921955416, + 1904987480, + 2182433518, + 2069144605, + 3260701109, + 2620446009, + 720527379, + 3318853667, + 677414384, + 3393288472, + 3101374703, + 2390351024, + 1614419982, + 1822297739, + 2954791486, + 3608508353, + 3174124327, + 2024746970, + 1432378464, + 3864339955, + 2857741204, + 1464375394, + 1676153920, + 1439316330, + 715854006, + 3033291828, + 289532110, + 2706671279, + 2087905683, + 3018724369, + 1668267050, + 732546397, + 1947742710, + 3462151702, + 2609353502, + 2950085171, + 1814351708, + 2050118529, + 680887927, + 999245976, + 1800124847, + 3300911131, + 1713906067, + 1641548236, + 4213287313, + 1216130144, + 1575780402, + 4018429277, + 3917837745, + 3693486850, + 3949271944, + 596196993, + 3549867205, + 258830323, + 2213823033, + 772490370, + 2760122372, + 1774776394, + 2652871518, + 566650946, + 4142492826, + 1728879713, + 2882767088, + 1783734482, + 3629395816, + 2517608232, + 2874225571, + 1861159788, + 326777828, + 3124490320, + 2130389656, + 2716951837, + 967770486, + 1724537150, + 2185432712, + 2364442137, + 1164943284, + 2105845187, + 998989502, + 3765401048, + 2244026483, + 1075463327, + 1455516326, + 1322494562, + 910128902, + 469688178, + 1117454909, + 936433444, + 3490320968, + 3675253459, + 1240580251, + 122909385, + 2157517691, + 634681816, + 4142456567, + 3825094682, + 3061402683, + 2540495037, + 79693498, + 3249098678, + 1084186820, + 1583128258, + 426386531, + 1761308591, + 1047286709, + 322548459, + 995290223, + 1845252383, + 2603652396, + 3431023940, + 2942221577, + 3202600964, + 3727903485, + 1712269319, + 422464435, + 3234572375, + 1170764815, + 3523960633, + 3117677531, + 1434042557, + 442511882, + 3600875718, + 1076654713, + 1738483198, + 4213154764, + 2393238008, + 3677496056, + 1014306527, + 4251020053, + 793779912, + 2902807211, + 842905082, + 4246964064, + 1395751752, + 1040244610, + 2656851899, + 3396308128, + 445077038, + 3742853595, + 3577915638, + 679411651, + 2892444358, + 2354009459, + 1767581616, + 3150600392, + 3791627101, + 3102740896, + 284835224, + 4246832056, + 1258075500, + 768725851, + 2589189241, + 3069724005, + 3532540348, + 1274779536, + 3789419226, + 2764799539, + 1660621633, + 3471099624, + 4011903706, + 913787905, + 3497959166, + 737222580, + 2514213453, + 2928710040, + 3937242737, + 1804850592, + 3499020752, + 2949064160, + 2386320175, + 2390070455, + 2415321851, + 4061277028, + 2290661394, + 2416832540, + 1336762016, + 1754252060, + 3520065937, + 3014181293, + 791618072, + 3188594551, + 3933548030, + 2332172193, + 3852520463, + 3043980520, + 413987798, + 3465142937, + 3030929376, + 4245938359, + 2093235073, + 3534596313, + 375366246, + 2157278981, + 2479649556, + 555357303, + 3870105701, + 2008414854, + 3344188149, + 4221384143, + 3956125452, + 2067696032, + 3594591187, + 2921233993, + 2428461, + 544322398, + 577241275, + 1471733935, + 610547355, + 4027169054, + 1432588573, + 1507829418, + 2025931657, + 3646575487, + 545086370, + 48609733, + 2200306550, + 1653985193, + 298326376, + 1316178497, + 3007786442, + 2064951626, + 458293330, + 2589141269, + 3591329599, + 3164325604, + 727753846, + 2179363840, + 146436021, + 1461446943, + 4069977195, + 705550613, + 3059967265, + 3887724982, + 4281599278, + 3313849956, + 1404054877, + 2845806497, + 146425753, + 1854211946, + 1266315497, + 3048417604, + 3681880366, + 3289982499, + 290971e4, + 1235738493, + 2632868024, + 2414719590, + 3970600049, + 1771706367, + 1449415276, + 3266420449, + 422970021, + 1963543593, + 2690192192, + 3826793022, + 1062508698, + 1531092325, + 1804592342, + 2583117782, + 2714934279, + 4024971509, + 1294809318, + 4028980673, + 1289560198, + 2221992742, + 1669523910, + 35572830, + 157838143, + 1052438473, + 1016535060, + 1802137761, + 1753167236, + 1386275462, + 3080475397, + 2857371447, + 1040679964, + 2145300060, + 2390574316, + 1461121720, + 2956646967, + 4031777805, + 4028374788, + 33600511, + 2920084762, + 1018524850, + 629373528, + 3691585981, + 3515945977, + 2091462646, + 2486323059, + 586499841, + 988145025, + 935516892, + 3367335476, + 2599673255, + 2839830854, + 265290510, + 3972581182, + 2759138881, + 3795373465, + 1005194799, + 847297441, + 406762289, + 1314163512, + 1332590856, + 1866599683, + 4127851711, + 750260880, + 613907577, + 1450815602, + 3165620655, + 3734664991, + 3650291728, + 3012275730, + 3704569646, + 1427272223, + 778793252, + 1343938022, + 2676280711, + 2052605720, + 1946737175, + 3164576444, + 3914038668, + 3967478842, + 3682934266, + 1661551462, + 3294938066, + 4011595847, + 840292616, + 3712170807, + 616741398, + 312560963, + 711312465, + 1351876610, + 322626781, + 1910503582, + 271666773, + 2175563734, + 1594956187, + 70604529, + 3617834859, + 1007753275, + 1495573769, + 4069517037, + 2549218298, + 2663038764, + 504708206, + 2263041392, + 3941167025, + 2249088522, + 1514023603, + 1998579484, + 1312622330, + 694541497, + 2582060303, + 2151582166, + 1382467621, + 776784248, + 2618340202, + 3323268794, + 2497899128, + 2784771155, + 503983604, + 4076293799, + 907881277, + 423175695, + 432175456, + 1378068232, + 4145222326, + 3954048622, + 3938656102, + 3820766613, + 2793130115, + 2977904593, + 26017576, + 3274890735, + 3194772133, + 1700274565, + 1756076034, + 4006520079, + 3677328699, + 720338349, + 1533947780, + 354530856, + 688349552, + 3973924725, + 1637815568, + 332179504, + 3949051286, + 53804574, + 2852348879, + 3044236432, + 1282449977, + 3583942155, + 3416972820, + 4006381244, + 1617046695, + 2628476075, + 3002303598, + 1686838959, + 431878346, + 2686675385, + 1700445008, + 1080580658, + 1009431731, + 832498133, + 3223435511, + 2605976345, + 2271191193, + 2516031870, + 1648197032, + 4164389018, + 2548247927, + 300782431, + 375919233, + 238389289, + 3353747414, + 2531188641, + 2019080857, + 1475708069, + 455242339, + 2609103871, + 448939670, + 3451063019, + 1395535956, + 2413381860, + 1841049896, + 1491858159, + 885456874, + 4264095073, + 4001119347, + 1565136089, + 3898914787, + 1108368660, + 540939232, + 1173283510, + 2745871338, + 3681308437, + 4207628240, + 3343053890, + 4016749493, + 1699691293, + 1103962373, + 3625875870, + 2256883143, + 3830138730, + 1031889488, + 3479347698, + 1535977030, + 4236805024, + 3251091107, + 2132092099, + 1774941330, + 1199868427, + 1452454533, + 157007616, + 2904115357, + 342012276, + 595725824, + 1480756522, + 206960106, + 497939518, + 591360097, + 863170706, + 2375253569, + 3596610801, + 1814182875, + 2094937945, + 3421402208, + 1082520231, + 3463918190, + 2785509508, + 435703966, + 3908032597, + 1641649973, + 2842273706, + 3305899714, + 1510255612, + 2148256476, + 2655287854, + 3276092548, + 4258621189, + 236887753, + 3681803219, + 274041037, + 1734335097, + 3815195456, + 3317970021, + 1899903192, + 1026095262, + 4050517792, + 356393447, + 2410691914, + 3873677099, + 3682840055, + 3913112168, + 2491498743, + 4132185628, + 2489919796, + 1091903735, + 1979897079, + 3170134830, + 3567386728, + 3557303409, + 857797738, + 1136121015, + 1342202287, + 507115054, + 2535736646, + 337727348, + 3213592640, + 1301675037, + 2528481711, + 1895095763, + 1721773893, + 3216771564, + 62756741, + 2142006736, + 835421444, + 2531993523, + 1442658625, + 3659876326, + 2882144922, + 676362277, + 1392781812, + 170690266, + 3921047035, + 1759253602, + 3611846912, + 1745797284, + 664899054, + 1329594018, + 3901205900, + 3045908486, + 2062866102, + 2865634940, + 3543621612, + 3464012697, + 1080764994, + 553557557, + 3656615353, + 3996768171, + 991055499, + 499776247, + 1265440854, + 648242737, + 3940784050, + 980351604, + 3713745714, + 1749149687, + 3396870395, + 4211799374, + 3640570775, + 1161844396, + 3125318951, + 1431517754, + 545492359, + 4268468663, + 3499529547, + 1437099964, + 2702547544, + 3433638243, + 2581715763, + 2787789398, + 1060185593, + 1593081372, + 2418618748, + 4260947970, + 69676912, + 2159744348, + 86519011, + 2512459080, + 3838209314, + 1220612927, + 3339683548, + 133810670, + 1090789135, + 1078426020, + 1569222167, + 845107691, + 3583754449, + 4072456591, + 1091646820, + 628848692, + 1613405280, + 3757631651, + 526609435, + 236106946, + 48312990, + 2942717905, + 3402727701, + 1797494240, + 859738849, + 992217954, + 4005476642, + 2243076622, + 3870952857, + 3732016268, + 765654824, + 3490871365, + 2511836413, + 1685915746, + 3888969200, + 1414112111, + 2273134842, + 3281911079, + 4080962846, + 172450625, + 2569994100, + 980381355, + 4109958455, + 2819808352, + 2716589560, + 2568741196, + 3681446669, + 3329971472, + 1835478071, + 660984891, + 3704678404, + 4045999559, + 3422617507, + 3040415634, + 1762651403, + 1719377915, + 3470491036, + 2693910283, + 3642056355, + 3138596744, + 1364962596, + 2073328063, + 1983633131, + 926494387, + 3423689081, + 2150032023, + 4096667949, + 1749200295, + 3328846651, + 309677260, + 2016342300, + 1779581495, + 3079819751, + 111262694, + 1274766160, + 443224088, + 298511866, + 1025883608, + 3806446537, + 1145181785, + 168956806, + 3641502830, + 3584813610, + 1689216846, + 3666258015, + 3200248200, + 1692713982, + 2646376535, + 4042768518, + 1618508792, + 1610833997, + 3523052358, + 4130873264, + 2001055236, + 3610705100, + 2202168115, + 4028541809, + 2961195399, + 1006657119, + 2006996926, + 3186142756, + 1430667929, + 3210227297, + 1314452623, + 4074634658, + 4101304120, + 2273951170, + 1399257539, + 3367210612, + 3027628629, + 1190975929, + 2062231137, + 2333990788, + 2221543033, + 2438960610, + 1181637006, + 548689776, + 2362791313, + 3372408396, + 3104550113, + 3145860560, + 296247880, + 1970579870, + 3078560182, + 3769228297, + 1714227617, + 3291629107, + 3898220290, + 166772364, + 1251581989, + 493813264, + 448347421, + 195405023, + 2709975567, + 677966185, + 3703036547, + 1463355134, + 2715995803, + 1338867538, + 1343315457, + 2802222074, + 2684532164, + 233230375, + 2599980071, + 2000651841, + 3277868038, + 1638401717, + 4028070440, + 3237316320, + 6314154, + 819756386, + 300326615, + 590932579, + 1405279636, + 3267499572, + 3150704214, + 2428286686, + 3959192993, + 3461946742, + 1862657033, + 1266418056, + 963775037, + 2089974820, + 2263052895, + 1917689273, + 448879540, + 3550394620, + 3981727096, + 150775221, + 3627908307, + 1303187396, + 508620638, + 2975983352, + 2726630617, + 1817252668, + 1876281319, + 1457606340, + 908771278, + 3720792119, + 3617206836, + 2455994898, + 1729034894, + 1080033504, + 976866871, + 3556439503, + 2881648439, + 1522871579, + 1555064734, + 1336096578, + 3548522304, + 2579274686, + 3574697629, + 3205460757, + 3593280638, + 3338716283, + 3079412587, + 564236357, + 2993598910, + 1781952180, + 1464380207, + 3163844217, + 3332601554, + 1699332808, + 1393555694, + 1183702653, + 3581086237, + 1288719814, + 691649499, + 2847557200, + 2895455976, + 3193889540, + 2717570544, + 1781354906, + 1676643554, + 2592534050, + 3230253752, + 1126444790, + 2770207658, + 2633158820, + 2210423226, + 2615765581, + 2414155088, + 3127139286, + 673620729, + 2805611233, + 1269405062, + 4015350505, + 3341807571, + 4149409754, + 1057255273, + 2012875353, + 2162469141, + 2276492801, + 2601117357, + 993977747, + 3918593370, + 2654263191, + 753973209, + 36408145, + 2530585658, + 25011837, + 3520020182, + 2088578344, + 530523599, + 2918365339, + 1524020338, + 1518925132, + 3760827505, + 3759777254, + 1202760957, + 3985898139, + 3906192525, + 674977740, + 4174734889, + 2031300136, + 2019492241, + 3983892565, + 4153806404, + 3822280332, + 352677332, + 2297720250, + 60907813, + 90501309, + 3286998549, + 1016092578, + 2535922412, + 2839152426, + 457141659, + 509813237, + 4120667899, + 652014361, + 1966332200, + 2975202805, + 55981186, + 2327461051, + 676427537, + 3255491064, + 2882294119, + 3433927263, + 1307055953, + 942726286, + 933058658, + 2468411793, + 3933900994, + 4215176142, + 1361170020, + 2001714738, + 2830558078, + 3274259782, + 1222529897, + 1679025792, + 2729314320, + 3714953764, + 1770335741, + 151462246, + 3013232138, + 1682292957, + 1483529935, + 471910574, + 1539241949, + 458788160, + 3436315007, + 1807016891, + 3718408830, + 978976581, + 1043663428, + 3165965781, + 1927990952, + 4200891579, + 2372276910, + 3208408903, + 3533431907, + 1412390302, + 2931980059, + 4132332400, + 1947078029, + 3881505623, + 4168226417, + 2941484381, + 1077988104, + 1320477388, + 886195818, + 18198404, + 3786409e3, + 2509781533, + 112762804, + 3463356488, + 1866414978, + 891333506, + 18488651, + 661792760, + 1628790961, + 3885187036, + 3141171499, + 876946877, + 2693282273, + 1372485963, + 791857591, + 2686433993, + 3759982718, + 3167212022, + 3472953795, + 2716379847, + 445679433, + 3561995674, + 3504004811, + 3574258232, + 54117162, + 3331405415, + 2381918588, + 3769707343, + 4154350007, + 1140177722, + 4074052095, + 668550556, + 3214352940, + 367459370, + 261225585, + 2610173221, + 4209349473, + 3468074219, + 3265815641, + 314222801, + 3066103646, + 3808782860, + 282218597, + 3406013506, + 3773591054, + 379116347, + 1285071038, + 846784868, + 2669647154, + 3771962079, + 3550491691, + 2305946142, + 453669953, + 1268987020, + 3317592352, + 3279303384, + 3744833421, + 2610507566, + 3859509063, + 266596637, + 3847019092, + 517658769, + 3462560207, + 3443424879, + 370717030, + 4247526661, + 2224018117, + 4143653529, + 4112773975, + 2788324899, + 2477274417, + 1456262402, + 2901442914, + 1517677493, + 1846949527, + 2295493580, + 3734397586, + 2176403920, + 1280348187, + 1908823572, + 3871786941, + 846861322, + 1172426758, + 3287448474, + 3383383037, + 1655181056, + 3139813346, + 901632758, + 1897031941, + 2986607138, + 3066810236, + 3447102507, + 1393639104, + 373351379, + 950779232, + 625454576, + 3124240540, + 4148612726, + 2007998917, + 544563296, + 2244738638, + 2330496472, + 2058025392, + 1291430526, + 424198748, + 50039436, + 29584100, + 3605783033, + 2429876329, + 2791104160, + 1057563949, + 3255363231, + 3075367218, + 3463963227, + 1469046755, + 985887462 + ]; + var C_ORIG = [ + 1332899944, + 1700884034, + 1701343084, + 1684370003, + 1668446532, + 1869963892 + ]; + function _encipher(lr, off, P, S) { + var n, l = lr[off], r = lr[off + 1]; + l ^= P[0]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[1]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[2]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[3]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[4]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[5]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[6]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[7]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[8]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[9]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[10]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[11]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[12]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[13]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[14]; + n = S[l >>> 24]; + n += S[256 | l >> 16 & 255]; + n ^= S[512 | l >> 8 & 255]; + n += S[768 | l & 255]; + r ^= n ^ P[15]; + n = S[r >>> 24]; + n += S[256 | r >> 16 & 255]; + n ^= S[512 | r >> 8 & 255]; + n += S[768 | r & 255]; + l ^= n ^ P[16]; + lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1]; + lr[off + 1] = l; + return lr; + } + function _streamtoword(data, offp) { + for (var i = 0, word = 0; i < 4; ++i) + word = word << 8 | data[offp] & 255, offp = (offp + 1) % data.length; + return { key: word, offp }; + } + function _key(key, P, S) { + var offset = 0, lr = [0, 0], plen = P.length, slen = S.length, sw; + for (var i = 0; i < plen; i++) + sw = _streamtoword(key, offset), offset = sw.offp, P[i] = P[i] ^ sw.key; + for (i = 0; i < plen; i += 2) + lr = _encipher(lr, 0, P, S), P[i] = lr[0], P[i + 1] = lr[1]; + for (i = 0; i < slen; i += 2) + lr = _encipher(lr, 0, P, S), S[i] = lr[0], S[i + 1] = lr[1]; + } + function _ekskey(data, key, P, S) { + var offp = 0, lr = [0, 0], plen = P.length, slen = S.length, sw; + for (var i = 0; i < plen; i++) + sw = _streamtoword(key, offp), offp = sw.offp, P[i] = P[i] ^ sw.key; + offp = 0; + for (i = 0; i < plen; i += 2) + sw = _streamtoword(data, offp), offp = sw.offp, lr[0] ^= sw.key, sw = _streamtoword(data, offp), offp = sw.offp, lr[1] ^= sw.key, lr = _encipher(lr, 0, P, S), P[i] = lr[0], P[i + 1] = lr[1]; + for (i = 0; i < slen; i += 2) + sw = _streamtoword(data, offp), offp = sw.offp, lr[0] ^= sw.key, sw = _streamtoword(data, offp), offp = sw.offp, lr[1] ^= sw.key, lr = _encipher(lr, 0, P, S), S[i] = lr[0], S[i + 1] = lr[1]; + } + function _crypt(b, salt, rounds, callback, progressCallback) { + var cdata = C_ORIG.slice(), clen = cdata.length, err; + if (rounds < 4 || rounds > 31) { + err = Error("Illegal number of rounds (4-31): " + rounds); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + if (salt.length !== BCRYPT_SALT_LEN) { + err = Error("Illegal salt length: " + salt.length + " != " + BCRYPT_SALT_LEN); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + rounds = 1 << rounds >>> 0; + var P, S, i = 0, j; + if (Int32Array) { + P = new Int32Array(P_ORIG); + S = new Int32Array(S_ORIG); + } else { + P = P_ORIG.slice(); + S = S_ORIG.slice(); + } + _ekskey(salt, b, P, S); + function next() { + if (progressCallback) + progressCallback(i / rounds); + if (i < rounds) { + var start = Date.now(); + for (; i < rounds; ) { + i = i + 1; + _key(b, P, S); + _key(salt, P, S); + if (Date.now() - start > MAX_EXECUTION_TIME) + break; + } + } else { + for (i = 0; i < 64; i++) + for (j = 0; j < clen >> 1; j++) + _encipher(cdata, j << 1, P, S); + var ret = []; + for (i = 0; i < clen; i++) + ret.push((cdata[i] >> 24 & 255) >>> 0), ret.push((cdata[i] >> 16 & 255) >>> 0), ret.push((cdata[i] >> 8 & 255) >>> 0), ret.push((cdata[i] & 255) >>> 0); + if (callback) { + callback(null, ret); + return; + } else + return ret; + } + if (callback) + nextTick(next); + } + if (typeof callback !== "undefined") { + next(); + } else { + var res; + while (true) + if (typeof (res = next()) !== "undefined") + return res || []; + } + } + function _hash(s, salt, callback, progressCallback) { + var err; + if (typeof s !== "string" || typeof salt !== "string") { + err = Error("Invalid string / salt: Not a string"); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + var minor, offset; + if (salt.charAt(0) !== "$" || salt.charAt(1) !== "2") { + err = Error("Invalid salt version: " + salt.substring(0, 2)); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + if (salt.charAt(2) === "$") + minor = String.fromCharCode(0), offset = 3; + else { + minor = salt.charAt(2); + if (minor !== "a" && minor !== "b" && minor !== "y" || salt.charAt(3) !== "$") { + err = Error("Invalid salt revision: " + salt.substring(2, 4)); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + offset = 4; + } + if (salt.charAt(offset + 2) > "$") { + err = Error("Missing salt rounds"); + if (callback) { + nextTick(callback.bind(this, err)); + return; + } else + throw err; + } + var r1 = parseInt(salt.substring(offset, offset + 1), 10) * 10, r2 = parseInt(salt.substring(offset + 1, offset + 2), 10), rounds = r1 + r2, real_salt = salt.substring(offset + 3, offset + 25); + s += minor >= "a" ? "\0" : ""; + var passwordb = stringToBytes2(s), saltb = base64_decode(real_salt, BCRYPT_SALT_LEN); + function finish(bytes) { + var res = []; + res.push("$2"); + if (minor >= "a") + res.push(minor); + res.push("$"); + if (rounds < 10) + res.push("0"); + res.push(rounds.toString()); + res.push("$"); + res.push(base64_encode(saltb, saltb.length)); + res.push(base64_encode(bytes, C_ORIG.length * 4 - 1)); + return res.join(""); + } + if (typeof callback == "undefined") + return finish(_crypt(passwordb, saltb, rounds)); + else { + _crypt(passwordb, saltb, rounds, function(err2, bytes) { + if (err2) + callback(err2, null); + else + callback(null, finish(bytes)); + }, progressCallback); + } + } + bcrypt3.encodeBase64 = base64_encode; + bcrypt3.decodeBase64 = base64_decode; + return bcrypt3; + }); + } +}); + +// node_modules/base64-js/index.js +var require_base64_js = __commonJS({ + "node_modules/base64-js/index.js"(exports) { + "use strict"; + init_modules_watch_stub(); + exports.byteLength = byteLength; + exports.toByteArray = toByteArray; + exports.fromByteArray = fromByteArray; + var lookup = []; + var revLookup = []; + var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array; + var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + for (i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i]; + revLookup[code.charCodeAt(i)] = i; + } + var i; + var len; + revLookup["-".charCodeAt(0)] = 62; + revLookup["_".charCodeAt(0)] = 63; + function getLens(b64) { + var len2 = b64.length; + if (len2 % 4 > 0) { + throw new Error("Invalid string. Length must be a multiple of 4"); + } + var validLen = b64.indexOf("="); + if (validLen === -1) + validLen = len2; + var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4; + return [validLen, placeHoldersLen]; + } + function byteLength(b64) { + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + function _byteLength(b64, validLen, placeHoldersLen) { + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + function toByteArray(b64) { + var tmp; + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); + var curByte = 0; + var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen; + var i2; + for (i2 = 0; i2 < len2; i2 += 4) { + tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)]; + arr[curByte++] = tmp >> 16 & 255; + arr[curByte++] = tmp >> 8 & 255; + arr[curByte++] = tmp & 255; + } + if (placeHoldersLen === 2) { + tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4; + arr[curByte++] = tmp & 255; + } + if (placeHoldersLen === 1) { + tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2; + arr[curByte++] = tmp >> 8 & 255; + arr[curByte++] = tmp & 255; + } + return arr; + } + function tripletToBase64(num) { + return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63]; + } + function encodeChunk(uint8, start, end) { + var tmp; + var output = []; + for (var i2 = start; i2 < end; i2 += 3) { + tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255); + output.push(tripletToBase64(tmp)); + } + return output.join(""); + } + function fromByteArray(uint8) { + var tmp; + var len2 = uint8.length; + var extraBytes = len2 % 3; + var parts = []; + var maxChunkLength = 16383; + for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) { + parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength)); + } + if (extraBytes === 1) { + tmp = uint8[len2 - 1]; + parts.push( + lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==" + ); + } else if (extraBytes === 2) { + tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1]; + parts.push( + lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=" + ); + } + return parts.join(""); + } + } +}); + +// node_modules/ieee754/index.js +var require_ieee754 = __commonJS({ + "node_modules/ieee754/index.js"(exports) { + init_modules_watch_stub(); + exports.read = function(buffer, offset, isLE, mLen, nBytes) { + var e, m; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var nBits = -7; + var i = isLE ? nBytes - 1 : 0; + var d = isLE ? -1 : 1; + var s = buffer[offset + i]; + i += d; + e = s & (1 << -nBits) - 1; + s >>= -nBits; + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) { + } + m = e & (1 << -nBits) - 1; + e >>= -nBits; + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) { + } + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : (s ? -1 : 1) * Infinity; + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); + }; + exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; + var i = isLE ? 0 : nBytes - 1; + var d = isLE ? 1 : -1; + var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; + value = Math.abs(value); + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; + } + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) { + } + e = e << mLen | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) { + } + buffer[offset + i - d] |= s * 128; + }; + } +}); + +// node_modules/buffer/index.js +var require_buffer = __commonJS({ + "node_modules/buffer/index.js"(exports) { + "use strict"; + init_modules_watch_stub(); + var base64 = require_base64_js(); + var ieee754 = require_ieee754(); + var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null; + exports.Buffer = Buffer5; + exports.SlowBuffer = SlowBuffer; + exports.INSPECT_MAX_BYTES = 50; + var K_MAX_LENGTH = 2147483647; + exports.kMaxLength = K_MAX_LENGTH; + Buffer5.TYPED_ARRAY_SUPPORT = typedArraySupport(); + if (!Buffer5.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") { + 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." + ); + } + function typedArraySupport() { + try { + const arr = new Uint8Array(1); + const proto = { foo: function() { + return 42; + } }; + Object.setPrototypeOf(proto, Uint8Array.prototype); + Object.setPrototypeOf(arr, proto); + return arr.foo() === 42; + } catch (e) { + return false; + } + } + Object.defineProperty(Buffer5.prototype, "parent", { + enumerable: true, + get: function() { + if (!Buffer5.isBuffer(this)) + return void 0; + return this.buffer; + } + }); + Object.defineProperty(Buffer5.prototype, "offset", { + enumerable: true, + get: function() { + if (!Buffer5.isBuffer(this)) + return void 0; + return this.byteOffset; + } + }); + function createBuffer(length) { + if (length > K_MAX_LENGTH) { + throw new RangeError('The value "' + length + '" is invalid for option "size"'); + } + const buf = new Uint8Array(length); + Object.setPrototypeOf(buf, Buffer5.prototype); + return buf; + } + function Buffer5(arg, encodingOrOffset, length) { + if (typeof arg === "number") { + if (typeof encodingOrOffset === "string") { + throw new TypeError( + 'The "string" argument must be of type string. Received type number' + ); + } + return allocUnsafe(arg); + } + return from(arg, encodingOrOffset, length); + } + Buffer5.poolSize = 8192; + function from(value, encodingOrOffset, length) { + if (typeof value === "string") { + return fromString(value, encodingOrOffset); + } + if (ArrayBuffer.isView(value)) { + return fromArrayView(value); + } + if (value == null) { + throw new TypeError( + "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value + ); + } + if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { + return fromArrayBuffer(value, encodingOrOffset, length); + } + if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) { + return fromArrayBuffer(value, encodingOrOffset, length); + } + if (typeof value === "number") { + throw new TypeError( + 'The "value" argument must not be of type number. Received type number' + ); + } + const valueOf = value.valueOf && value.valueOf(); + if (valueOf != null && valueOf !== value) { + return Buffer5.from(valueOf, encodingOrOffset, length); + } + const b = fromObject(value); + if (b) + return b; + if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") { + return Buffer5.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length); + } + throw new TypeError( + "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value + ); + } + Buffer5.from = function(value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length); + }; + Object.setPrototypeOf(Buffer5.prototype, Uint8Array.prototype); + Object.setPrototypeOf(Buffer5, Uint8Array); + function assertSize(size) { + if (typeof size !== "number") { + throw new TypeError('"size" argument must be of type number'); + } else if (size < 0) { + throw new RangeError('The value "' + size + '" is invalid for option "size"'); + } + } + function alloc(size, fill, encoding) { + assertSize(size); + if (size <= 0) { + return createBuffer(size); + } + if (fill !== void 0) { + return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); + } + return createBuffer(size); + } + Buffer5.alloc = function(size, fill, encoding) { + return alloc(size, fill, encoding); + }; + function allocUnsafe(size) { + assertSize(size); + return createBuffer(size < 0 ? 0 : checked(size) | 0); + } + Buffer5.allocUnsafe = function(size) { + return allocUnsafe(size); + }; + Buffer5.allocUnsafeSlow = function(size) { + return allocUnsafe(size); + }; + function fromString(string, encoding) { + if (typeof encoding !== "string" || encoding === "") { + encoding = "utf8"; + } + if (!Buffer5.isEncoding(encoding)) { + throw new TypeError("Unknown encoding: " + encoding); + } + const length = byteLength(string, encoding) | 0; + let buf = createBuffer(length); + const actual = buf.write(string, encoding); + if (actual !== length) { + buf = buf.slice(0, actual); + } + return buf; + } + function fromArrayLike(array) { + const length = array.length < 0 ? 0 : checked(array.length) | 0; + const buf = createBuffer(length); + for (let i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf; + } + function fromArrayView(arrayView) { + if (isInstance(arrayView, Uint8Array)) { + const copy = new Uint8Array(arrayView); + return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); + } + return fromArrayLike(arrayView); + } + function fromArrayBuffer(array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('"offset" is outside of buffer bounds'); + } + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('"length" is outside of buffer bounds'); + } + let buf; + if (byteOffset === void 0 && length === void 0) { + buf = new Uint8Array(array); + } else if (length === void 0) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + Object.setPrototypeOf(buf, Buffer5.prototype); + return buf; + } + function fromObject(obj) { + if (Buffer5.isBuffer(obj)) { + const len = checked(obj.length) | 0; + const buf = createBuffer(len); + if (buf.length === 0) { + return buf; + } + obj.copy(buf, 0, 0, len); + return buf; + } + if (obj.length !== void 0) { + if (typeof obj.length !== "number" || numberIsNaN(obj.length)) { + return createBuffer(0); + } + return fromArrayLike(obj); + } + if (obj.type === "Buffer" && Array.isArray(obj.data)) { + return fromArrayLike(obj.data); + } + } + function checked(length) { + if (length >= K_MAX_LENGTH) { + throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes"); + } + return length | 0; + } + function SlowBuffer(length) { + if (+length != length) { + length = 0; + } + return Buffer5.alloc(+length); + } + Buffer5.isBuffer = function isBuffer(b) { + return b != null && b._isBuffer === true && b !== Buffer5.prototype; + }; + Buffer5.compare = function compare2(a, b) { + if (isInstance(a, Uint8Array)) + a = Buffer5.from(a, a.offset, a.byteLength); + if (isInstance(b, Uint8Array)) + b = Buffer5.from(b, b.offset, b.byteLength); + if (!Buffer5.isBuffer(a) || !Buffer5.isBuffer(b)) { + throw new TypeError( + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' + ); + } + if (a === b) + return 0; + let x = a.length; + let y = b.length; + for (let i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } + if (x < y) + return -1; + if (y < x) + return 1; + return 0; + }; + Buffer5.isEncoding = function isEncoding(encoding) { + switch (String(encoding).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 true; + default: + return false; + } + }; + Buffer5.concat = function concat(list, length) { + if (!Array.isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers'); + } + if (list.length === 0) { + return Buffer5.alloc(0); + } + let i; + if (length === void 0) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + const buffer = Buffer5.allocUnsafe(length); + let pos = 0; + for (i = 0; i < list.length; ++i) { + let buf = list[i]; + if (isInstance(buf, Uint8Array)) { + if (pos + buf.length > buffer.length) { + if (!Buffer5.isBuffer(buf)) + buf = Buffer5.from(buf); + buf.copy(buffer, pos); + } else { + Uint8Array.prototype.set.call( + buffer, + buf, + pos + ); + } + } else if (!Buffer5.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers'); + } else { + buf.copy(buffer, pos); + } + pos += buf.length; + } + return buffer; + }; + function byteLength(string, encoding) { + if (Buffer5.isBuffer(string)) { + return string.length; + } + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { + return string.byteLength; + } + if (typeof string !== "string") { + throw new TypeError( + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string + ); + } + const len = string.length; + const mustMatch = arguments.length > 2 && arguments[2] === true; + if (!mustMatch && len === 0) + return 0; + let loweredCase = false; + for (; ; ) { + switch (encoding) { + case "ascii": + case "latin1": + case "binary": + return len; + case "utf8": + case "utf-8": + return utf8ToBytes(string).length; + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return len * 2; + case "hex": + return len >>> 1; + case "base64": + return base64ToBytes(string).length; + default: + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length; + } + encoding = ("" + encoding).toLowerCase(); + loweredCase = true; + } + } + } + Buffer5.byteLength = byteLength; + function slowToString(encoding, start, end) { + let loweredCase = false; + if (start === void 0 || start < 0) { + start = 0; + } + if (start > this.length) { + return ""; + } + if (end === void 0 || end > this.length) { + end = this.length; + } + if (end <= 0) { + return ""; + } + end >>>= 0; + start >>>= 0; + if (end <= start) { + return ""; + } + if (!encoding) + encoding = "utf8"; + while (true) { + switch (encoding) { + case "hex": + return hexSlice(this, start, end); + case "utf8": + case "utf-8": + return utf8Slice(this, start, end); + case "ascii": + return asciiSlice(this, start, end); + case "latin1": + case "binary": + return latin1Slice(this, start, end); + case "base64": + return base64Slice(this, start, end); + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return utf16leSlice(this, start, end); + default: + if (loweredCase) + throw new TypeError("Unknown encoding: " + encoding); + encoding = (encoding + "").toLowerCase(); + loweredCase = true; + } + } + } + Buffer5.prototype._isBuffer = true; + function swap(b, n, m) { + const i = b[n]; + b[n] = b[m]; + b[m] = i; + } + Buffer5.prototype.swap16 = function swap16() { + const len = this.length; + if (len % 2 !== 0) { + throw new RangeError("Buffer size must be a multiple of 16-bits"); + } + for (let i = 0; i < len; i += 2) { + swap(this, i, i + 1); + } + return this; + }; + Buffer5.prototype.swap32 = function swap32() { + const len = this.length; + if (len % 4 !== 0) { + throw new RangeError("Buffer size must be a multiple of 32-bits"); + } + for (let i = 0; i < len; i += 4) { + swap(this, i, i + 3); + swap(this, i + 1, i + 2); + } + return this; + }; + Buffer5.prototype.swap64 = function swap64() { + const len = this.length; + if (len % 8 !== 0) { + throw new RangeError("Buffer size must be a multiple of 64-bits"); + } + for (let i = 0; i < len; i += 8) { + swap(this, i, i + 7); + swap(this, i + 1, i + 6); + swap(this, i + 2, i + 5); + swap(this, i + 3, i + 4); + } + return this; + }; + Buffer5.prototype.toString = function toString2() { + const length = this.length; + if (length === 0) + return ""; + if (arguments.length === 0) + return utf8Slice(this, 0, length); + return slowToString.apply(this, arguments); + }; + Buffer5.prototype.toLocaleString = Buffer5.prototype.toString; + Buffer5.prototype.equals = function equals(b) { + if (!Buffer5.isBuffer(b)) + throw new TypeError("Argument must be a Buffer"); + if (this === b) + return true; + return Buffer5.compare(this, b) === 0; + }; + Buffer5.prototype.inspect = function inspect() { + let str2 = ""; + const max = exports.INSPECT_MAX_BYTES; + str2 = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim(); + if (this.length > max) + str2 += " ... "; + return ""; + }; + if (customInspectSymbol) { + Buffer5.prototype[customInspectSymbol] = Buffer5.prototype.inspect; + } + Buffer5.prototype.compare = function compare2(target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) { + target = Buffer5.from(target, target.offset, target.byteLength); + } + if (!Buffer5.isBuffer(target)) { + throw new TypeError( + 'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof target + ); + } + if (start === void 0) { + start = 0; + } + if (end === void 0) { + end = target ? target.length : 0; + } + if (thisStart === void 0) { + thisStart = 0; + } + if (thisEnd === void 0) { + thisEnd = this.length; + } + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError("out of range index"); + } + if (thisStart >= thisEnd && start >= end) { + return 0; + } + if (thisStart >= thisEnd) { + return -1; + } + if (start >= end) { + return 1; + } + start >>>= 0; + end >>>= 0; + thisStart >>>= 0; + thisEnd >>>= 0; + if (this === target) + return 0; + let x = thisEnd - thisStart; + let y = end - start; + const len = Math.min(x, y); + const thisCopy = this.slice(thisStart, thisEnd); + const targetCopy = target.slice(start, end); + for (let i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i]; + y = targetCopy[i]; + break; + } + } + if (x < y) + return -1; + if (y < x) + return 1; + return 0; + }; + function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { + if (buffer.length === 0) + return -1; + if (typeof byteOffset === "string") { + encoding = byteOffset; + byteOffset = 0; + } else if (byteOffset > 2147483647) { + byteOffset = 2147483647; + } else if (byteOffset < -2147483648) { + byteOffset = -2147483648; + } + byteOffset = +byteOffset; + if (numberIsNaN(byteOffset)) { + byteOffset = dir ? 0 : buffer.length - 1; + } + if (byteOffset < 0) + byteOffset = buffer.length + byteOffset; + if (byteOffset >= buffer.length) { + if (dir) + return -1; + else + byteOffset = buffer.length - 1; + } else if (byteOffset < 0) { + if (dir) + byteOffset = 0; + else + return -1; + } + if (typeof val === "string") { + val = Buffer5.from(val, encoding); + } + if (Buffer5.isBuffer(val)) { + if (val.length === 0) { + return -1; + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir); + } else if (typeof val === "number") { + val = val & 255; + if (typeof Uint8Array.prototype.indexOf === "function") { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); + } + } + return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); + } + throw new TypeError("val must be string, number or Buffer"); + } + function arrayIndexOf(arr, val, byteOffset, encoding, dir) { + let indexSize = 1; + let arrLength = arr.length; + let valLength = val.length; + if (encoding !== void 0) { + encoding = String(encoding).toLowerCase(); + if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") { + if (arr.length < 2 || val.length < 2) { + return -1; + } + indexSize = 2; + arrLength /= 2; + valLength /= 2; + byteOffset /= 2; + } + } + function read(buf, i2) { + if (indexSize === 1) { + return buf[i2]; + } else { + return buf.readUInt16BE(i2 * indexSize); + } + } + let i; + if (dir) { + let foundIndex = -1; + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) + foundIndex = i; + if (i - foundIndex + 1 === valLength) + return foundIndex * indexSize; + } else { + if (foundIndex !== -1) + i -= i - foundIndex; + foundIndex = -1; + } + } + } else { + if (byteOffset + valLength > arrLength) + byteOffset = arrLength - valLength; + for (i = byteOffset; i >= 0; i--) { + let found = true; + for (let j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false; + break; + } + } + if (found) + return i; + } + } + return -1; + } + Buffer5.prototype.includes = function includes(val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1; + }; + Buffer5.prototype.indexOf = function indexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true); + }; + Buffer5.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false); + }; + function hexWrite(buf, string, offset, length) { + offset = Number(offset) || 0; + const remaining = buf.length - offset; + if (!length) { + length = remaining; + } else { + length = Number(length); + if (length > remaining) { + length = remaining; + } + } + const strLen = string.length; + if (length > strLen / 2) { + length = strLen / 2; + } + let i; + for (i = 0; i < length; ++i) { + const parsed = parseInt(string.substr(i * 2, 2), 16); + if (numberIsNaN(parsed)) + return i; + buf[offset + i] = parsed; + } + return i; + } + function utf8Write(buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); + } + function asciiWrite(buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length); + } + function base64Write(buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length); + } + function ucs2Write(buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); + } + Buffer5.prototype.write = function write(string, offset, length, encoding) { + if (offset === void 0) { + encoding = "utf8"; + length = this.length; + offset = 0; + } else if (length === void 0 && typeof offset === "string") { + encoding = offset; + length = this.length; + offset = 0; + } else if (isFinite(offset)) { + offset = offset >>> 0; + if (isFinite(length)) { + length = length >>> 0; + if (encoding === void 0) + encoding = "utf8"; + } else { + encoding = length; + length = void 0; + } + } else { + throw new Error( + "Buffer.write(string, encoding, offset[, length]) is no longer supported" + ); + } + const remaining = this.length - offset; + if (length === void 0 || length > remaining) + length = remaining; + if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { + throw new RangeError("Attempt to write outside buffer bounds"); + } + if (!encoding) + encoding = "utf8"; + let loweredCase = false; + for (; ; ) { + switch (encoding) { + case "hex": + return hexWrite(this, string, offset, length); + case "utf8": + case "utf-8": + return utf8Write(this, string, offset, length); + case "ascii": + case "latin1": + case "binary": + return asciiWrite(this, string, offset, length); + case "base64": + return base64Write(this, string, offset, length); + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return ucs2Write(this, string, offset, length); + default: + if (loweredCase) + throw new TypeError("Unknown encoding: " + encoding); + encoding = ("" + encoding).toLowerCase(); + loweredCase = true; + } + } + }; + Buffer5.prototype.toJSON = function toJSON() { + return { + type: "Buffer", + data: Array.prototype.slice.call(this._arr || this, 0) + }; + }; + function base64Slice(buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf); + } else { + return base64.fromByteArray(buf.slice(start, end)); + } + } + function utf8Slice(buf, start, end) { + end = Math.min(buf.length, end); + const res = []; + let i = start; + while (i < end) { + const firstByte = buf[i]; + let codePoint = null; + let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; + if (i + bytesPerSequence <= end) { + let secondByte, thirdByte, fourthByte, tempCodePoint; + switch (bytesPerSequence) { + case 1: + if (firstByte < 128) { + codePoint = firstByte; + } + break; + case 2: + secondByte = buf[i + 1]; + if ((secondByte & 192) === 128) { + tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; + if (tempCodePoint > 127) { + codePoint = tempCodePoint; + } + } + break; + case 3: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { + tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; + if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { + codePoint = tempCodePoint; + } + } + break; + case 4: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + fourthByte = buf[i + 3]; + if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { + tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; + if (tempCodePoint > 65535 && tempCodePoint < 1114112) { + codePoint = tempCodePoint; + } + } + } + } + if (codePoint === null) { + codePoint = 65533; + bytesPerSequence = 1; + } else if (codePoint > 65535) { + codePoint -= 65536; + res.push(codePoint >>> 10 & 1023 | 55296); + codePoint = 56320 | codePoint & 1023; + } + res.push(codePoint); + i += bytesPerSequence; + } + return decodeCodePointsArray(res); + } + var MAX_ARGUMENTS_LENGTH = 4096; + function decodeCodePointsArray(codePoints) { + const len = codePoints.length; + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints); + } + let res = ""; + let i = 0; + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ); + } + return res; + } + function asciiSlice(buf, start, end) { + let ret = ""; + end = Math.min(buf.length, end); + for (let i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 127); + } + return ret; + } + function latin1Slice(buf, start, end) { + let ret = ""; + end = Math.min(buf.length, end); + for (let i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]); + } + return ret; + } + function hexSlice(buf, start, end) { + const len = buf.length; + if (!start || start < 0) + start = 0; + if (!end || end < 0 || end > len) + end = len; + let out = ""; + for (let i = start; i < end; ++i) { + out += hexSliceLookupTable[buf[i]]; + } + return out; + } + function utf16leSlice(buf, start, end) { + const bytes = buf.slice(start, end); + let res = ""; + for (let i = 0; i < bytes.length - 1; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); + } + return res; + } + Buffer5.prototype.slice = function slice(start, end) { + const len = this.length; + start = ~~start; + end = end === void 0 ? len : ~~end; + if (start < 0) { + start += len; + if (start < 0) + start = 0; + } else if (start > len) { + start = len; + } + if (end < 0) { + end += len; + if (end < 0) + end = 0; + } else if (end > len) { + end = len; + } + if (end < start) + end = start; + const newBuf = this.subarray(start, end); + Object.setPrototypeOf(newBuf, Buffer5.prototype); + return newBuf; + }; + function checkOffset(offset, ext, length) { + if (offset % 1 !== 0 || offset < 0) + throw new RangeError("offset is not uint"); + if (offset + ext > length) + throw new RangeError("Trying to access beyond buffer length"); + } + Buffer5.prototype.readUintLE = Buffer5.prototype.readUIntLE = function readUIntLE(offset, byteLength2, noAssert) { + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) + checkOffset(offset, byteLength2, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while (++i < byteLength2 && (mul *= 256)) { + val += this[offset + i] * mul; + } + return val; + }; + Buffer5.prototype.readUintBE = Buffer5.prototype.readUIntBE = function readUIntBE(offset, byteLength2, noAssert) { + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) { + checkOffset(offset, byteLength2, this.length); + } + let val = this[offset + --byteLength2]; + let mul = 1; + while (byteLength2 > 0 && (mul *= 256)) { + val += this[offset + --byteLength2] * mul; + } + return val; + }; + Buffer5.prototype.readUint8 = Buffer5.prototype.readUInt8 = function readUInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 1, this.length); + return this[offset]; + }; + Buffer5.prototype.readUint16LE = Buffer5.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 2, this.length); + return this[offset] | this[offset + 1] << 8; + }; + Buffer5.prototype.readUint16BE = Buffer5.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 2, this.length); + return this[offset] << 8 | this[offset + 1]; + }; + Buffer5.prototype.readUint32LE = Buffer5.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216; + }; + Buffer5.prototype.readUint32BE = Buffer5.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); + }; + Buffer5.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === void 0 || last === void 0) { + boundsError(offset, this.length - 8); + } + const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24; + const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24; + return BigInt(lo) + (BigInt(hi) << BigInt(32)); + }); + Buffer5.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === void 0 || last === void 0) { + boundsError(offset, this.length - 8); + } + const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; + const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last; + return (BigInt(hi) << BigInt(32)) + BigInt(lo); + }); + Buffer5.prototype.readIntLE = function readIntLE(offset, byteLength2, noAssert) { + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) + checkOffset(offset, byteLength2, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while (++i < byteLength2 && (mul *= 256)) { + val += this[offset + i] * mul; + } + mul *= 128; + if (val >= mul) + val -= Math.pow(2, 8 * byteLength2); + return val; + }; + Buffer5.prototype.readIntBE = function readIntBE(offset, byteLength2, noAssert) { + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) + checkOffset(offset, byteLength2, this.length); + let i = byteLength2; + let mul = 1; + let val = this[offset + --i]; + while (i > 0 && (mul *= 256)) { + val += this[offset + --i] * mul; + } + mul *= 128; + if (val >= mul) + val -= Math.pow(2, 8 * byteLength2); + return val; + }; + Buffer5.prototype.readInt8 = function readInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 1, this.length); + if (!(this[offset] & 128)) + return this[offset]; + return (255 - this[offset] + 1) * -1; + }; + Buffer5.prototype.readInt16LE = function readInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 2, this.length); + const val = this[offset] | this[offset + 1] << 8; + return val & 32768 ? val | 4294901760 : val; + }; + Buffer5.prototype.readInt16BE = function readInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 2, this.length); + const val = this[offset + 1] | this[offset] << 8; + return val & 32768 ? val | 4294901760 : val; + }; + Buffer5.prototype.readInt32LE = function readInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; + }; + Buffer5.prototype.readInt32BE = function readInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; + }; + Buffer5.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === void 0 || last === void 0) { + boundsError(offset, this.length - 8); + } + const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); + return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24); + }); + Buffer5.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === void 0 || last === void 0) { + boundsError(offset, this.length - 8); + } + const val = (first << 24) + // Overflow + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; + return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last); + }); + Buffer5.prototype.readFloatLE = function readFloatLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, true, 23, 4); + }; + Buffer5.prototype.readFloatBE = function readFloatBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, false, 23, 4); + }; + Buffer5.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, true, 52, 8); + }; + Buffer5.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) + checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, false, 52, 8); + }; + function checkInt(buf, value, offset, ext, max, min) { + if (!Buffer5.isBuffer(buf)) + throw new TypeError('"buffer" argument must be a Buffer instance'); + if (value > max || value < min) + throw new RangeError('"value" argument is out of bounds'); + if (offset + ext > buf.length) + throw new RangeError("Index out of range"); + } + Buffer5.prototype.writeUintLE = Buffer5.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength2, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength2) - 1; + checkInt(this, value, offset, byteLength2, maxBytes, 0); + } + let mul = 1; + let i = 0; + this[offset] = value & 255; + while (++i < byteLength2 && (mul *= 256)) { + this[offset + i] = value / mul & 255; + } + return offset + byteLength2; + }; + Buffer5.prototype.writeUintBE = Buffer5.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength2, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength2 = byteLength2 >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength2) - 1; + checkInt(this, value, offset, byteLength2, maxBytes, 0); + } + let i = byteLength2 - 1; + let mul = 1; + this[offset + i] = value & 255; + while (--i >= 0 && (mul *= 256)) { + this[offset + i] = value / mul & 255; + } + return offset + byteLength2; + }; + Buffer5.prototype.writeUint8 = Buffer5.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 1, 255, 0); + this[offset] = value & 255; + return offset + 1; + }; + Buffer5.prototype.writeUint16LE = Buffer5.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 2, 65535, 0); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + Buffer5.prototype.writeUint16BE = Buffer5.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 2, 65535, 0); + this[offset] = value >>> 8; + this[offset + 1] = value & 255; + return offset + 2; + }; + Buffer5.prototype.writeUint32LE = Buffer5.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 4, 4294967295, 0); + this[offset + 3] = value >>> 24; + this[offset + 2] = value >>> 16; + this[offset + 1] = value >>> 8; + this[offset] = value & 255; + return offset + 4; + }; + Buffer5.prototype.writeUint32BE = Buffer5.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 4, 4294967295, 0); + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 255; + return offset + 4; + }; + function wrtBigUInt64LE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(4294967295)); + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + let hi = Number(value >> BigInt(32) & BigInt(4294967295)); + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + return offset; + } + function wrtBigUInt64BE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(4294967295)); + buf[offset + 7] = lo; + lo = lo >> 8; + buf[offset + 6] = lo; + lo = lo >> 8; + buf[offset + 5] = lo; + lo = lo >> 8; + buf[offset + 4] = lo; + let hi = Number(value >> BigInt(32) & BigInt(4294967295)); + buf[offset + 3] = hi; + hi = hi >> 8; + buf[offset + 2] = hi; + hi = hi >> 8; + buf[offset + 1] = hi; + hi = hi >> 8; + buf[offset] = hi; + return offset + 8; + } + Buffer5.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); + }); + Buffer5.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); + }); + Buffer5.prototype.writeIntLE = function writeIntLE(value, offset, byteLength2, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength2 - 1); + checkInt(this, value, offset, byteLength2, limit - 1, -limit); + } + let i = 0; + let mul = 1; + let sub = 0; + this[offset] = value & 255; + while (++i < byteLength2 && (mul *= 256)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1; + } + this[offset + i] = (value / mul >> 0) - sub & 255; + } + return offset + byteLength2; + }; + Buffer5.prototype.writeIntBE = function writeIntBE(value, offset, byteLength2, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength2 - 1); + checkInt(this, value, offset, byteLength2, limit - 1, -limit); + } + let i = byteLength2 - 1; + let mul = 1; + let sub = 0; + this[offset + i] = value & 255; + while (--i >= 0 && (mul *= 256)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1; + } + this[offset + i] = (value / mul >> 0) - sub & 255; + } + return offset + byteLength2; + }; + Buffer5.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 1, 127, -128); + if (value < 0) + value = 255 + value + 1; + this[offset] = value & 255; + return offset + 1; + }; + Buffer5.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 2, 32767, -32768); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + Buffer5.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 2, 32767, -32768); + this[offset] = value >>> 8; + this[offset + 1] = value & 255; + return offset + 2; + }; + Buffer5.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 4, 2147483647, -2147483648); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + this[offset + 2] = value >>> 16; + this[offset + 3] = value >>> 24; + return offset + 4; + }; + Buffer5.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) + checkInt(this, value, offset, 4, 2147483647, -2147483648); + if (value < 0) + value = 4294967295 + value + 1; + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 255; + return offset + 4; + }; + Buffer5.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); + }); + Buffer5.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); + }); + function checkIEEE754(buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) + throw new RangeError("Index out of range"); + if (offset < 0) + throw new RangeError("Index out of range"); + } + function writeFloat(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 34028234663852886e22, -34028234663852886e22); + } + ieee754.write(buf, value, offset, littleEndian, 23, 4); + return offset + 4; + } + Buffer5.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert); + }; + Buffer5.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert); + }; + function writeDouble(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 17976931348623157e292, -17976931348623157e292); + } + ieee754.write(buf, value, offset, littleEndian, 52, 8); + return offset + 8; + } + Buffer5.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert); + }; + Buffer5.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert); + }; + Buffer5.prototype.copy = function copy(target, targetStart, start, end) { + if (!Buffer5.isBuffer(target)) + throw new TypeError("argument should be a Buffer"); + if (!start) + start = 0; + if (!end && end !== 0) + end = this.length; + if (targetStart >= target.length) + targetStart = target.length; + if (!targetStart) + targetStart = 0; + if (end > 0 && end < start) + end = start; + if (end === start) + return 0; + if (target.length === 0 || this.length === 0) + return 0; + if (targetStart < 0) { + throw new RangeError("targetStart out of bounds"); + } + if (start < 0 || start >= this.length) + throw new RangeError("Index out of range"); + if (end < 0) + throw new RangeError("sourceEnd out of bounds"); + if (end > this.length) + end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + const len = end - start; + if (this === target && typeof Uint8Array.prototype.copyWithin === "function") { + this.copyWithin(targetStart, start, end); + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, end), + targetStart + ); + } + return len; + }; + Buffer5.prototype.fill = function fill(val, start, end, encoding) { + if (typeof val === "string") { + if (typeof start === "string") { + encoding = start; + start = 0; + end = this.length; + } else if (typeof end === "string") { + encoding = end; + end = this.length; + } + if (encoding !== void 0 && typeof encoding !== "string") { + throw new TypeError("encoding must be a string"); + } + if (typeof encoding === "string" && !Buffer5.isEncoding(encoding)) { + throw new TypeError("Unknown encoding: " + encoding); + } + if (val.length === 1) { + const code = val.charCodeAt(0); + if (encoding === "utf8" && code < 128 || encoding === "latin1") { + val = code; + } + } + } else if (typeof val === "number") { + val = val & 255; + } else if (typeof val === "boolean") { + val = Number(val); + } + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError("Out of range index"); + } + if (end <= start) { + return this; + } + start = start >>> 0; + end = end === void 0 ? this.length : end >>> 0; + if (!val) + val = 0; + let i; + if (typeof val === "number") { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + const bytes = Buffer5.isBuffer(val) ? val : Buffer5.from(val, encoding); + const len = bytes.length; + if (len === 0) { + throw new TypeError('The value "' + val + '" is invalid for argument "value"'); + } + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + return this; + }; + var errors = {}; + function E(sym, getMessage, Base) { + errors[sym] = class NodeError extends Base { + constructor() { + super(); + Object.defineProperty(this, "message", { + value: getMessage.apply(this, arguments), + writable: true, + configurable: true + }); + this.name = `${this.name} [${sym}]`; + this.stack; + delete this.name; + } + get code() { + return sym; + } + set code(value) { + Object.defineProperty(this, "code", { + configurable: true, + enumerable: true, + value, + writable: true + }); + } + toString() { + return `${this.name} [${sym}]: ${this.message}`; + } + }; + } + E( + "ERR_BUFFER_OUT_OF_BOUNDS", + function(name) { + if (name) { + return `${name} is outside of buffer bounds`; + } + return "Attempt to access memory outside buffer bounds"; + }, + RangeError + ); + E( + "ERR_INVALID_ARG_TYPE", + function(name, actual) { + return `The "${name}" argument must be of type number. Received type ${typeof actual}`; + }, + TypeError + ); + E( + "ERR_OUT_OF_RANGE", + function(str2, range, input) { + let msg = `The value of "${str2}" is out of range.`; + let received = input; + if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) { + received = addNumericalSeparator(String(input)); + } else if (typeof input === "bigint") { + received = String(input); + if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) { + received = addNumericalSeparator(received); + } + received += "n"; + } + msg += ` It must be ${range}. Received ${received}`; + return msg; + }, + RangeError + ); + function addNumericalSeparator(val) { + let res = ""; + let i = val.length; + const start = val[0] === "-" ? 1 : 0; + for (; i >= start + 4; i -= 3) { + res = `_${val.slice(i - 3, i)}${res}`; + } + return `${val.slice(0, i)}${res}`; + } + function checkBounds(buf, offset, byteLength2) { + validateNumber(offset, "offset"); + if (buf[offset] === void 0 || buf[offset + byteLength2] === void 0) { + boundsError(offset, buf.length - (byteLength2 + 1)); + } + } + function checkIntBI(value, min, max, buf, offset, byteLength2) { + if (value > max || value < min) { + const n = typeof min === "bigint" ? "n" : ""; + let range; + if (byteLength2 > 3) { + if (min === 0 || min === BigInt(0)) { + range = `>= 0${n} and < 2${n} ** ${(byteLength2 + 1) * 8}${n}`; + } else { + range = `>= -(2${n} ** ${(byteLength2 + 1) * 8 - 1}${n}) and < 2 ** ${(byteLength2 + 1) * 8 - 1}${n}`; + } + } else { + range = `>= ${min}${n} and <= ${max}${n}`; + } + throw new errors.ERR_OUT_OF_RANGE("value", range, value); + } + checkBounds(buf, offset, byteLength2); + } + function validateNumber(value, name) { + if (typeof value !== "number") { + throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value); + } + } + function boundsError(value, length, type2) { + if (Math.floor(value) !== value) { + validateNumber(value, type2); + throw new errors.ERR_OUT_OF_RANGE(type2 || "offset", "an integer", value); + } + if (length < 0) { + throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); + } + throw new errors.ERR_OUT_OF_RANGE( + type2 || "offset", + `>= ${type2 ? 1 : 0} and <= ${length}`, + value + ); + } + var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; + function base64clean(str2) { + str2 = str2.split("=")[0]; + str2 = str2.trim().replace(INVALID_BASE64_RE, ""); + if (str2.length < 2) + return ""; + while (str2.length % 4 !== 0) { + str2 = str2 + "="; + } + return str2; + } + function utf8ToBytes(string, units) { + units = units || Infinity; + let codePoint; + const length = string.length; + let leadSurrogate = null; + const bytes = []; + for (let i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + if (codePoint > 55295 && codePoint < 57344) { + if (!leadSurrogate) { + if (codePoint > 56319) { + if ((units -= 3) > -1) + bytes.push(239, 191, 189); + continue; + } else if (i + 1 === length) { + if ((units -= 3) > -1) + bytes.push(239, 191, 189); + continue; + } + leadSurrogate = codePoint; + continue; + } + if (codePoint < 56320) { + if ((units -= 3) > -1) + bytes.push(239, 191, 189); + leadSurrogate = codePoint; + continue; + } + codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; + } else if (leadSurrogate) { + if ((units -= 3) > -1) + bytes.push(239, 191, 189); + } + leadSurrogate = null; + if (codePoint < 128) { + if ((units -= 1) < 0) + break; + bytes.push(codePoint); + } else if (codePoint < 2048) { + if ((units -= 2) < 0) + break; + bytes.push( + codePoint >> 6 | 192, + codePoint & 63 | 128 + ); + } else if (codePoint < 65536) { + if ((units -= 3) < 0) + break; + bytes.push( + codePoint >> 12 | 224, + codePoint >> 6 & 63 | 128, + codePoint & 63 | 128 + ); + } else if (codePoint < 1114112) { + if ((units -= 4) < 0) + break; + bytes.push( + codePoint >> 18 | 240, + codePoint >> 12 & 63 | 128, + codePoint >> 6 & 63 | 128, + codePoint & 63 | 128 + ); + } else { + throw new Error("Invalid code point"); + } + } + return bytes; + } + function asciiToBytes(str2) { + const byteArray = []; + for (let i = 0; i < str2.length; ++i) { + byteArray.push(str2.charCodeAt(i) & 255); + } + return byteArray; + } + function utf16leToBytes(str2, units) { + let c, hi, lo; + const byteArray = []; + for (let i = 0; i < str2.length; ++i) { + if ((units -= 2) < 0) + break; + c = str2.charCodeAt(i); + hi = c >> 8; + lo = c % 256; + byteArray.push(lo); + byteArray.push(hi); + } + return byteArray; + } + function base64ToBytes(str2) { + return base64.toByteArray(base64clean(str2)); + } + function blitBuffer(src, dst, offset, length) { + let i; + for (i = 0; i < length; ++i) { + if (i + offset >= dst.length || i >= src.length) + break; + dst[i + offset] = src[i]; + } + return i; + } + function isInstance(obj, type2) { + return obj instanceof type2 || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type2.name; + } + function numberIsNaN(obj) { + return obj !== obj; + } + var hexSliceLookupTable = function() { + const alphabet = "0123456789abcdef"; + const table = new Array(256); + for (let i = 0; i < 16; ++i) { + const i16 = i * 16; + for (let j = 0; j < 16; ++j) { + table[i16 + j] = alphabet[i] + alphabet[j]; + } + } + return table; + }(); + function defineBigIntMethod(fn) { + return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn; + } + function BufferBigIntNotDefined() { + throw new Error("BigInt not supported"); + } + } +}); + +// src/worker.ts +init_modules_watch_stub(); + +// src/vless.ts +init_modules_watch_stub(); +import { connect } from "cloudflare:sockets"; + +// src/helpers.ts +init_modules_watch_stub(); +var import_sha224 = __toESM(require_sha224()); +var import_enc_hex = __toESM(require_enc_hex()); + +// node_modules/uuid/dist/esm-browser/index.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/stringify.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/validate.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/regex.js +init_modules_watch_stub(); +var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; + +// node_modules/uuid/dist/esm-browser/validate.js +function validate(uuid) { + return typeof uuid === "string" && regex_default.test(uuid); +} +var validate_default = validate; + +// node_modules/uuid/dist/esm-browser/stringify.js +var byteToHex = []; +for (let i = 0; i < 256; ++i) { + byteToHex.push((i + 256).toString(16).slice(1)); +} +function unsafeStringify(arr, offset = 0) { + return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]; +} + +// node_modules/uuid/dist/esm-browser/v35.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/parse.js +init_modules_watch_stub(); +function parse(uuid) { + if (!validate_default(uuid)) { + throw TypeError("Invalid UUID"); + } + let v; + const arr = new Uint8Array(16); + arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24; + arr[1] = v >>> 16 & 255; + arr[2] = v >>> 8 & 255; + arr[3] = v & 255; + arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8; + arr[5] = v & 255; + arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8; + arr[7] = v & 255; + arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8; + arr[9] = v & 255; + arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255; + arr[11] = v / 4294967296 & 255; + arr[12] = v >>> 24 & 255; + arr[13] = v >>> 16 & 255; + arr[14] = v >>> 8 & 255; + arr[15] = v & 255; + return arr; +} +var parse_default = parse; + +// node_modules/uuid/dist/esm-browser/v35.js +function stringToBytes(str2) { + str2 = unescape(encodeURIComponent(str2)); + const bytes = []; + for (let i = 0; i < str2.length; ++i) { + bytes.push(str2.charCodeAt(i)); + } + return bytes; +} +var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; +var URL2 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"; +function v35(name, version2, hashfunc) { + function generateUUID(value, namespace, buf, offset) { + var _namespace; + if (typeof value === "string") { + value = stringToBytes(value); + } + if (typeof namespace === "string") { + namespace = parse_default(namespace); + } + if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) { + throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)"); + } + let bytes = new Uint8Array(16 + value.length); + bytes.set(namespace); + bytes.set(value, namespace.length); + bytes = hashfunc(bytes); + bytes[6] = bytes[6] & 15 | version2; + bytes[8] = bytes[8] & 63 | 128; + if (buf) { + offset = offset || 0; + for (let i = 0; i < 16; ++i) { + buf[offset + i] = bytes[i]; + } + return buf; + } + return unsafeStringify(bytes); + } + try { + generateUUID.name = name; + } catch (err) { + } + generateUUID.DNS = DNS; + generateUUID.URL = URL2; + return generateUUID; +} + +// node_modules/uuid/dist/esm-browser/v5.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/sha1.js +init_modules_watch_stub(); +function f(s, x, y, z) { + switch (s) { + case 0: + return x & y ^ ~x & z; + case 1: + return x ^ y ^ z; + case 2: + return x & y ^ x & z ^ y & z; + case 3: + return x ^ y ^ z; + } +} +function ROTL(x, n) { + return x << n | x >>> 32 - n; +} +function sha1(bytes) { + const K = [1518500249, 1859775393, 2400959708, 3395469782]; + const H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; + if (typeof bytes === "string") { + const msg = unescape(encodeURIComponent(bytes)); + bytes = []; + for (let i = 0; i < msg.length; ++i) { + bytes.push(msg.charCodeAt(i)); + } + } else if (!Array.isArray(bytes)) { + bytes = Array.prototype.slice.call(bytes); + } + bytes.push(128); + const l = bytes.length / 4 + 2; + const N = Math.ceil(l / 16); + const M = new Array(N); + for (let i = 0; i < N; ++i) { + const arr = new Uint32Array(16); + for (let j = 0; j < 16; ++j) { + arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3]; + } + M[i] = arr; + } + M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32); + M[N - 1][14] = Math.floor(M[N - 1][14]); + M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295; + for (let i = 0; i < N; ++i) { + const W = new Uint32Array(80); + for (let t = 0; t < 16; ++t) { + W[t] = M[i][t]; + } + for (let t = 16; t < 80; ++t) { + W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); + } + let a = H[0]; + let b = H[1]; + let c = H[2]; + let d = H[3]; + let e = H[4]; + for (let t = 0; t < 80; ++t) { + const s = Math.floor(t / 20); + const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0; + e = d; + d = c; + c = ROTL(b, 30) >>> 0; + b = a; + a = T; + } + H[0] = H[0] + a >>> 0; + H[1] = H[1] + b >>> 0; + H[2] = H[2] + c >>> 0; + H[3] = H[3] + d >>> 0; + H[4] = H[4] + e >>> 0; + } + return [H[0] >> 24 & 255, H[0] >> 16 & 255, H[0] >> 8 & 255, H[0] & 255, H[1] >> 24 & 255, H[1] >> 16 & 255, H[1] >> 8 & 255, H[1] & 255, H[2] >> 24 & 255, H[2] >> 16 & 255, H[2] >> 8 & 255, H[2] & 255, H[3] >> 24 & 255, H[3] >> 16 & 255, H[3] >> 8 & 255, H[3] & 255, H[4] >> 24 & 255, H[4] >> 16 & 255, H[4] >> 8 & 255, H[4] & 255]; +} +var sha1_default = sha1; + +// node_modules/uuid/dist/esm-browser/v5.js +var v5 = v35("v5", 80, sha1_default); +var v5_default = v5; + +// src/variables.ts +init_modules_watch_stub(); +var version = "2.4"; +var providersUri = "https://raw.githubusercontent.com/vfarid/v2ray-worker/main/resources/provider-list.txt"; +var proxiesUri = "https://raw.githubusercontent.com/vfarid/v2ray-worker/main/resources/proxy-list.txt"; +var defaultProtocols = [ + "vmess", + "built-in-vless", + "vless", + "built-in-trojan" +]; +var defaultALPNList = [ + "h3,h2,http/1.1", + "h3,h2,http/1.1", + "h3,h2,http/1.1", + "h3,h2", + "h2,http/1.1", + "h2", + "http/1.1" +]; +var defaultPFList = [ + "chrome", + "firefox", + "randomized", + "safari", + "chrome", + "edge", + "randomized", + "ios", + "chrome", + "android", + "randomized" +]; +var cfPorts = [ + 443, + 2053, + 2083, + 2087, + 2096, + 8443 +]; +var fragmentsLengthList = [ + "10-20", + "10-50", + "20-50", + "30-80", + "50-100" +]; +var fragmentsIntervalList = [ + "10-20", + "10-50", + "20-50" +]; +var defaultClashConfig = { + port: 7890, + "socks-port": 7891, + "allow-lan": false, + mode: "rule", + "log-level": "info", + "external-controller": "127.0.0.1:9090", + dns: { + "enable": true, + "ipv6": false, + "enhanced-mode": "fake-ip", + "nameserver": [ + "114.114.114.114", + "223.5.5.5", + "8.8.8.8", + "9.9.9.9", + "1.1.1.1", + "https://dns.google/dns-query", + "tls://dns.google:853" + ] + }, + proxies: [], + "proxy-groups": [], + rules: [ + "GEOIP,IR,DIRECT", + "DOMAIN-SUFFIX,ir,DIRECT", + "IP-CIDR,127.0.0.0/8,DIRECT", + "IP-CIDR,192.168.0.0/16,DIRECT", + "IP-CIDR,172.16.0.0/12,DIRECT", + "IP-CIDR,10.0.0.0/8,DIRECT", + "MATCH,All" + ] +}; + +// src/helpers.ts +function GetMultipleRandomElements(arr, num) { + let shuffled = arr.sort(() => 0.5 - Math.random()); + return shuffled.slice(0, num); +} +function IsIp(str2) { + try { + if (str2 == "" || str2 == void 0) + return false; + if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])$/.test(str2)) { + return false; + } + let ls = str2.split("."); + if (ls == null || ls.length != 4 || ls[3] == "0" || parseInt(ls[3]) === 0) { + return false; + } + return true; + } catch (e) { + } + return false; +} +function IsValidUUID(uuid) { + return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid); +} +function GetVlessConfig(no, uuid, sni, address, port) { + if (address.toLowerCase() == sni.toLowerCase()) { + address = sni; + } + return { + remarks: `${no}-vless-worker-${address}`, + configType: "vless", + security: "tls", + tls: "tls", + network: "ws", + port, + sni, + uuid, + host: sni, + path: "vless-ws/?ed=2048", + address + }; +} +function GetTrojanConfig(no, sha224Password, sni, address, port) { + if (address.toLowerCase() == sni.toLowerCase()) { + address = sni; + } + return { + remarks: `${no}-trojan-worker-${address}`, + configType: "trojan", + security: "tls", + tls: "tls", + network: "ws", + port, + sni, + password: sha224Password, + host: sni, + path: "trojan-ws/?ed=2048", + address + }; +} +function IsBase64(str2) { + return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(str2); +} +function RemoveDuplicateConfigs(configList) { + const seen = {}; + return configList.filter((conf) => { + const key = conf.remarks + conf.port + conf.address + conf.uuid; + if (!seen[key]) { + seen[key] = true; + return true; + } + return false; + }); +} +function AddNumberToConfigs(configList, start) { + const seen = {}; + return configList.map((conf, index) => { + conf.remarks = index + start + "-" + conf.remarks; + return conf; + }); +} +function GenerateToken(length = 32) { + const buffer = new Uint8Array(length); + for (let i = 0; i < length; i++) { + buffer[i] = Math.floor(Math.random() * 256); + } + return Array.from(buffer).map((byte) => byte.toString(16).padStart(2, "0")).join(""); +} +function Delay(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} +function MuddleDomain(hostname) { + const parts = hostname.split("."); + const subdomain = parts.slice(0, parts.length - 2).join("."); + const domain = parts.slice(-2).join("."); + const muddledDomain = domain.split("").map( + (char) => Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase() + ).join(""); + return subdomain + "." + muddledDomain; +} +function getUUID(sni) { + return v5_default(sni.toLowerCase(), "ebc4a168-a6fe-47ce-bc25-6183c6212dcc"); +} +function getSHA224Password(sni) { + return (0, import_sha224.default)(sni.toLowerCase()).toString(import_enc_hex.default); +} + +// src/vless.ts +var WS_READY_STATE_OPEN = 1; +var WS_READY_STATE_CLOSING = 2; +var proxyIP = ""; +var proxyList = []; +var blockPorn = ""; +var filterCountries = ""; +var countries = []; +async function GetVlessConfigList(sni, addressList, start, max, env) { + filterCountries = ""; + blockPorn = ""; + proxyList = []; + const uuid = getUUID(sni); + let configList = []; + for (let i = 0; i < max; i++) { + configList.push(GetVlessConfig( + i + start, + uuid, + MuddleDomain(sni), + addressList[Math.floor(Math.random() * addressList.length)], + cfPorts[Math.floor(Math.random() * cfPorts.length)] + )); + } + return configList; +} +async function VlessOverWSHandler(request, sni, env) { + const uuid = getUUID(sni); + const [client, webSocket] = Object.values(new WebSocketPair()); + webSocket.accept(); + let address = ""; + const earlyDataHeader = request.headers.get("sec-websocket-protocol") || ""; + const readableWebSocketStream = MakeReadableWebSocketStream(webSocket, earlyDataHeader); + let remoteSocketWapper = { + value: null + }; + let udpStreamWrite = null; + let isDns = false; + readableWebSocketStream.pipeTo(new WritableStream({ + async write(chunk, controller) { + if (isDns && udpStreamWrite) { + return udpStreamWrite(chunk); + } + if (remoteSocketWapper.value) { + const writer = remoteSocketWapper.value.writable.getWriter(); + await writer.write(chunk); + writer.releaseLock(); + return; + } + const { + hasError, + message, + addressRemote = "", + addressType, + portRemote = 443, + rawDataIndex, + vlessVersion = new Uint8Array([0, 0]), + isUDP, + isMUX + } = ProcessVlessHeader(chunk, uuid); + address = addressRemote; + if (hasError) { + throw new Error(message); + } + if (isUDP) { + if (portRemote === 53) { + isDns = true; + } else { + throw new Error("UDP proxy only enable for DNS which is port 53"); + } + } else if (isMUX) { + throw new Error("MUX is not supported!"); + } + const vlessResponseHeader = new Uint8Array([vlessVersion[0], 0]); + const rawClientData = chunk.slice(rawDataIndex); + if (isDns) { + const { write } = await HandleUDPOutbound(webSocket, vlessResponseHeader, env); + udpStreamWrite = write; + udpStreamWrite(rawClientData); + return; + } + HandleTCPOutbound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, env); + } + })).catch((err) => { + }); + return new Response(null, { + status: 101, + webSocket: client + }); +} +function MakeReadableWebSocketStream(webSocketServer, earlyDataHeader) { + let readableStreamCancel = false; + const stream = new ReadableStream({ + start(controller) { + webSocketServer.addEventListener("message", (event) => { + if (readableStreamCancel) { + return; + } + const message = event.data; + controller.enqueue(message); + }); + webSocketServer.addEventListener("close", () => { + SafeCloseWebSocket(webSocketServer); + if (readableStreamCancel) { + return; + } + controller.close(); + }); + webSocketServer.addEventListener("error", (err) => { + controller.error(err); + }); + const { earlyData, error } = Base64ToArrayBuffer(earlyDataHeader); + if (error) { + controller.error(error); + } else if (earlyData) { + controller.enqueue(earlyData); + } + }, + cancel(reason) { + if (readableStreamCancel) { + return; + } + readableStreamCancel = true; + SafeCloseWebSocket(webSocketServer); + } + }); + return stream; +} +function ProcessVlessHeader(vlessBuffer, uuid) { + if (vlessBuffer.byteLength < 24) { + return { + hasError: true, + message: "Invalid data" + }; + } + const version2 = new Uint8Array(vlessBuffer.slice(0, 1)); + let isValidUser = false; + let isUDP = false; + let isMUX = false; + if (Stringify(new Uint8Array(vlessBuffer.slice(1, 17))) === uuid) { + isValidUser = true; + } + if (!isValidUser) { + return { + hasError: true, + message: "Invalid user" + }; + } + const optLength = new Uint8Array(vlessBuffer.slice(17, 18))[0]; + const command = new Uint8Array( + vlessBuffer.slice(18 + optLength, 18 + optLength + 1) + )[0]; + if (command === 1) { + } else if (command === 2) { + isUDP = true; + } else if (command === 3) { + isMUX = true; + } else { + return { + hasError: true, + message: `Command ${command} is not support, command 01-tcp, 02-udp, 03-mux` + }; + } + const portIndex = 18 + optLength + 1; + const portBuffer = vlessBuffer.slice(portIndex, portIndex + 2); + const portRemote = new DataView(portBuffer).getUint16(0); + let addressIndex = portIndex + 2; + const addressBuffer = new Uint8Array( + vlessBuffer.slice(addressIndex, addressIndex + 1) + ); + const addressType = addressBuffer[0]; + let addressLength = 0; + let addressValueIndex = addressIndex + 1; + let addressValue = ""; + switch (addressType) { + case 1: + addressLength = 4; + addressValue = new Uint8Array( + vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength) + ).join("."); + break; + case 2: + addressLength = new Uint8Array( + vlessBuffer.slice(addressValueIndex, addressValueIndex + 1) + )[0]; + addressValueIndex += 1; + addressValue = new TextDecoder().decode( + vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength) + ); + break; + case 3: + addressLength = 16; + const dataView = new DataView( + vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength) + ); + const ipv6 = []; + for (let i = 0; i < 8; i++) { + ipv6.push(dataView.getUint16(i * 2).toString(16)); + } + addressValue = ipv6.join(":"); + break; + default: + return { + hasError: true, + message: `invild addressType is ${addressType}` + }; + } + if (!addressValue) { + return { + hasError: true, + message: `addressValue is empty, addressType is ${addressType}` + }; + } + return { + hasError: false, + addressRemote: addressValue, + addressType, + portRemote, + rawDataIndex: addressValueIndex + addressLength, + vlessVersion: version2, + isUDP, + isMUX + }; +} +async function HandleUDPOutbound(webSocket, vlessResponseHeader, env) { + let isVlessHeaderSent = false; + const transformStream = new TransformStream({ + transform(chunk, controller) { + for (let index = 0; index < chunk.byteLength; ) { + const lengthBuffer = chunk.slice(index, index + 2); + const udpPakcetLength = new DataView(lengthBuffer).getUint16(0); + const udpData = new Uint8Array( + chunk.slice(index + 2, index + 2 + udpPakcetLength) + ); + index = index + 2 + udpPakcetLength; + controller.enqueue(udpData); + } + } + }); + if (blockPorn == "") { + blockPorn = await env.settings.get("BlockPorn") || "no"; + } + transformStream.readable.pipeTo(new WritableStream({ + async write(chunk) { + const resp = await fetch(blockPorn == "yes" ? "https://1.1.1.3/dns-query" : "https://1.1.1.1/dns-query", { + method: "POST", + headers: { + "content-type": "application/dns-message" + }, + body: chunk + }); + const dnsQueryResult = await resp.arrayBuffer(); + const udpSize = dnsQueryResult.byteLength; + const udpSizeBuffer = new Uint8Array([udpSize >> 8 & 255, udpSize & 255]); + if (webSocket.readyState === WS_READY_STATE_OPEN) { + if (isVlessHeaderSent) { + webSocket.send(await new Blob([udpSizeBuffer, dnsQueryResult]).arrayBuffer()); + } else { + webSocket.send(await new Blob([vlessResponseHeader, udpSizeBuffer, dnsQueryResult]).arrayBuffer()); + isVlessHeaderSent = true; + } + } + } + })).catch((error) => { + }); + const writer = transformStream.writable.getWriter(); + return { + write(chunk) { + writer.write(chunk); + } + }; +} +async function HandleTCPOutbound(remoteSocket, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, env) { + const maxRetryCount = 5; + let retryCount = 0; + async function connectAndWrite(address, port) { + const socketAddress = { + hostname: address, + port + }; + const socketOptions = { + allowHalfOpen: false + // secureTransport: "starttls", + }; + const tcpSocket2 = connect(socketAddress, socketOptions); + remoteSocket.value = tcpSocket2; + const writer = tcpSocket2.writable.getWriter(); + await writer.write(rawClientData); + writer.releaseLock(); + return tcpSocket2; + } + async function retry() { + retryCount++; + if (retryCount > maxRetryCount) { + return; + } + if (!proxyList.length) { + countries = (await env.settings.get("Countries"))?.split(",").filter((t) => t.trim().length > 0) || []; + proxyList = await fetch(proxiesUri).then((r) => r.text()).then((t) => t.trim().split("\n").filter((t2) => t2.trim().length > 0)); + if (countries.length > 0) { + proxyList = proxyList.filter((t) => { + const arr = t.split(","); + if (arr.length > 0) { + return countries.includes(arr[1]); + } + }); + } + proxyList = proxyList.map((ip) => ip.split(",")[0]); + console.log(proxyList); + } + if (proxyList.length > 0) { + proxyIP = proxyList[Math.floor(Math.random() * proxyList.length)]; + const tcpSocket2 = await connectAndWrite(proxyIP, portRemote); + RemoteSocketToWS(tcpSocket2, webSocket, vlessResponseHeader, retry); + } + } + const tcpSocket = await connectAndWrite(addressRemote, portRemote); + RemoteSocketToWS(tcpSocket, webSocket, vlessResponseHeader, retry); +} +async function RemoteSocketToWS(remoteSocket, webSocket, vlessResponseHeader, retry) { + let vlessHeader = vlessResponseHeader; + let hasIncomingData = false; + await remoteSocket.readable.pipeTo( + new WritableStream({ + async write(chunk, controller) { + try { + hasIncomingData = true; + if (webSocket.readyState !== WS_READY_STATE_OPEN) { + controller.error("webSocket.readyState is not open, maybe close"); + } + if (vlessHeader) { + webSocket.send(await new Blob([vlessHeader, chunk]).arrayBuffer()); + vlessHeader = null; + } else { + webSocket.send(chunk); + } + } catch (e) { + } + }, + abort(reason) { + } + }) + ).catch((error) => { + SafeCloseWebSocket(webSocket); + }); + if (hasIncomingData === false && retry) { + retry(); + } +} +function SafeCloseWebSocket(socket) { + try { + if (socket.readyState === WS_READY_STATE_OPEN || socket.readyState === WS_READY_STATE_CLOSING) { + socket.close(); + } + } catch (error) { + } +} +function Base64ToArrayBuffer(base64Str) { + if (!base64Str) { + return { + earlyData: null, + error: null + }; + } + try { + base64Str = base64Str.replace(/-/g, "+").replace(/_/g, "/"); + const decode = atob(base64Str); + const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0)); + return { + earlyData: arryBuffer.buffer, + error: null + }; + } catch (error) { + return { + earlyData: null, + error + }; + } +} +function IsValidVlessUUID(uuid) { + return /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid); +} +function Stringify(arr, offset = 0) { + const uuid = UnsafeStringify(arr, offset); + if (!IsValidVlessUUID(uuid)) { + throw TypeError("Stringified UUID is invalid"); + } + return uuid; +} +var byteToHex2 = []; +for (let i = 0; i < 256; ++i) { + byteToHex2.push((i + 256).toString(16).slice(1)); +} +function UnsafeStringify(arr, offset = 0) { + return `${byteToHex2[arr[offset + 0]] + byteToHex2[arr[offset + 1]] + byteToHex2[arr[offset + 2]] + byteToHex2[arr[offset + 3]]}-${byteToHex2[arr[offset + 4]] + byteToHex2[arr[offset + 5]]}-${byteToHex2[arr[offset + 6]] + byteToHex2[arr[offset + 7]]}-${byteToHex2[arr[offset + 8]] + byteToHex2[arr[offset + 9]]}-${byteToHex2[arr[offset + 10]] + byteToHex2[arr[offset + 11]] + byteToHex2[arr[offset + 12]] + byteToHex2[arr[offset + 13]] + byteToHex2[arr[offset + 14]] + byteToHex2[arr[offset + 15]]}`.toLowerCase(); +} + +// src/trojan.ts +init_modules_watch_stub(); +import { connect as connect2 } from "cloudflare:sockets"; +var WS_READY_STATE_OPEN2 = 1; +var WS_READY_STATE_CLOSING2 = 2; +var proxyIP2 = ""; +var proxyList2 = []; +var filterCountries2 = ""; +var countries2 = []; +async function GetTrojanConfigList(sni, addressList, start, max, env) { + filterCountries2 = ""; + proxyList2 = []; + let configList = []; + for (let i = 0; i < max; i++) { + configList.push(GetTrojanConfig( + i + start, + getUUID(sni), + MuddleDomain(sni), + addressList[Math.floor(Math.random() * addressList.length)], + cfPorts[Math.floor(Math.random() * cfPorts.length)] + )); + } + return configList; +} +async function TrojanOverWSHandler(request, sni, env) { + const sha224Password = getSHA224Password(getUUID(sni)); + const [client, webSocket] = Object.values(new WebSocketPair()); + webSocket.accept(); + let address = ""; + const earlyDataHeader = request.headers.get("sec-websocket-protocol") || ""; + const readableWebSocketStream = MakeReadableWebSocketStream2(webSocket, earlyDataHeader); + let remoteSocketWapper = { + value: null + }; + readableWebSocketStream.pipeTo(new WritableStream({ + async write(chunk, controller) { + if (remoteSocketWapper.value) { + const writer = remoteSocketWapper.value.writable.getWriter(); + await writer.write(chunk); + writer.releaseLock(); + return; + } + const { + hasError, + message, + portRemote = 443, + addressRemote = "", + rawClientData + } = await ParseTrojanHeader(chunk, sha224Password); + address = addressRemote; + if (hasError) { + throw new Error(message); + } + HandleTCPOutbound2(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, env); + } + })).catch((err) => { + }); + return new Response(null, { + status: 101, + webSocket: client + }); +} +async function ParseTrojanHeader(buffer, sha224Password) { + if (buffer.byteLength < 56) { + return { + hasError: true, + message: "invalid data" + }; + } + let crLfIndex = 56; + if (new Uint8Array(buffer.slice(56, 57))[0] !== 13 || new Uint8Array(buffer.slice(57, 58))[0] !== 10) { + return { + hasError: true, + message: "invalid header format (missing CR LF)" + }; + } + const password = new TextDecoder().decode(buffer.slice(0, crLfIndex)); + if (password !== sha224Password) { + return { + hasError: true, + message: "invalid password" + }; + } + const socks5DataBuffer = buffer.slice(crLfIndex + 2); + if (socks5DataBuffer.byteLength < 6) { + return { + hasError: true, + message: "invalid SOCKS5 request data" + }; + } + const view = new DataView(socks5DataBuffer); + const cmd = view.getUint8(0); + if (cmd !== 1) { + return { + hasError: true, + message: "unsupported command, only TCP (CONNECT) is allowed" + }; + } + const atype = view.getUint8(1); + let addressLength = 0; + let addressIndex = 2; + let address = ""; + switch (atype) { + case 1: + addressLength = 4; + address = new Uint8Array( + socks5DataBuffer.slice(addressIndex, addressIndex + addressLength) + ).join("."); + break; + case 3: + addressLength = new Uint8Array( + socks5DataBuffer.slice(addressIndex, addressIndex + 1) + )[0]; + addressIndex += 1; + address = new TextDecoder().decode( + socks5DataBuffer.slice(addressIndex, addressIndex + addressLength) + ); + break; + case 4: + addressLength = 16; + const dataView = new DataView(socks5DataBuffer.slice(addressIndex, addressIndex + addressLength)); + const ipv6 = []; + for (let i = 0; i < 8; i++) { + ipv6.push(dataView.getUint16(i * 2).toString(16)); + } + address = ipv6.join(":"); + break; + default: + return { + hasError: true, + message: `invalid addressType is ${atype}` + }; + } + if (!address) { + return { + hasError: true, + message: `address is empty, addressType is ${atype}` + }; + } + const portIndex = addressIndex + addressLength; + const portBuffer = socks5DataBuffer.slice(portIndex, portIndex + 2); + const portRemote = new DataView(portBuffer).getUint16(0); + return { + hasError: false, + addressRemote: address, + portRemote, + rawClientData: socks5DataBuffer.slice(portIndex + 4) + }; +} +async function HandleTCPOutbound2(remoteSocket, addressRemote, portRemote, rawClientData, webSocket, env) { + const maxRetryCount = 5; + let retryCount = 0; + async function connectAndWrite(address, port) { + const socketAddress = { + hostname: address, + port + }; + const tcpSocket2 = connect2(socketAddress); + remoteSocket.value = tcpSocket2; + const writer = tcpSocket2.writable.getWriter(); + await writer.write(rawClientData); + writer.releaseLock(); + return tcpSocket2; + } + async function retry() { + retryCount++; + if (retryCount > maxRetryCount) { + return; + } + if (!proxyList2.length) { + countries2 = (await env.settings.get("Countries"))?.split(",").filter((t) => t.trim().length > 0) || []; + proxyList2 = await fetch(proxiesUri).then((r) => r.text()).then((t) => t.trim().split("\n").filter((t2) => t2.trim().length > 0)); + if (countries2.length > 0) { + proxyList2 = proxyList2.filter((t) => { + const arr = t.split(","); + if (arr.length > 0) { + return countries2.includes(arr[1]); + } + }); + } + proxyList2 = proxyList2.map((ip) => ip.split(",")[0]); + } + if (proxyList2.length > 0) { + proxyIP2 = proxyList2[Math.floor(Math.random() * proxyList2.length)]; + const tcpSocket2 = await connectAndWrite(proxyIP2, portRemote); + RemoteSocketToWS2(tcpSocket2, webSocket, retry); + } + } + const tcpSocket = await connectAndWrite(addressRemote, portRemote); + RemoteSocketToWS2(tcpSocket, webSocket, retry); +} +function MakeReadableWebSocketStream2(webSocketServer, earlyDataHeader) { + let readableStreamCancel = false; + const stream = new ReadableStream({ + start(controller) { + webSocketServer.addEventListener("message", (event) => { + if (readableStreamCancel) { + return; + } + const message = event.data; + controller.enqueue(message); + }); + webSocketServer.addEventListener("close", () => { + SafeCloseWebSocket2(webSocketServer); + if (readableStreamCancel) { + return; + } + controller.close(); + }); + webSocketServer.addEventListener("error", (err) => { + controller.error(err); + }); + const { earlyData, error } = Base64ToArrayBuffer2(earlyDataHeader); + if (error) { + controller.error(error); + } else if (earlyData) { + controller.enqueue(earlyData); + } + }, + pull(controller) { + }, + cancel(reason) { + if (readableStreamCancel) { + return; + } + readableStreamCancel = true; + SafeCloseWebSocket2(webSocketServer); + } + }); + return stream; +} +async function RemoteSocketToWS2(remoteSocket, webSocket, retry) { + let hasIncomingData = false; + await remoteSocket.readable.pipeTo( + new WritableStream({ + async write(chunk, controller) { + try { + hasIncomingData = true; + if (webSocket.readyState !== WS_READY_STATE_OPEN2) { + controller.error("webSocket.readyState is not open, maybe close"); + } + webSocket.send(chunk); + } catch (e) { + } + }, + abort(reason) { + } + }) + ).catch((error) => { + SafeCloseWebSocket2(webSocket); + }); + if (hasIncomingData === false && retry) { + retry(); + } +} +function Base64ToArrayBuffer2(base64Str) { + if (!base64Str) { + return { + earlyData: null, + error: null + }; + } + try { + base64Str = base64Str.replace(/-/g, "+").replace(/_/g, "/"); + const decode = atob(base64Str); + const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0)); + return { + earlyData: arryBuffer.buffer, + error: null + }; + } catch (error) { + return { + earlyData: null, + error + }; + } +} +function SafeCloseWebSocket2(socket) { + try { + if (socket.readyState === WS_READY_STATE_OPEN2 || socket.readyState === WS_READY_STATE_CLOSING2) { + socket.close(); + } + } catch (error) { + } +} + +// src/panel.ts +init_modules_watch_stub(); +var bcrypt = __toESM(require_bcrypt()); +async function GetPanel(request, env) { + const url = new URL(request.url); + try { + const hash2 = await env.settings.get("Password"); + const token = await env.settings.get("Token"); + if (hash2 && url.searchParams.get("token") != token) { + return Response.redirect(`${url.origin}/login`, 302); + } + const settingsVersion = await env.settings.get("Version") || "2.0"; + if (settingsVersion != version) { + await env.settings.delete("Providers"); + await env.settings.delete("Protocols"); + } + const maxConfigs = parseInt(await env.settings.get("MaxConfigs") || "200"); + const protocols = (await env.settings.get("Protocols"))?.split("\n").filter((t) => t.trim().length > 0) || defaultProtocols; + const alpnList = (await env.settings.get("ALPNs"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const fingerPrints = (await env.settings.get("FingerPrints"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const cleanDomainIPs = (await env.settings.get("CleanDomainIPs"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const configs = (await env.settings.get("Configs"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const includeOriginalConfigs = await env.settings.get("IncludeOriginalConfigs") || "yes"; + const includeMergedConfigs = await env.settings.get("IncludeMergedConfigs") || "yes"; + const enableFragments = await env.settings.get("EnableFragments") || "no"; + const blockPorn2 = await env.settings.get("BlockPorn") || "no"; + const providers = (await env.settings.get("Providers"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const countries3 = (await env.settings.get("Countries"))?.split(",").filter((t) => t.trim().length > 0) || []; + let allCountries = await fetch(proxiesUri).then((r) => r.text()).then((t) => { + return t.trim().split("\n").map((t2) => { + const arr = t2.split(","); + return arr.length > 0 ? arr[1]?.toString().trim().toUpperCase() : ""; + }).filter((t2) => t2); + }); + allCountries = [...new Set(allCountries)].sort(); + let htmlMessage = ""; + const message = url.searchParams.get("message"); + if (message == "success") { + htmlMessage = `
Settings saved successfully.
\u062A\u0646\u0638\u06CC\u0645\u0627\u062A \u0628\u0627 \u0645\u0648\u0641\u0642\u06CC\u062A \u0630\u062E\u06CC\u0631\u0647 \u0634\u062F.
`; + } else if (message == "error") { + htmlMessage = `
Failed to save settings!
\u062E\u0637\u0627 \u062F\u0631 \u0630\u062E\u06CC\u0631\u0647\u200C\u06CC \u062A\u0646\u0638\u06CC\u0645\u0627\u062A!
`; + } + let passwordSection = ""; + if (hash2) { + passwordSection = ` +
+ +
+ `; + } else { + passwordSection = ` +
+ +
+
+ + +
+ Minimum 6 chars / \u062D\u062F\u0627\u0642\u0644 \u06F6 \u06A9\u0627\u0631\u0627\u06A9\u062A\u0631 \u0648\u0627\u0631\u062F \u06A9\u0646\u06CC\u062F. +
+

+ + +
+ `; + } + let htmlContent = ` + + + + + + + - ---------------------------------------------------------------
- ################################################################
- ${FileName} 配置信息
- ---------------------------------------------------------------
- ${动态UUID信息}HOST: ${hostName}
- UUID: ${userID}
- FKID: ${fakeUserID}
- UA: ${UA}
- ${订阅器}
- ---------------------------------------------------------------
- ################################################################
- v2ray
- ---------------------------------------------------------------
- ${v2ray}
- ---------------------------------------------------------------
- ################################################################
- clash-meta
- ---------------------------------------------------------------
- ${clash}
- ---------------------------------------------------------------
- ################################################################
- ${cmad} - `; - return 节点配置页; - } else { - if (typeof fetch != 'function') { - return 'Error: fetch is not available in this environment.'; - } - - let newAddressesapi = []; - let newAddressescsv = []; - let newAddressesnotlsapi = []; - let newAddressesnotlscsv = []; - - // 如果是使用默认域名,则改成一个workers的域名,订阅器会加上代理 - if (hostName.includes(".workers.dev")){ - noTLS = 'true'; - fakeHostName = `${fakeHostName}.workers.dev`; - newAddressesnotlsapi = await 整理优选列表(addressesnotlsapi); - newAddressesnotlscsv = await 整理测速结果('FALSE'); - } else if (hostName.includes(".pages.dev")){ - fakeHostName = `${fakeHostName}.pages.dev`; - } else if (hostName.includes("worker") || hostName.includes("notls") || noTLS == 'true'){ - noTLS = 'true'; - fakeHostName = `notls${fakeHostName}.net`; - newAddressesnotlsapi = await 整理优选列表(addressesnotlsapi); - newAddressesnotlscsv = await 整理测速结果('FALSE'); - } else { - fakeHostName = `${fakeHostName}.xyz` - } - console.log(`虚假HOST: ${fakeHostName}`); - let url = `${subProtocol}://${sub}/sub?host=${fakeHostName}&uuid=${fakeUserID + atob('JmVkZ2V0dW5uZWw9Y21saXUmcHJveHlpcD0=') + RproxyIP}&path=${encodeURIComponent(path)}`; - let isBase64 = true; - - if (!sub || sub == ""){ - if(hostName.includes('workers.dev')) { - if (proxyhostsURL && (!proxyhosts || proxyhosts.length == 0)) { - try { - const response = await fetch(proxyhostsURL); - - if (!response.ok) { - console.error('获取地址时出错:', response.status, response.statusText); - return; // 如果有错误,直接返回 - } - - const text = await response.text(); - const lines = text.split('\n'); - // 过滤掉空行或只包含空白字符的行 - const nonEmptyLines = lines.filter(line => line.trim() !== ''); - - proxyhosts = proxyhosts.concat(nonEmptyLines); - } catch (error) { - console.error('获取地址时出错:', error); - } - } - // 使用Set对象去重 - proxyhosts = [...new Set(proxyhosts)]; - } - - newAddressesapi = await 整理优选列表(addressesapi); - newAddressescsv = await 整理测速结果('TRUE'); - url = `https://${hostName}/${fakeUserID + _url.search}`; - if (hostName.includes("worker") || hostName.includes("notls") || noTLS == 'true') { - if (_url.search) url += '¬ls'; - else url += '?notls'; - } - console.log(`虚假订阅: ${url}`); - } - - if (!userAgent.includes(('CF-Workers-SUB').toLowerCase())){ - if ((userAgent.includes('clash') && !userAgent.includes('nekobox')) || ( _url.searchParams.has('clash') && !userAgent.includes('subconverter'))) { - url = `${subProtocol}://${subConverter}/sub?target=clash&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subConfig)}&emoji=${subEmoji}&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`; - isBase64 = false; - } else if (userAgent.includes('sing-box') || userAgent.includes('singbox') || (( _url.searchParams.has('singbox') || _url.searchParams.has('sb')) && !userAgent.includes('subconverter'))) { - url = `${subProtocol}://${subConverter}/sub?target=singbox&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subConfig)}&emoji=${subEmoji}&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`; - isBase64 = false; - } - } - - try { - let content; - if ((!sub || sub == "") && isBase64 == true) { - content = await 生成本地订阅(fakeHostName,fakeUserID,noTLS,newAddressesapi,newAddressescsv,newAddressesnotlsapi,newAddressesnotlscsv); - } else { - const response = await fetch(url ,{ - headers: { - 'User-Agent': UA + atob('IENGLVdvcmtlcnMtZWRnZXR1bm5lbC9jbWxpdQ==') - }}); - content = await response.text(); - } - - if (_url.pathname == `/${fakeUserID}`) return content; - - return 恢复伪装信息(content, userID, hostName, isBase64); - - } catch (error) { - console.error('Error fetching content:', error); - return `Error fetching content: ${error.message}`; - } - } -} - -async function 整理优选列表(api) { - if (!api || api.length === 0) return []; - - let newapi = ""; - - // 创建一个AbortController对象,用于控制fetch请求的取消 - const controller = new AbortController(); - - const timeout = setTimeout(() => { - controller.abort(); // 取消所有请求 - }, 2000); // 2秒后触发 - - try { - // 使用Promise.allSettled等待所有API请求完成,无论成功或失败 - // 对api数组进行遍历,对每个API地址发起fetch请求 - const responses = await Promise.allSettled(api.map(apiUrl => fetch(apiUrl, { - method: 'get', - headers: { - 'Accept': 'text/html,application/xhtml+xml,application/xml;', - 'User-Agent': atob('Q0YtV29ya2Vycy1lZGdldHVubmVsL2NtbGl1') - }, - signal: controller.signal // 将AbortController的信号量添加到fetch请求中,以便于需要时可以取消请求 - }).then(response => response.ok ? response.text() : Promise.reject()))); - - // 遍历所有响应 - for (const [index, response] of responses.entries()) { - // 检查响应状态是否为'fulfilled',即请求成功完成 - if (response.status === 'fulfilled') { - // 获取响应的内容 - const content = await response.value; - - const lines = content.split(/\r?\n/); - let 节点备注 = ''; - let 测速端口 = '443'; - - if (lines[0].split(',').length > 3){ - const idMatch = api[index].match(/id=([^&]*)/); - if (idMatch) 节点备注 = idMatch[1]; - - const portMatch = api[index].match(/port=([^&]*)/); - if (portMatch) 测速端口 = portMatch[1]; - - for (let i = 1; i < lines.length; i++) { - const columns = lines[i].split(',')[0]; - if(columns){ - newapi += `${columns}:${测速端口}${节点备注 ? `#${节点备注}` : ''}\n`; - if (api[index].includes('proxyip=true')) proxyIPPool.push(`${columns}:${测速端口}`); - } - } - } else { - // 验证当前apiUrl是否带有'proxyip=true' - if (api[index].includes('proxyip=true')) { - // 如果URL带有'proxyip=true',则将内容添加到proxyIPPool - proxyIPPool = proxyIPPool.concat((await 整理(content)).map(item => { - const baseItem = item.split('#')[0] || item; - if (baseItem.includes(':')) { - const port = baseItem.split(':')[1]; - if (!httpsPorts.includes(port)) { - return baseItem; - } - } else { - return `${baseItem}:443`; - } - return null; // 不符合条件时返回 null - }).filter(Boolean)); // 过滤掉 null 值 - } - // 将内容添加到newapi中 - newapi += content + '\n'; - } - } - } - } catch (error) { - console.error(error); - } finally { - // 无论成功或失败,最后都清除设置的超时定时器 - clearTimeout(timeout); - } - - const newAddressesapi = await 整理(newapi); - - // 返回处理后的结果 - return newAddressesapi; -} - -async function 整理测速结果(tls) { - if (!addressescsv || addressescsv.length === 0) { - return []; - } - - let newAddressescsv = []; - - for (const csvUrl of addressescsv) { - try { - const response = await fetch(csvUrl); - - if (!response.ok) { - console.error('获取CSV地址时出错:', response.status, response.statusText); - continue; - } - - const text = await response.text();// 使用正确的字符编码解析文本内容 - let lines; - if (text.includes('\r\n')){ - lines = text.split('\r\n'); - } else { - lines = text.split('\n'); - } - - // 检查CSV头部是否包含必需字段 - const header = lines[0].split(','); - const tlsIndex = header.indexOf('TLS'); - - const ipAddressIndex = 0;// IP地址在 CSV 头部的位置 - const portIndex = 1;// 端口在 CSV 头部的位置 - const dataCenterIndex = tlsIndex + remarkIndex; // 数据中心是 TLS 的后一个字段 - - if (tlsIndex === -1) { - console.error('CSV文件缺少必需的字段'); - continue; - } - - // 从第二行开始遍历CSV行 - for (let i = 1; i < lines.length; i++) { - const columns = lines[i].split(','); - const speedIndex = columns.length - 1; // 最后一个字段 - // 检查TLS是否为"TRUE"且速度大于DLS - if (columns[tlsIndex].toUpperCase() === tls && parseFloat(columns[speedIndex]) > DLS) { - const ipAddress = columns[ipAddressIndex]; - const port = columns[portIndex]; - const dataCenter = columns[dataCenterIndex]; - - const formattedAddress = `${ipAddress}:${port}#${dataCenter}`; - newAddressescsv.push(formattedAddress); - if (csvUrl.includes('proxyip=true') && columns[tlsIndex].toUpperCase() == 'true' && !httpsPorts.includes(port)) { - // 如果URL带有'proxyip=true',则将内容添加到proxyIPPool - proxyIPPool.push(`${ipAddress}:${port}`); - } - } - } - } catch (error) { - console.error('获取CSV地址时出错:', error); - continue; - } - } - - return newAddressescsv; -} - -function 生成本地订阅(host,UUID,noTLS,newAddressesapi,newAddressescsv,newAddressesnotlsapi,newAddressesnotlscsv) { - const regex = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[.*\]):?(\d+)?#?(.*)?$/; - addresses = addresses.concat(newAddressesapi); - addresses = addresses.concat(newAddressescsv); - let notlsresponseBody ; - if (noTLS == 'true'){ - addressesnotls = addressesnotls.concat(newAddressesnotlsapi); - addressesnotls = addressesnotls.concat(newAddressesnotlscsv); - const uniqueAddressesnotls = [...new Set(addressesnotls)]; - - notlsresponseBody = uniqueAddressesnotls.map(address => { - let port = "-1"; - let addressid = address; - - const match = addressid.match(regex); - if (!match) { - if (address.includes(':') && address.includes('#')) { - const parts = address.split(':'); - address = parts[0]; - const subParts = parts[1].split('#'); - port = subParts[0]; - addressid = subParts[1]; - } else if (address.includes(':')) { - const parts = address.split(':'); - address = parts[0]; - port = parts[1]; - } else if (address.includes('#')) { - const parts = address.split('#'); - address = parts[0]; - addressid = parts[1]; - } - - if (addressid.includes(':')) { - addressid = addressid.split(':')[0]; - } - } else { - address = match[1]; - port = match[2] || port; - addressid = match[3] || address; - } - - const httpPorts = ["8080","8880","2052","2082","2086","2095"]; - if (!isValidIPv4(address) && port == "-1") { - for (let httpPort of httpPorts) { - if (address.includes(httpPort)) { - port = httpPort; - break; - } - } - } - if (port == "-1") port = "80"; - - let 伪装域名 = host ; - let 最终路径 = path ; - let 节点备注 = ''; - const 协议类型 = atob(啥啥啥_写的这是啥啊); - - const 维列斯Link = `${协议类型}://${UUID}@${address}:${port + atob('P2VuY3J5cHRpb249bm9uZSZzZWN1cml0eT0mdHlwZT13cyZob3N0PQ==') + 伪装域名}&path=${encodeURIComponent(最终路径)}#${encodeURIComponent(addressid + 节点备注)}`; - - return 维列斯Link; - - }).join('\n'); - - } - - // 使用Set对象去重 - const uniqueAddresses = [...new Set(addresses)]; - - const responseBody = uniqueAddresses.map(address => { - let port = "-1"; - let addressid = address; - - const match = addressid.match(regex); - if (!match) { - if (address.includes(':') && address.includes('#')) { - const parts = address.split(':'); - address = parts[0]; - const subParts = parts[1].split('#'); - port = subParts[0]; - addressid = subParts[1]; - } else if (address.includes(':')) { - const parts = address.split(':'); - address = parts[0]; - port = parts[1]; - } else if (address.includes('#')) { - const parts = address.split('#'); - address = parts[0]; - addressid = parts[1]; - } - - if (addressid.includes(':')) { - addressid = addressid.split(':')[0]; - } - } else { - address = match[1]; - port = match[2] || port; - addressid = match[3] || address; - } - - if (!isValidIPv4(address) && port == "-1") { - for (let httpsPort of httpsPorts) { - if (address.includes(httpsPort)) { - port = httpsPort; - break; - } - } - } - if (port == "-1") port = "443"; - - let 伪装域名 = host ; - let 最终路径 = path ; - let 节点备注 = ''; - const matchingProxyIP = proxyIPPool.find(proxyIP => proxyIP.includes(address)); - if (matchingProxyIP) 最终路径 += `&proxyip=${matchingProxyIP}`; - - if(proxyhosts.length > 0 && (伪装域名.includes('.workers.dev'))) { - 最终路径 = `/${伪装域名}${最终路径}`; - 伪装域名 = proxyhosts[Math.floor(Math.random() * proxyhosts.length)]; - 节点备注 = ` 已启用临时域名中转服务,请尽快绑定自定义域!`; - } - - const 协议类型 = atob(啥啥啥_写的这是啥啊); - const 维列斯Link = `${协议类型}://${UUID}@${address}:${port + atob('P2VuY3J5cHRpb249bm9uZSZzZWN1cml0eT10bHMmc25pPQ==') + 伪装域名}&fp=random&type=ws&host=${伪装域名}&path=${encodeURIComponent(最终路径)}#${encodeURIComponent(addressid + 节点备注)}`; - - return 维列斯Link; - }).join('\n'); - - let base64Response = responseBody; // 重新进行 Base64 编码 - if(noTLS == 'true') base64Response += `\n${notlsresponseBody}`; - if (link.length > 0) base64Response += '\n' + link.join('\n'); - return btoa(base64Response); -} - -async function 整理(内容) { - // 将制表符、双引号、单引号和换行符都替换为逗号 - // 然后将连续的多个逗号替换为单个逗号 - var 替换后的内容 = 内容.replace(/[ |"'\r\n]+/g, ',').replace(/,+/g, ','); - - // 删除开头和结尾的逗号(如果有的话) - if (替换后的内容.charAt(0) == ',') 替换后的内容 = 替换后的内容.slice(1); - if (替换后的内容.charAt(替换后的内容.length - 1) == ',') 替换后的内容 = 替换后的内容.slice(0, 替换后的内容.length - 1); - - // 使用逗号分割字符串,得到地址数组 - const 地址数组 = 替换后的内容.split(','); - - return 地址数组; -} - -async function sendMessage(type, ip, add_data = "") { - if (!BotToken || !ChatID) return; - - try { - let msg = ""; - const response = await fetch(`http://ip-api.com/json/${ip}?lang=zh-CN`); - if (response.ok) { - const ipInfo = await response.json(); - msg = `${type}\nIP: ${ip}\n国家: ${ipInfo.country}\n城市: ${ipInfo.city}\n组织: ${ipInfo.org}\nASN: ${ipInfo.as}\n${add_data}`; - } else { - msg = `${type}\nIP: ${ip}\n${add_data}`; - } - - const url = `https://api.telegram.org/bot${BotToken}/sendMessage?chat_id=${ChatID}&parse_mode=HTML&text=${encodeURIComponent(msg)}`; - return fetch(url, { - method: 'GET', - headers: { - 'Accept': 'text/html,application/xhtml+xml,application/xml;', - 'Accept-Encoding': 'gzip, deflate, br', - 'User-Agent': 'Mozilla/5.0 Chrome/90.0.4430.72' - } - }); - } catch (error) { - console.error('Error sending message:', error); - } -} - -function isValidIPv4(address) { - const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; - return ipv4Regex.test(address); -} - -function 生成动态UUID(密钥) { - const 时区偏移 = 8; // 北京时间相对于UTC的时区偏移+8小时 - const 起始日期 = new Date(2007, 6, 7, 更新时间, 0, 0); // 固定起始日期为2007年7月7日的凌晨3点 - const 一周的毫秒数 = 1000 * 60 * 60 * 24 * 有效时间; - - function 获取当前周数() { - const 现在 = new Date(); - const 调整后的现在 = new Date(现在.getTime() + 时区偏移 * 60 * 60 * 1000); - const 时间差 = Number(调整后的现在) - Number(起始日期); - return Math.ceil(时间差 / 一周的毫秒数); - } - - function 生成UUID(基础字符串) { - const 哈希缓冲区 = new TextEncoder().encode(基础字符串); - return crypto.subtle.digest('SHA-256', 哈希缓冲区).then((哈希) => { - const 哈希数组 = Array.from(new Uint8Array(哈希)); - const 十六进制哈希 = 哈希数组.map(b => b.toString(16).padStart(2, '0')).join(''); - return `${十六进制哈希.substr(0, 8)}-${十六进制哈希.substr(8, 4)}-4${十六进制哈希.substr(13, 3)}-${(parseInt(十六进制哈希.substr(16, 2), 16) & 0x3f | 0x80).toString(16)}${十六进制哈希.substr(18, 2)}-${十六进制哈希.substr(20, 12)}`; - }); - } - - const 当前周数 = 获取当前周数(); // 获取当前周数 - const 结束时间 = new Date(起始日期.getTime() + 当前周数 * 一周的毫秒数); - - // 生成两个 UUID - const 当前UUIDPromise = 生成UUID(密钥 + 当前周数); - const 上一个UUIDPromise = 生成UUID(密钥 + (当前周数 - 1)); - - // 格式化到期时间 - const 到期时间UTC = new Date(结束时间.getTime() - 时区偏移 * 60 * 60 * 1000); // UTC时间 - const 到期时间字符串 = `到期时间(UTC): ${到期时间UTC.toISOString().slice(0, 19).replace('T', ' ')} (UTC+8): ${结束时间.toISOString().slice(0, 19).replace('T', ' ')}\n`; - - return Promise.all([当前UUIDPromise, 上一个UUIDPromise, 到期时间字符串]); -} - -async function 迁移地址列表(env, txt = 'ADD.txt') { - const 旧数据 = await env.KV.get(`/${txt}`); - const 新数据 = await env.KV.get(txt); - - if (旧数据 && !新数据) { - // 写入新位置 - await env.KV.put(txt, 旧数据); - // 删除旧数据 - await env.KV.delete(`/${txt}`); - return true; - } - return false; -} - -async function KV(request, env, txt = 'ADD.txt') { - try { - // POST请求处理 - if (request.method === "POST") { - if (!env.KV) return new Response("未绑定KV空间", { status: 400 }); - try { - const content = await request.text(); - await env.KV.put(txt, content); - return new Response("保存成功"); - } catch (error) { - console.error('保存KV时发生错误:', error); - return new Response("保存失败: " + error.message, { status: 500 }); - } - } - - // GET请求部分 - let content = ''; - let hasKV = !!env.KV; - - if (hasKV) { - try { - content = await env.KV.get(txt) || ''; - } catch (error) { - console.error('读取KV时发生错误:', error); - content = '读取数据时发生错误: ' + error.message; - } - } - - const html = ` - - - - 优选订阅列表 - - - - - - ################################################################
- ${FileName} 优选订阅列表:
- ---------------------------------------------------------------
-   注意事项∨
-
- ${decodeURIComponent(atob('JTA5JTA5JTA5JTA5JTA5JTNDc3Ryb25nJTNFMS4lM0MlMkZzdHJvbmclM0UlMjBBRERBUEklMjAlRTUlQTYlODIlRTYlOUUlOUMlRTYlOTglQUYlRTUlOEYlOEQlRTQlQkIlQTNJUCVFRiVCQyU4QyVFNSU4RiVBRiVFNCVCRCU5QyVFNCVCOCVCQVBST1hZSVAlRTclOUElODQlRTglQUYlOUQlRUYlQkMlOEMlRTUlOEYlQUYlRTUlQjAlODYlMjIlM0Zwcm94eWlwJTNEdHJ1ZSUyMiVFNSU4RiU4MiVFNiU5NSVCMCVFNiVCNyVCQiVFNSU4QSVBMCVFNSU4OCVCMCVFOSU5MyVCRSVFNiU4RSVBNSVFNiU5QyVBQiVFNSVCMCVCRSVFRiVCQyU4QyVFNCVCRSU4QiVFNSVBNiU4MiVFRiVCQyU5QSUzQ2JyJTNFCiUwOSUwOSUwOSUwOSUwOSUyNm5ic3AlM0IlMjZuYnNwJTNCaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGY21saXUlMkZXb3JrZXJWbGVzczJzdWIlMkZtYWluJTJGYWRkcmVzc2VzYXBpLnR4dCUzQ3N0cm9uZyUzRSUzRnByb3h5aXAlM0R0cnVlJTNDJTJGc3Ryb25nJTNFJTNDYnIlM0UlM0NiciUzRQolMDklMDklMDklMDklMDklM0NzdHJvbmclM0UyLiUzQyUyRnN0cm9uZyUzRSUyMEFEREFQSSUyMCVFNSVBNiU4MiVFNiU5RSU5QyVFNiU5OCVBRiUyMCUzQ2ElMjBocmVmJTNEJTI3aHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGWElVMiUyRkNsb3VkZmxhcmVTcGVlZFRlc3QlMjclM0VDbG91ZGZsYXJlU3BlZWRUZXN0JTNDJTJGYSUzRSUyMCVFNyU5QSU4NCUyMGNzdiUyMCVFNyVCQiU5MyVFNiU5RSU5QyVFNiU5NiU4NyVFNCVCQiVCNiVFRiVCQyU4QyVFNCVCRSU4QiVFNSVBNiU4MiVFRiVCQyU5QSUzQ2JyJTNFCiUwOSUwOSUwOSUwOSUwOSUyNm5ic3AlM0IlMjZuYnNwJTNCaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGY21saXUlMkZXb3JrZXJWbGVzczJzdWIlMkZyZWZzJTJGaGVhZHMlMkZtYWluJTJGQ2xvdWRmbGFyZVNwZWVkVGVzdC5jc3YlM0NiciUzRSUzQ2JyJTNFCiUwOSUwOSUwOSUwOSUwOSUyNm5ic3AlM0IlMjZuYnNwJTNCLSUyMCVFNSVBNiU4MiVFOSU5QyU4MCVFNiU4QyU4NyVFNSVBRSU5QTIwNTMlRTclQUIlQUYlRTUlOEYlQTMlRTUlOEYlQUYlRTUlQjAlODYlMjIlM0Zwb3J0JTNEMjA1MyUyMiVFNSU4RiU4MiVFNiU5NSVCMCVFNiVCNyVCQiVFNSU4QSVBMCVFNSU4OCVCMCVFOSU5MyVCRSVFNiU4RSVBNSVFNiU5QyVBQiVFNSVCMCVCRSVFRiVCQyU4QyVFNCVCRSU4QiVFNSVBNiU4MiVFRiVCQyU5QSUzQ2JyJTNFCiUwOSUwOSUwOSUwOSUwOSUyNm5ic3AlM0IlMjZuYnNwJTNCaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGY21saXUlMkZXb3JrZXJWbGVzczJzdWIlMkZyZWZzJTJGaGVhZHMlMkZtYWluJTJGQ2xvdWRmbGFyZVNwZWVkVGVzdC5jc3YlM0NzdHJvbmclM0UlM0Zwb3J0JTNEMjA1MyUzQyUyRnN0cm9uZyUzRSUzQ2JyJTNFJTNDYnIlM0UKJTA5JTA5JTA5JTA5JTA5JTI2bmJzcCUzQiUyNm5ic3AlM0ItJTIwJUU1JUE2JTgyJUU5JTlDJTgwJUU2JThDJTg3JUU1JUFFJTlBJUU4JThBJTgyJUU3JTgyJUI5JUU1JUE0JTg3JUU2JUIzJUE4JUU1JThGJUFGJUU1JUIwJTg2JTIyJTNGaWQlM0RDRiVFNCVCQyU5OCVFOSU4MCU4OSUyMiVFNSU4RiU4MiVFNiU5NSVCMCVFNiVCNyVCQiVFNSU4QSVBMCVFNSU4OCVCMCVFOSU5MyVCRSVFNiU4RSVBNSVFNiU5QyVBQiVFNSVCMCVCRSVFRiVCQyU4QyVFNCVCRSU4QiVFNSVBNiU4MiVFRiVCQyU5QSUzQ2JyJTNFCiUwOSUwOSUwOSUwOSUwOSUyNm5ic3AlM0IlMjZuYnNwJTNCaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGY21saXUlMkZXb3JrZXJWbGVzczJzdWIlMkZyZWZzJTJGaGVhZHMlMkZtYWluJTJGQ2xvdWRmbGFyZVNwZWVkVGVzdC5jc3YlM0NzdHJvbmclM0UlM0ZpZCUzRENGJUU0JUJDJTk4JUU5JTgwJTg5JTNDJTJGc3Ryb25nJTNFJTNDYnIlM0UlM0NiciUzRQolMDklMDklMDklMDklMDklMjZuYnNwJTNCJTI2bmJzcCUzQi0lMjAlRTUlQTYlODIlRTklOUMlODAlRTYlOEMlODclRTUlQUUlOUElRTUlQTQlOUElRTQlQjglQUElRTUlOEYlODIlRTYlOTUlQjAlRTUlODglOTklRTklOUMlODAlRTglQTYlODElRTQlQkQlQkYlRTclOTQlQTglMjclMjYlMjclRTUlODElOUElRTklOTclQjQlRTklOUElOTQlRUYlQkMlOEMlRTQlQkUlOEIlRTUlQTYlODIlRUYlQkMlOUElM0NiciUzRQolMDklMDklMDklMDklMDklMjZuYnNwJTNCJTI2bmJzcCUzQmh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSUyRmNtbGl1JTJGV29ya2VyVmxlc3Myc3ViJTJGcmVmcyUyRmhlYWRzJTJGbWFpbiUyRkNsb3VkZmxhcmVTcGVlZFRlc3QuY3N2JTNGaWQlM0RDRiVFNCVCQyU5OCVFOSU4MCU4OSUzQ3N0cm9uZyUzRSUyNiUzQyUyRnN0cm9uZyUzRXBvcnQlM0QyMDUzJTNDYnIlM0U='))} -
-
- ${hasKV ? ` - -
- - - -
-
- ################################################################
- ${cmad} - ` : '

未绑定KV空间

'} -
- - - - - `; - - return new Response(html, { - headers: { "Content-Type": "text/html;charset=utf-8" } - }); - } catch (error) { - console.error('处理请求时发生错误:', error); - return new Response("服务器错误: " + error.message, { - status: 500, - headers: { "Content-Type": "text/plain;charset=utf-8" } - }); - } -} \ No newline at end of file From e528e8a6fbe60e405c97484b2ef5f432fba56be3 Mon Sep 17 00:00:00 2001 From: masoud13632020 Date: Tue, 24 Dec 2024 01:21:41 +0330 Subject: [PATCH 2/2] masoud --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b66da122..1adadf24b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # edgetunnel -这是一个基于 CF Worker 平台的脚本,在原版的基础上修改了显示 VLESS 配置信息转换为订阅内容。使用该脚本,你可以方便地将 VLESS 配置信息使用在线配置转换到 Clash 或 Singbox 等工具中。 + - 基础部署视频教程:https://www.youtube.com/watch?v=LeT4jQUh8ok - 快速部署视频教程:https://www.youtube.com/watch?v=59THrmJhmAw ***最佳推荐!!!***