@turbo/gen 2.9.6 → 2.9.7-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +125 -162
- package/dist/dist-BKebfWjz.js +3 -0
- package/dist/dist-Cz6osHpM.js +4 -0
- package/dist/dist-DY7shNXC.js +1 -0
- package/dist/dist-SfgYosnQ.js +29 -0
- package/dist/source-map-Bu3j_In8.js +1 -0
- package/dist/src-DlP4pjzy.js +6 -0
- package/package.json +4 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
const e=require(`./src-DlP4pjzy.js`),t=e.__toESM(require(`events`)),n=e.__toESM(require(`url`)),r=e.__toESM(require(`net`)),i=e.__toESM(require(`tls`));var a=e.__toESM(e.require_src(),1);const o=(0,a.default)(`http-proxy-agent`);var s=class extends e.Agent{constructor(e,t){super(t),this.proxy=typeof e==`string`?new n.URL(e):e,this.proxyHeaders=t?.headers??{},o(`Creating new HttpProxyAgent instance: %o`,this.proxy.href);let r=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),i=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={...t?c(t,`headers`):null,host:r,port:i}}addRequest(e,t){e._header=null,this.setRequestProps(e,t),super.addRequest(e,t)}setRequestProps(e,t){let{proxy:r}=this,i=t.secureEndpoint?`https:`:`http:`,a=e.getHeader(`host`)||`localhost`,o=`${i}//${a}`,s=new n.URL(e.path,o);t.port!==80&&(s.port=String(t.port)),e.path=String(s);let c=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders};if(r.username||r.password){let e=`${decodeURIComponent(r.username)}:${decodeURIComponent(r.password)}`;c[`Proxy-Authorization`]=`Basic ${Buffer.from(e).toString(`base64`)}`}c[`Proxy-Connection`]||=this.keepAlive?`Keep-Alive`:`close`;for(let t of Object.keys(c)){let n=c[t];n&&e.setHeader(t,n)}}async connect(e,n){e._header=null,e.path.includes(`://`)||this.setRequestProps(e,n);let a,s;o(`Regenerating stored HTTP header string for request`),e._implicitHeader(),e.outputData&&e.outputData.length>0&&(o(`Patching connection write() output buffer with updated header`),a=e.outputData[0].data,s=a.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`)+4,e.outputData[0].data=e._header+a.substring(s),o(`Output buffer: %o`,e.outputData[0].data));let c;return this.proxy.protocol===`https:`?(o("Creating `tls.Socket`: %o",this.connectOpts),c=i.connect(this.connectOpts)):(o("Creating `net.Socket`: %o",this.connectOpts),c=r.connect(this.connectOpts)),await(0,t.once)(c,`connect`),c}};s.protocols=[`http`,`https`];function c(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}exports.HttpProxyAgent=s;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const e=require(`./src-DlP4pjzy.js`),t=e.__toESM(require(`assert`)),n=e.__toESM(require(`url`)),r=e.__toESM(require(`net`)),i=e.__toESM(require(`tls`));var a=e.__toESM(e.require_src(),1);const o=(0,a.default)(`https-proxy-agent:parse-proxy-response`);function s(e){return new Promise((t,n)=>{let r=0,i=[];function a(){let t=e.read();t?u(t):e.once(`readable`,a)}function s(){e.removeListener(`end`,c),e.removeListener(`error`,l),e.removeListener(`readable`,a)}function c(){s(),o(`onend`),n(Error(`Proxy connection ended before receiving CONNECT response`))}function l(e){s(),o(`onerror %o`,e),n(e)}function u(c){i.push(c),r+=c.length;let l=Buffer.concat(i,r),u=l.indexOf(`\r
|
|
2
|
+
\r
|
|
3
|
+
`);if(u===-1){o(`have not received end of HTTP headers yet...`),a();return}let d=l.slice(0,u).toString(`ascii`).split(`\r
|
|
4
|
+
`),f=d.shift();if(!f)return e.destroy(),n(Error(`No header received from proxy CONNECT response`));let p=f.split(` `),m=+p[1],h=p.slice(2).join(` `),g={};for(let t of d){if(!t)continue;let r=t.indexOf(`:`);if(r===-1)return e.destroy(),n(Error(`Invalid header from proxy CONNECT response: "${t}"`));let i=t.slice(0,r).toLowerCase(),a=t.slice(r+1).trimStart(),o=g[i];typeof o==`string`?g[i]=[o,a]:Array.isArray(o)?o.push(a):g[i]=a}o(`got proxy server response: %o %o`,f,g),s(),t({connect:{statusCode:m,statusText:h,headers:g},buffered:l})}e.on(`error`,l),e.on(`end`,c),a()})}var c=e.__toESM(e.require_src(),1);const l=(0,c.default)(`https-proxy-agent`),u=e=>e.servername===void 0&&e.host&&!r.isIP(e.host)?{...e,servername:e.host}:e;var d=class extends e.Agent{constructor(e,t){super(t),this.options={path:void 0},this.proxy=typeof e==`string`?new n.URL(e):e,this.proxyHeaders=t?.headers??{},l(`Creating new HttpsProxyAgent instance: %o`,this.proxy.href);let r=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,``),i=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol===`https:`?443:80;this.connectOpts={ALPNProtocols:[`http/1.1`],...t?p(t,`headers`):null,host:r,port:i}}async connect(e,n){let{proxy:a}=this;if(!n.host)throw TypeError(`No "host" provided`);let o;a.protocol===`https:`?(l("Creating `tls.Socket`: %o",this.connectOpts),o=i.connect(u(this.connectOpts))):(l("Creating `net.Socket`: %o",this.connectOpts),o=r.connect(this.connectOpts));let c=typeof this.proxyHeaders==`function`?this.proxyHeaders():{...this.proxyHeaders},d=r.isIPv6(n.host)?`[${n.host}]`:n.host,m=`CONNECT ${d}:${n.port} HTTP/1.1\r\n`;if(a.username||a.password){let e=`${decodeURIComponent(a.username)}:${decodeURIComponent(a.password)}`;c[`Proxy-Authorization`]=`Basic ${Buffer.from(e).toString(`base64`)}`}c.Host=`${d}:${n.port}`,c[`Proxy-Connection`]||=this.keepAlive?`Keep-Alive`:`close`;for(let e of Object.keys(c))m+=`${e}: ${c[e]}\r\n`;let h=s(o);o.write(`${m}\r\n`);let{connect:g,buffered:_}=await h;if(e.emit(`proxyConnect`,g),this.emit(`proxyConnect`,g,e),g.statusCode===200)return e.once(`socket`,f),n.secureEndpoint?(l(`Upgrading socket connection to TLS`),i.connect({...p(u(n),`host`,`path`,`port`),socket:o})):o;o.destroy();let v=new r.Socket({writable:!1});return v.readable=!0,e.once(`socket`,e=>{l(`Replaying proxy buffer for failed request`),(0,t.default)(e.listenerCount(`data`)>0),e.push(_),e.push(null)}),v}};d.protocols=[`http`,`https`];function f(e){e.resume()}function p(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}exports.HttpsProxyAgent=d;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./src-DlP4pjzy.js`),t=e.__toESM(require(`url`)),n=e.__toESM(require(`net`)),r=e.__toESM(require(`tls`)),i=e.__toESM(require(`dns`));var a=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0});let t=require(`buffer`),n={INVALID_ENCODING:`Invalid encoding provided. Please specify a valid encoding the internal Node.js Buffer supports.`,INVALID_SMARTBUFFER_SIZE:`Invalid size provided. Size must be a valid integer greater than zero.`,INVALID_SMARTBUFFER_BUFFER:`Invalid Buffer provided in SmartBufferOptions.`,INVALID_SMARTBUFFER_OBJECT:`Invalid SmartBufferOptions object supplied to SmartBuffer constructor or factory methods.`,INVALID_OFFSET:`An invalid offset value was provided.`,INVALID_OFFSET_NON_NUMBER:`An invalid offset value was provided. A numeric value is required.`,INVALID_LENGTH:`An invalid length value was provided.`,INVALID_LENGTH_NON_NUMBER:`An invalid length value was provived. A numeric value is required.`,INVALID_TARGET_OFFSET:`Target offset is beyond the bounds of the internal SmartBuffer data.`,INVALID_TARGET_LENGTH:`Specified length value moves cursor beyong the bounds of the internal SmartBuffer data.`,INVALID_READ_BEYOND_BOUNDS:`Attempted to read beyond the bounds of the managed data.`,INVALID_WRITE_BEYOND_BOUNDS:`Attempted to write beyond the bounds of the managed data.`};exports.ERRORS=n;function r(e){if(!t.Buffer.isEncoding(e))throw Error(n.INVALID_ENCODING)}exports.checkEncoding=r;function i(e){return typeof e==`number`&&isFinite(e)&&l(e)}exports.isFiniteInteger=i;function a(e,t){if(typeof e==`number`){if(!i(e)||e<0)throw Error(t?n.INVALID_OFFSET:n.INVALID_LENGTH)}else throw Error(t?n.INVALID_OFFSET_NON_NUMBER:n.INVALID_LENGTH_NON_NUMBER)}function o(e){a(e,!1)}exports.checkLengthValue=o;function s(e){a(e,!0)}exports.checkOffsetValue=s;function c(e,t){if(e<0||e>t.length)throw Error(n.INVALID_TARGET_OFFSET)}exports.checkTargetOffset=c;function l(e){return typeof e==`number`&&isFinite(e)&&Math.floor(e)===e}function u(e){if(typeof BigInt>`u`)throw Error(`Platform does not support JS BigInt type.`);if(t.Buffer.prototype[e]===void 0)throw Error(`Platform does not support Buffer.prototype.${e}.`)}exports.bigIntAndBufferInt64Check=u}),o=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0});let t=a(),n=4096,r=`utf8`;var i=class e{constructor(i){if(this.length=0,this._encoding=r,this._writeOffset=0,this._readOffset=0,e.isSmartBufferOptions(i))if(i.encoding&&(t.checkEncoding(i.encoding),this._encoding=i.encoding),i.size)if(t.isFiniteInteger(i.size)&&i.size>0)this._buff=Buffer.allocUnsafe(i.size);else throw Error(t.ERRORS.INVALID_SMARTBUFFER_SIZE);else if(i.buff)if(Buffer.isBuffer(i.buff))this._buff=i.buff,this.length=i.buff.length;else throw Error(t.ERRORS.INVALID_SMARTBUFFER_BUFFER);else this._buff=Buffer.allocUnsafe(n);else{if(i!==void 0)throw Error(t.ERRORS.INVALID_SMARTBUFFER_OBJECT);this._buff=Buffer.allocUnsafe(n)}}static fromSize(e,t){return new this({size:e,encoding:t})}static fromBuffer(e,t){return new this({buff:e,encoding:t})}static fromOptions(e){return new this(e)}static isSmartBufferOptions(e){let t=e;return t&&(t.encoding!==void 0||t.size!==void 0||t.buff!==void 0)}readInt8(e){return this._readNumberValue(Buffer.prototype.readInt8,1,e)}readInt16BE(e){return this._readNumberValue(Buffer.prototype.readInt16BE,2,e)}readInt16LE(e){return this._readNumberValue(Buffer.prototype.readInt16LE,2,e)}readInt32BE(e){return this._readNumberValue(Buffer.prototype.readInt32BE,4,e)}readInt32LE(e){return this._readNumberValue(Buffer.prototype.readInt32LE,4,e)}readBigInt64BE(e){return t.bigIntAndBufferInt64Check(`readBigInt64BE`),this._readNumberValue(Buffer.prototype.readBigInt64BE,8,e)}readBigInt64LE(e){return t.bigIntAndBufferInt64Check(`readBigInt64LE`),this._readNumberValue(Buffer.prototype.readBigInt64LE,8,e)}writeInt8(e,t){return this._writeNumberValue(Buffer.prototype.writeInt8,1,e,t),this}insertInt8(e,t){return this._insertNumberValue(Buffer.prototype.writeInt8,1,e,t)}writeInt16BE(e,t){return this._writeNumberValue(Buffer.prototype.writeInt16BE,2,e,t)}insertInt16BE(e,t){return this._insertNumberValue(Buffer.prototype.writeInt16BE,2,e,t)}writeInt16LE(e,t){return this._writeNumberValue(Buffer.prototype.writeInt16LE,2,e,t)}insertInt16LE(e,t){return this._insertNumberValue(Buffer.prototype.writeInt16LE,2,e,t)}writeInt32BE(e,t){return this._writeNumberValue(Buffer.prototype.writeInt32BE,4,e,t)}insertInt32BE(e,t){return this._insertNumberValue(Buffer.prototype.writeInt32BE,4,e,t)}writeInt32LE(e,t){return this._writeNumberValue(Buffer.prototype.writeInt32LE,4,e,t)}insertInt32LE(e,t){return this._insertNumberValue(Buffer.prototype.writeInt32LE,4,e,t)}writeBigInt64BE(e,n){return t.bigIntAndBufferInt64Check(`writeBigInt64BE`),this._writeNumberValue(Buffer.prototype.writeBigInt64BE,8,e,n)}insertBigInt64BE(e,n){return t.bigIntAndBufferInt64Check(`writeBigInt64BE`),this._insertNumberValue(Buffer.prototype.writeBigInt64BE,8,e,n)}writeBigInt64LE(e,n){return t.bigIntAndBufferInt64Check(`writeBigInt64LE`),this._writeNumberValue(Buffer.prototype.writeBigInt64LE,8,e,n)}insertBigInt64LE(e,n){return t.bigIntAndBufferInt64Check(`writeBigInt64LE`),this._insertNumberValue(Buffer.prototype.writeBigInt64LE,8,e,n)}readUInt8(e){return this._readNumberValue(Buffer.prototype.readUInt8,1,e)}readUInt16BE(e){return this._readNumberValue(Buffer.prototype.readUInt16BE,2,e)}readUInt16LE(e){return this._readNumberValue(Buffer.prototype.readUInt16LE,2,e)}readUInt32BE(e){return this._readNumberValue(Buffer.prototype.readUInt32BE,4,e)}readUInt32LE(e){return this._readNumberValue(Buffer.prototype.readUInt32LE,4,e)}readBigUInt64BE(e){return t.bigIntAndBufferInt64Check(`readBigUInt64BE`),this._readNumberValue(Buffer.prototype.readBigUInt64BE,8,e)}readBigUInt64LE(e){return t.bigIntAndBufferInt64Check(`readBigUInt64LE`),this._readNumberValue(Buffer.prototype.readBigUInt64LE,8,e)}writeUInt8(e,t){return this._writeNumberValue(Buffer.prototype.writeUInt8,1,e,t)}insertUInt8(e,t){return this._insertNumberValue(Buffer.prototype.writeUInt8,1,e,t)}writeUInt16BE(e,t){return this._writeNumberValue(Buffer.prototype.writeUInt16BE,2,e,t)}insertUInt16BE(e,t){return this._insertNumberValue(Buffer.prototype.writeUInt16BE,2,e,t)}writeUInt16LE(e,t){return this._writeNumberValue(Buffer.prototype.writeUInt16LE,2,e,t)}insertUInt16LE(e,t){return this._insertNumberValue(Buffer.prototype.writeUInt16LE,2,e,t)}writeUInt32BE(e,t){return this._writeNumberValue(Buffer.prototype.writeUInt32BE,4,e,t)}insertUInt32BE(e,t){return this._insertNumberValue(Buffer.prototype.writeUInt32BE,4,e,t)}writeUInt32LE(e,t){return this._writeNumberValue(Buffer.prototype.writeUInt32LE,4,e,t)}insertUInt32LE(e,t){return this._insertNumberValue(Buffer.prototype.writeUInt32LE,4,e,t)}writeBigUInt64BE(e,n){return t.bigIntAndBufferInt64Check(`writeBigUInt64BE`),this._writeNumberValue(Buffer.prototype.writeBigUInt64BE,8,e,n)}insertBigUInt64BE(e,n){return t.bigIntAndBufferInt64Check(`writeBigUInt64BE`),this._insertNumberValue(Buffer.prototype.writeBigUInt64BE,8,e,n)}writeBigUInt64LE(e,n){return t.bigIntAndBufferInt64Check(`writeBigUInt64LE`),this._writeNumberValue(Buffer.prototype.writeBigUInt64LE,8,e,n)}insertBigUInt64LE(e,n){return t.bigIntAndBufferInt64Check(`writeBigUInt64LE`),this._insertNumberValue(Buffer.prototype.writeBigUInt64LE,8,e,n)}readFloatBE(e){return this._readNumberValue(Buffer.prototype.readFloatBE,4,e)}readFloatLE(e){return this._readNumberValue(Buffer.prototype.readFloatLE,4,e)}writeFloatBE(e,t){return this._writeNumberValue(Buffer.prototype.writeFloatBE,4,e,t)}insertFloatBE(e,t){return this._insertNumberValue(Buffer.prototype.writeFloatBE,4,e,t)}writeFloatLE(e,t){return this._writeNumberValue(Buffer.prototype.writeFloatLE,4,e,t)}insertFloatLE(e,t){return this._insertNumberValue(Buffer.prototype.writeFloatLE,4,e,t)}readDoubleBE(e){return this._readNumberValue(Buffer.prototype.readDoubleBE,8,e)}readDoubleLE(e){return this._readNumberValue(Buffer.prototype.readDoubleLE,8,e)}writeDoubleBE(e,t){return this._writeNumberValue(Buffer.prototype.writeDoubleBE,8,e,t)}insertDoubleBE(e,t){return this._insertNumberValue(Buffer.prototype.writeDoubleBE,8,e,t)}writeDoubleLE(e,t){return this._writeNumberValue(Buffer.prototype.writeDoubleLE,8,e,t)}insertDoubleLE(e,t){return this._insertNumberValue(Buffer.prototype.writeDoubleLE,8,e,t)}readString(e,n){let r;typeof e==`number`?(t.checkLengthValue(e),r=Math.min(e,this.length-this._readOffset)):(n=e,r=this.length-this._readOffset),n!==void 0&&t.checkEncoding(n);let i=this._buff.slice(this._readOffset,this._readOffset+r).toString(n||this._encoding);return this._readOffset+=r,i}insertString(e,n,r){return t.checkOffsetValue(n),this._handleString(e,!0,n,r)}writeString(e,t,n){return this._handleString(e,!1,t,n)}readStringNT(e){e!==void 0&&t.checkEncoding(e);let n=this.length;for(let e=this._readOffset;e<this.length;e++)if(this._buff[e]===0){n=e;break}let r=this._buff.slice(this._readOffset,n);return this._readOffset=n+1,r.toString(e||this._encoding)}insertStringNT(e,n,r){return t.checkOffsetValue(n),this.insertString(e,n,r),this.insertUInt8(0,n+e.length),this}writeStringNT(e,t,n){return this.writeString(e,t,n),this.writeUInt8(0,typeof t==`number`?t+e.length:this.writeOffset),this}readBuffer(e){e!==void 0&&t.checkLengthValue(e);let n=typeof e==`number`?e:this.length,r=Math.min(this.length,this._readOffset+n),i=this._buff.slice(this._readOffset,r);return this._readOffset=r,i}insertBuffer(e,n){return t.checkOffsetValue(n),this._handleBuffer(e,!0,n)}writeBuffer(e,t){return this._handleBuffer(e,!1,t)}readBufferNT(){let e=this.length;for(let t=this._readOffset;t<this.length;t++)if(this._buff[t]===0){e=t;break}let t=this._buff.slice(this._readOffset,e);return this._readOffset=e+1,t}insertBufferNT(e,n){return t.checkOffsetValue(n),this.insertBuffer(e,n),this.insertUInt8(0,n+e.length),this}writeBufferNT(e,n){return n!==void 0&&t.checkOffsetValue(n),this.writeBuffer(e,n),this.writeUInt8(0,typeof n==`number`?n+e.length:this._writeOffset),this}clear(){return this._writeOffset=0,this._readOffset=0,this.length=0,this}remaining(){return this.length-this._readOffset}get readOffset(){return this._readOffset}set readOffset(e){t.checkOffsetValue(e),t.checkTargetOffset(e,this),this._readOffset=e}get writeOffset(){return this._writeOffset}set writeOffset(e){t.checkOffsetValue(e),t.checkTargetOffset(e,this),this._writeOffset=e}get encoding(){return this._encoding}set encoding(e){t.checkEncoding(e),this._encoding=e}get internalBuffer(){return this._buff}toBuffer(){return this._buff.slice(0,this.length)}toString(e){let n=typeof e==`string`?e:this._encoding;return t.checkEncoding(n),this._buff.toString(n,0,this.length)}destroy(){return this.clear(),this}_handleString(e,n,r,i){let a=this._writeOffset,o=this._encoding;typeof r==`number`?a=r:typeof r==`string`&&(t.checkEncoding(r),o=r),typeof i==`string`&&(t.checkEncoding(i),o=i);let s=Buffer.byteLength(e,o);return n?this.ensureInsertable(s,a):this._ensureWriteable(s,a),this._buff.write(e,a,s,o),n?this._writeOffset+=s:typeof r==`number`?this._writeOffset=Math.max(this._writeOffset,a+s):this._writeOffset+=s,this}_handleBuffer(e,t,n){let r=typeof n==`number`?n:this._writeOffset;return t?this.ensureInsertable(e.length,r):this._ensureWriteable(e.length,r),e.copy(this._buff,r),t?this._writeOffset+=e.length:typeof n==`number`?this._writeOffset=Math.max(this._writeOffset,r+e.length):this._writeOffset+=e.length,this}ensureReadable(e,n){let r=this._readOffset;if(n!==void 0&&(t.checkOffsetValue(n),r=n),r<0||r+e>this.length)throw Error(t.ERRORS.INVALID_READ_BEYOND_BOUNDS)}ensureInsertable(e,n){t.checkOffsetValue(n),this._ensureCapacity(this.length+e),n<this.length&&this._buff.copy(this._buff,n+e,n,this._buff.length),n+e>this.length?this.length=n+e:this.length+=e}_ensureWriteable(e,t){let n=typeof t==`number`?t:this._writeOffset;this._ensureCapacity(n+e),n+e>this.length&&(this.length=n+e)}_ensureCapacity(e){let t=this._buff.length;if(e>t){let n=this._buff,r=t*3/2+1;r<e&&(r=e),this._buff=Buffer.allocUnsafe(r),n.copy(this._buff,0,0,t)}}_readNumberValue(e,t,n){this.ensureReadable(t,n);let r=e.call(this._buff,typeof n==`number`?n:this._readOffset);return n===void 0&&(this._readOffset+=t),r}_insertNumberValue(e,n,r,i){return t.checkOffsetValue(i),this.ensureInsertable(n,i),e.call(this._buff,r,i),this._writeOffset+=n,this}_writeNumberValue(e,n,r,i){if(typeof i==`number`){if(i<0)throw Error(t.ERRORS.INVALID_WRITE_BEYOND_BOUNDS);t.checkOffsetValue(i)}let a=typeof i==`number`?i:this._writeOffset;return this._ensureWriteable(n,a),e.call(this._buff,r,a),typeof i==`number`?this._writeOffset=Math.max(this._writeOffset,a+n):this._writeOffset+=n,this}};exports.SmartBuffer=i}),s=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.SOCKS5_NO_ACCEPTABLE_AUTH=exports.SOCKS5_CUSTOM_AUTH_END=exports.SOCKS5_CUSTOM_AUTH_START=exports.SOCKS_INCOMING_PACKET_SIZES=exports.SocksClientState=exports.Socks5Response=exports.Socks5HostType=exports.Socks5Auth=exports.Socks4Response=exports.SocksCommand=exports.ERRORS=exports.DEFAULT_TIMEOUT=void 0;let t=3e4;exports.DEFAULT_TIMEOUT=t;let n={InvalidSocksCommand:`An invalid SOCKS command was provided. Valid options are connect, bind, and associate.`,InvalidSocksCommandForOperation:`An invalid SOCKS command was provided. Only a subset of commands are supported for this operation.`,InvalidSocksCommandChain:`An invalid SOCKS command was provided. Chaining currently only supports the connect command.`,InvalidSocksClientOptionsDestination:`An invalid destination host was provided.`,InvalidSocksClientOptionsExistingSocket:`An invalid existing socket was provided. This should be an instance of stream.Duplex.`,InvalidSocksClientOptionsProxy:`Invalid SOCKS proxy details were provided.`,InvalidSocksClientOptionsTimeout:`An invalid timeout value was provided. Please enter a value above 0 (in ms).`,InvalidSocksClientOptionsProxiesLength:`At least two socks proxies must be provided for chaining.`,InvalidSocksClientOptionsCustomAuthRange:`Custom auth must be a value between 0x80 and 0xFE.`,InvalidSocksClientOptionsCustomAuthOptions:`When a custom_auth_method is provided, custom_auth_request_handler, custom_auth_response_size, and custom_auth_response_handler must also be provided and valid.`,NegotiationError:`Negotiation error`,SocketClosed:`Socket closed`,ProxyConnectionTimedOut:`Proxy connection timed out`,InternalError:`SocksClient internal error (this should not happen)`,InvalidSocks4HandshakeResponse:`Received invalid Socks4 handshake response`,Socks4ProxyRejectedConnection:`Socks4 Proxy rejected connection`,InvalidSocks4IncomingConnectionResponse:`Socks4 invalid incoming connection response`,Socks4ProxyRejectedIncomingBoundConnection:`Socks4 Proxy rejected incoming bound connection`,InvalidSocks5InitialHandshakeResponse:`Received invalid Socks5 initial handshake response`,InvalidSocks5IntiailHandshakeSocksVersion:`Received invalid Socks5 initial handshake (invalid socks version)`,InvalidSocks5InitialHandshakeNoAcceptedAuthType:`Received invalid Socks5 initial handshake (no accepted authentication type)`,InvalidSocks5InitialHandshakeUnknownAuthType:`Received invalid Socks5 initial handshake (unknown authentication type)`,Socks5AuthenticationFailed:`Socks5 Authentication failed`,InvalidSocks5FinalHandshake:`Received invalid Socks5 final handshake response`,InvalidSocks5FinalHandshakeRejected:`Socks5 proxy rejected connection`,InvalidSocks5IncomingConnectionResponse:`Received invalid Socks5 incoming connection response`,Socks5ProxyRejectedIncomingBoundConnection:`Socks5 Proxy rejected incoming bound connection`};exports.ERRORS=n;let r={Socks5InitialHandshakeResponse:2,Socks5UserPassAuthenticationResponse:2,Socks5ResponseHeader:5,Socks5ResponseIPv4:10,Socks5ResponseIPv6:22,Socks5ResponseHostname:e=>e+7,Socks4Response:8};exports.SOCKS_INCOMING_PACKET_SIZES=r;var i;(function(e){e[e.connect=1]=`connect`,e[e.bind=2]=`bind`,e[e.associate=3]=`associate`})(i||(exports.SocksCommand=i={}));var a;(function(e){e[e.Granted=90]=`Granted`,e[e.Failed=91]=`Failed`,e[e.Rejected=92]=`Rejected`,e[e.RejectedIdent=93]=`RejectedIdent`})(a||(exports.Socks4Response=a={}));var o;(function(e){e[e.NoAuth=0]=`NoAuth`,e[e.GSSApi=1]=`GSSApi`,e[e.UserPass=2]=`UserPass`})(o||(exports.Socks5Auth=o={}));let s=128;exports.SOCKS5_CUSTOM_AUTH_START=s;let c=254;exports.SOCKS5_CUSTOM_AUTH_END=c;let l=255;exports.SOCKS5_NO_ACCEPTABLE_AUTH=l;var u;(function(e){e[e.Granted=0]=`Granted`,e[e.Failure=1]=`Failure`,e[e.NotAllowed=2]=`NotAllowed`,e[e.NetworkUnreachable=3]=`NetworkUnreachable`,e[e.HostUnreachable=4]=`HostUnreachable`,e[e.ConnectionRefused=5]=`ConnectionRefused`,e[e.TTLExpired=6]=`TTLExpired`,e[e.CommandNotSupported=7]=`CommandNotSupported`,e[e.AddressNotSupported=8]=`AddressNotSupported`})(u||(exports.Socks5Response=u={}));var d;(function(e){e[e.IPv4=1]=`IPv4`,e[e.Hostname=3]=`Hostname`,e[e.IPv6=4]=`IPv6`})(d||(exports.Socks5HostType=d={}));var f;(function(e){e[e.Created=0]=`Created`,e[e.Connecting=1]=`Connecting`,e[e.Connected=2]=`Connected`,e[e.SentInitialHandshake=3]=`SentInitialHandshake`,e[e.ReceivedInitialHandshakeResponse=4]=`ReceivedInitialHandshakeResponse`,e[e.SentAuthentication=5]=`SentAuthentication`,e[e.ReceivedAuthenticationResponse=6]=`ReceivedAuthenticationResponse`,e[e.SentFinalHandshake=7]=`SentFinalHandshake`,e[e.ReceivedFinalResponse=8]=`ReceivedFinalResponse`,e[e.BoundWaitingForConnection=9]=`BoundWaitingForConnection`,e[e.Established=10]=`Established`,e[e.Disconnected=11]=`Disconnected`,e[e.Error=99]=`Error`})(f||(exports.SocksClientState=f={}))}),c=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.shuffleArray=exports.SocksClientError=void 0;var t=class extends Error{constructor(e,t){super(e),this.options=t}};exports.SocksClientError=t;function n(e){for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}exports.shuffleArray=n}),l=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.isInSubnet=t,exports.isCorrect=n,exports.numberToPaddedHex=r,exports.stringToPaddedHex=i,exports.testBit=a;function t(e){return this.subnetMask<e.subnetMask?!1:this.mask(e.subnetMask)===e.mask()}function n(e){return function(){return this.addressMinusSuffix===this.correctForm()?this.subnetMask===e&&!this.parsedSubnet?!0:this.parsedSubnet===String(this.subnetMask):!1}}function r(e){return e.toString(16).padStart(2,`0`)}function i(e){return r(parseInt(e,10))}function a(e,t){let{length:n}=e;if(t>n)return!1;let r=n-t;return e.substring(r,r+1)===`1`}}),u=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.RE_SUBNET_STRING=exports.RE_ADDRESS=exports.GROUPS=exports.BITS=void 0,exports.BITS=32,exports.GROUPS=4,exports.RE_ADDRESS=/^(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]?)$/g,exports.RE_SUBNET_STRING=/\/\d{1,2}$/}),d=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.AddressError=void 0;var t=class extends Error{constructor(e,t){super(e),this.name=`AddressError`,this.parseMessage=t}};exports.AddressError=t}),f=e.__commonJSMin(exports=>{var t=Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]},n=Object.create?function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}:function(e,t){e.default=t},r=function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.Address4=void 0;let i=r(l()),a=r(u()),o=d();var s=class e{constructor(e){this.groups=a.GROUPS,this.parsedAddress=[],this.parsedSubnet=``,this.subnet=`/32`,this.subnetMask=32,this.v4=!0,this.isCorrect=i.isCorrect(a.BITS),this.isInSubnet=i.isInSubnet,this.address=e;let t=a.RE_SUBNET_STRING.exec(e);if(t){if(this.parsedSubnet=t[0].replace(`/`,``),this.subnetMask=parseInt(this.parsedSubnet,10),this.subnet=`/${this.subnetMask}`,this.subnetMask<0||this.subnetMask>a.BITS)throw new o.AddressError(`Invalid subnet mask.`);e=e.replace(a.RE_SUBNET_STRING,``)}this.addressMinusSuffix=e,this.parsedAddress=this.parse(e)}static isValid(t){try{return new e(t),!0}catch{return!1}}parse(e){let t=e.split(`.`);if(!e.match(a.RE_ADDRESS))throw new o.AddressError(`Invalid IPv4 address.`);return t}correctForm(){return this.parsedAddress.map(e=>parseInt(e,10)).join(`.`)}static fromHex(t){let n=t.replace(/:/g,``).padStart(8,`0`),r=[],i;for(i=0;i<8;i+=2){let e=n.slice(i,i+2);r.push(parseInt(e,16))}return new e(r.join(`.`))}static fromInteger(t){return e.fromHex(t.toString(16))}static fromArpa(t){let n=t.replace(/(\.in-addr\.arpa)?\.$/,``),r=n.split(`.`).reverse().join(`.`);return new e(r)}toHex(){return this.parsedAddress.map(e=>i.stringToPaddedHex(e)).join(`:`)}toArray(){return this.parsedAddress.map(e=>parseInt(e,10))}toGroup6(){let e=[],t;for(t=0;t<a.GROUPS;t+=2)e.push(`${i.stringToPaddedHex(this.parsedAddress[t])}${i.stringToPaddedHex(this.parsedAddress[t+1])}`);return e.join(`:`)}bigInt(){return BigInt(`0x${this.parsedAddress.map(e=>i.stringToPaddedHex(e)).join(``)}`)}_startAddress(){return BigInt(`0b${this.mask()+`0`.repeat(a.BITS-this.subnetMask)}`)}startAddress(){return e.fromBigInt(this._startAddress())}startAddressExclusive(){let t=BigInt(`1`);return e.fromBigInt(this._startAddress()+t)}_endAddress(){return BigInt(`0b${this.mask()+`1`.repeat(a.BITS-this.subnetMask)}`)}endAddress(){return e.fromBigInt(this._endAddress())}endAddressExclusive(){let t=BigInt(`1`);return e.fromBigInt(this._endAddress()-t)}static fromBigInt(t){return e.fromHex(t.toString(16))}static fromByteArray(e){if(e.length!==4)throw new o.AddressError(`IPv4 addresses require exactly 4 bytes`);for(let t=0;t<e.length;t++)if(!Number.isInteger(e[t])||e[t]<0||e[t]>255)throw new o.AddressError(`All bytes must be integers between 0 and 255`);return this.fromUnsignedByteArray(e)}static fromUnsignedByteArray(t){if(t.length!==4)throw new o.AddressError(`IPv4 addresses require exactly 4 bytes`);let n=t.join(`.`);return new e(n)}mask(e){return e===void 0&&(e=this.subnetMask),this.getBitsBase2(0,e)}getBitsBase2(e,t){return this.binaryZeroPad().slice(e,t)}reverseForm(e){e||={};let t=this.correctForm().split(`.`).reverse().join(`.`);return e.omitSuffix?t:`${t}.in-addr.arpa.`}isMulticast(){return this.isInSubnet(new e(`224.0.0.0/4`))}binaryZeroPad(){return this.bigInt().toString(2).padStart(a.BITS,`0`)}groupForV6(){let e=this.parsedAddress;return this.address.replace(a.RE_ADDRESS,`<span class="hover-group group-v4 group-6">${e.slice(0,2).join(`.`)}</span>.<span class="hover-group group-v4 group-7">${e.slice(2,4).join(`.`)}</span>`)}};exports.Address4=s}),p=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.RE_URL_WITH_PORT=exports.RE_URL=exports.RE_ZONE_STRING=exports.RE_SUBNET_STRING=exports.RE_BAD_ADDRESS=exports.RE_BAD_CHARACTERS=exports.TYPES=exports.SCOPES=exports.GROUPS=exports.BITS=void 0,exports.BITS=128,exports.GROUPS=8,exports.SCOPES={0:`Reserved`,1:`Interface local`,2:`Link local`,4:`Admin local`,5:`Site local`,8:`Organization local`,14:`Global`,15:`Reserved`},exports.TYPES={"ff01::1/128":`Multicast (All nodes on this interface)`,"ff01::2/128":`Multicast (All routers on this interface)`,"ff02::1/128":`Multicast (All nodes on this link)`,"ff02::2/128":`Multicast (All routers on this link)`,"ff05::2/128":`Multicast (All routers in this site)`,"ff02::5/128":`Multicast (OSPFv3 AllSPF routers)`,"ff02::6/128":`Multicast (OSPFv3 AllDR routers)`,"ff02::9/128":`Multicast (RIP routers)`,"ff02::a/128":`Multicast (EIGRP routers)`,"ff02::d/128":`Multicast (PIM routers)`,"ff02::16/128":`Multicast (MLDv2 reports)`,"ff01::fb/128":`Multicast (mDNSv6)`,"ff02::fb/128":`Multicast (mDNSv6)`,"ff05::fb/128":`Multicast (mDNSv6)`,"ff02::1:2/128":`Multicast (All DHCP servers and relay agents on this link)`,"ff05::1:2/128":`Multicast (All DHCP servers and relay agents in this site)`,"ff02::1:3/128":`Multicast (All DHCP servers on this link)`,"ff05::1:3/128":`Multicast (All DHCP servers in this site)`,"::/128":`Unspecified`,"::1/128":`Loopback`,"ff00::/8":`Multicast`,"fe80::/10":`Link-local unicast`},exports.RE_BAD_CHARACTERS=/([^0-9a-f:/%])/gi,exports.RE_BAD_ADDRESS=/([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi,exports.RE_SUBNET_STRING=/\/\d{1,3}(?=%|$)/,exports.RE_ZONE_STRING=/%.*$/,exports.RE_URL=/^\[{0,1}([0-9a-f:]+)\]{0,1}/,exports.RE_URL_WITH_PORT=/\[([0-9a-f:]+)\]:([0-9]{1,5})/}),m=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.spanAllZeroes=t,exports.spanAll=n,exports.spanLeadingZeroes=i,exports.simpleGroup=a;function t(e){return e.replace(/(0+)/g,`<span class="zero">$1</span>`)}function n(e,n=0){let r=e.split(``);return r.map((e,r)=>`<span class="digit value-${e} position-${r+n}">${t(e)}</span>`).join(``)}function r(e){return e.replace(/^(0+)/,`<span class="zero">$1</span>`)}function i(e){let t=e.split(`:`);return t.map(e=>r(e)).join(`:`)}function a(e,t=0){let n=e.split(`:`);return n.map((e,n)=>/group-v4/.test(e)?e:`<span class="hover-group group-${n+t}">${r(e)}</span>`)}}),h=e.__commonJSMin(exports=>{var t=Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]},n=Object.create?function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}:function(e,t){e.default=t},r=function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.ADDRESS_BOUNDARY=void 0,exports.groupPossibilities=a,exports.padGroup=o,exports.simpleRegularExpression=s,exports.possibleElisions=c;let i=r(p());function a(e){return`(${e.join(`|`)})`}function o(e){return e.length<4?`0{0,${4-e.length}}${e}`:e}exports.ADDRESS_BOUNDARY=`[^A-Fa-f0-9:]`;function s(e){let t=[];e.forEach((e,n)=>{let r=parseInt(e,16);r===0&&t.push(n)});let n=t.map(t=>e.map((e,n)=>{if(n===t){let t=n===0||n===i.GROUPS-1?`:`:``;return a([o(e),t])}return o(e)}).join(`:`));return n.push(e.map(o).join(`:`)),a(n)}function c(e,t,n){let r=t?``:`:`,i=n?``:`:`,o=[];!t&&!n&&o.push(`::`),t&&n&&o.push(``),(n&&!t||!n&&t)&&o.push(`:`),o.push(`${r}(:0{1,4}){1,${e-1}}`),o.push(`(0{1,4}:){1,${e-1}}${i}`),o.push(`(0{1,4}:){${e-1}}0{1,4}`);for(let t=1;t<e-1;t++)for(let n=1;n<e-t;n++)o.push(`(0{1,4}:){${n}}:(0{1,4}:){${e-n-t-1}}0{1,4}`);return a(o)}}),g=e.__commonJSMin(exports=>{var t=Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]},n=Object.create?function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}:function(e,t){e.default=t},r=function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.Address6=void 0;let i=r(l()),a=r(u()),o=r(p()),s=r(m()),c=f(),g=h(),_=d(),v=l();function y(e){if(!e)throw Error(`Assertion failed.`)}function b(e){let t=/(\d+)(\d{3})/;for(;t.test(e);)e=e.replace(t,`$1,$2`);return e}function x(e){return e=e.replace(/^(0{1,})([1-9]+)$/,`<span class="parse-error">$1</span>$2`),e=e.replace(/^(0{1,})(0)$/,`<span class="parse-error">$1</span>$2`),e}function S(e,t){let n=[],r=[],i;for(i=0;i<e.length;i++)i<t[0]?n.push(e[i]):i>t[1]&&r.push(e[i]);return n.concat([`compact`]).concat(r)}function C(e){return parseInt(e,16).toString(16).padStart(4,`0`)}function w(e){return e&255}var T=class e{constructor(e,t){this.addressMinusSuffix=``,this.parsedSubnet=``,this.subnet=`/128`,this.subnetMask=128,this.v4=!1,this.zone=``,this.isInSubnet=i.isInSubnet,this.isCorrect=i.isCorrect(o.BITS),t===void 0?this.groups=o.GROUPS:this.groups=t,this.address=e;let n=o.RE_SUBNET_STRING.exec(e);if(n){if(this.parsedSubnet=n[0].replace(`/`,``),this.subnetMask=parseInt(this.parsedSubnet,10),this.subnet=`/${this.subnetMask}`,Number.isNaN(this.subnetMask)||this.subnetMask<0||this.subnetMask>o.BITS)throw new _.AddressError(`Invalid subnet mask.`);e=e.replace(o.RE_SUBNET_STRING,``)}else if(/\//.test(e))throw new _.AddressError(`Invalid subnet mask.`);let r=o.RE_ZONE_STRING.exec(e);r&&(this.zone=r[0],e=e.replace(o.RE_ZONE_STRING,``)),this.addressMinusSuffix=e,this.parsedAddress=this.parse(this.addressMinusSuffix)}static isValid(t){try{return new e(t),!0}catch{return!1}}static fromBigInt(t){let n=t.toString(16).padStart(32,`0`),r=[],i;for(i=0;i<o.GROUPS;i++)r.push(n.slice(i*4,(i+1)*4));return new e(r.join(`:`))}static fromURL(t){let n,r=null,i;if(t.indexOf(`[`)!==-1&&t.indexOf(`]:`)!==-1){if(i=o.RE_URL_WITH_PORT.exec(t),i===null)return{error:`failed to parse address with port`,address:null,port:null};n=i[1],r=i[2]}else if(t.indexOf(`/`)!==-1){if(t=t.replace(/^[a-z0-9]+:\/\//,``),i=o.RE_URL.exec(t),i===null)return{error:`failed to parse address from URL`,address:null,port:null};n=i[1]}else n=t;return r?(r=parseInt(r,10),(r<0||r>65536)&&(r=null)):r=null,{address:new e(n),port:r}}static fromAddress4(t){let n=new c.Address4(t),r=o.BITS-(a.BITS-n.subnetMask);return new e(`::ffff:${n.correctForm()}/${r}`)}static fromArpa(t){let n=t.replace(/(\.ip6\.arpa)?\.$/,``),r=7;if(n.length!==63)throw new _.AddressError(`Invalid 'ip6.arpa' form.`);let i=n.split(`.`).reverse();for(let e=r;e>0;e--){let t=e*4;i.splice(t,0,`:`)}return n=i.join(``),new e(n)}microsoftTranscription(){return`${this.correctForm().replace(/:/g,`-`)}.ipv6-literal.net`}mask(e=this.subnetMask){return this.getBitsBase2(0,e)}possibleSubnets(e=128){let t=o.BITS-this.subnetMask,n=Math.abs(e-o.BITS),r=t-n;return r<0?`0`:b((BigInt(`2`)**BigInt(r)).toString(10))}_startAddress(){return BigInt(`0b${this.mask()+`0`.repeat(o.BITS-this.subnetMask)}`)}startAddress(){return e.fromBigInt(this._startAddress())}startAddressExclusive(){let t=BigInt(`1`);return e.fromBigInt(this._startAddress()+t)}_endAddress(){return BigInt(`0b${this.mask()+`1`.repeat(o.BITS-this.subnetMask)}`)}endAddress(){return e.fromBigInt(this._endAddress())}endAddressExclusive(){let t=BigInt(`1`);return e.fromBigInt(this._endAddress()-t)}getScope(){let e=o.SCOPES[parseInt(this.getBits(12,16).toString(10),10)];return this.getType()===`Global unicast`&&e!==`Link local`&&(e=`Global`),e||`Unknown`}getType(){for(let t of Object.keys(o.TYPES))if(this.isInSubnet(new e(t)))return o.TYPES[t];return`Global unicast`}getBits(e,t){return BigInt(`0b${this.getBitsBase2(e,t)}`)}getBitsBase2(e,t){return this.binaryZeroPad().slice(e,t)}getBitsBase16(e,t){let n=t-e;if(n%4!=0)throw Error(`Length of bits to retrieve must be divisible by four`);return this.getBits(e,t).toString(16).padStart(n/4,`0`)}getBitsPastSubnet(){return this.getBitsBase2(this.subnetMask,o.BITS)}reverseForm(e){e||={};let t=Math.floor(this.subnetMask/4),n=this.canonicalForm().replace(/:/g,``).split(``).slice(0,t).reverse().join(`.`);return t>0?e.omitSuffix?n:`${n}.ip6.arpa.`:e.omitSuffix?``:`ip6.arpa.`}correctForm(){let e,t=[],n=0,r=[];for(e=0;e<this.parsedAddress.length;e++){let t=parseInt(this.parsedAddress[e],16);t===0&&n++,t!==0&&n>0&&(n>1&&r.push([e-n,e-1]),n=0)}n>1&&r.push([this.parsedAddress.length-n,this.parsedAddress.length-1]);let i=r.map(e=>e[1]-e[0]+1);if(r.length>0){let e=i.indexOf(Math.max(...i));t=S(this.parsedAddress,r[e])}else t=this.parsedAddress;for(e=0;e<t.length;e++)t[e]!==`compact`&&(t[e]=parseInt(t[e],16).toString(16));let a=t.join(`:`);return a=a.replace(/^compact$/,`::`),a=a.replace(/(^compact)|(compact$)/,`:`),a=a.replace(/compact/,``),a}binaryZeroPad(){return this.bigInt().toString(2).padStart(o.BITS,`0`)}parse4in6(e){let t=e.split(`:`),n=t.slice(-1)[0],r=n.match(a.RE_ADDRESS);if(r){this.parsedAddress4=r[0],this.address4=new c.Address4(this.parsedAddress4);for(let t=0;t<this.address4.groups;t++)if(/^0[0-9]+/.test(this.address4.parsedAddress[t]))throw new _.AddressError(`IPv4 addresses can't have leading zeroes.`,e.replace(a.RE_ADDRESS,this.address4.parsedAddress.map(x).join(`.`)));this.v4=!0,t[t.length-1]=this.address4.toGroup6(),e=t.join(`:`)}return e}parse(e){e=this.parse4in6(e);let t=e.match(o.RE_BAD_CHARACTERS);if(t)throw new _.AddressError(`Bad character${t.length>1?`s`:``} detected in address: ${t.join(``)}`,e.replace(o.RE_BAD_CHARACTERS,`<span class="parse-error">$1</span>`));let n=e.match(o.RE_BAD_ADDRESS);if(n)throw new _.AddressError(`Address failed regex: ${n.join(``)}`,e.replace(o.RE_BAD_ADDRESS,`<span class="parse-error">$1</span>`));let r=[],i=e.split(`::`);if(i.length===2){let e=i[0].split(`:`),t=i[1].split(`:`);e.length===1&&e[0]===``&&(e=[]),t.length===1&&t[0]===``&&(t=[]);let n=this.groups-(e.length+t.length);if(!n)throw new _.AddressError(`Error parsing groups`);this.elidedGroups=n,this.elisionBegin=e.length,this.elisionEnd=e.length+this.elidedGroups,r=r.concat(e);for(let e=0;e<n;e++)r.push(`0`);r=r.concat(t)}else if(i.length===1)r=e.split(`:`),this.elidedGroups=0;else throw new _.AddressError(`Too many :: groups found`);if(r=r.map(e=>parseInt(e,16).toString(16)),r.length!==this.groups)throw new _.AddressError(`Incorrect number of groups found`);return r}canonicalForm(){return this.parsedAddress.map(C).join(`:`)}decimal(){return this.parsedAddress.map(e=>parseInt(e,16).toString(10).padStart(5,`0`)).join(`:`)}bigInt(){return BigInt(`0x${this.parsedAddress.map(C).join(``)}`)}to4(){let e=this.binaryZeroPad().split(``);return c.Address4.fromHex(BigInt(`0b${e.slice(96,128).join(``)}`).toString(16))}to4in6(){let t=this.to4(),n=new e(this.parsedAddress.slice(0,6).join(`:`),6),r=n.correctForm(),i=``;return/:$/.test(r)||(i=`:`),r+i+t.address}inspectTeredo(){let e=this.getBitsBase16(0,32),t=this.getBits(80,96),n=(t^BigInt(`0xffff`)).toString(),r=c.Address4.fromHex(this.getBitsBase16(32,64)),i=this.getBits(96,128),a=c.Address4.fromHex((i^BigInt(`0xffffffff`)).toString(16)),o=this.getBitsBase2(64,80),s=(0,v.testBit)(o,15),l=(0,v.testBit)(o,14),u=(0,v.testBit)(o,8),d=(0,v.testBit)(o,9),f=BigInt(`0b${o.slice(2,6)+o.slice(8,16)}`).toString(10);return{prefix:`${e.slice(0,4)}:${e.slice(4,8)}`,server4:r.address,client4:a.address,flags:o,coneNat:s,microsoft:{reserved:l,universalLocal:d,groupIndividual:u,nonce:f},udpPort:n}}inspect6to4(){let e=this.getBitsBase16(0,16),t=c.Address4.fromHex(this.getBitsBase16(16,48));return{prefix:e.slice(0,4),gateway:t.address}}to6to4(){if(!this.is4())return null;let t=[`2002`,this.getBitsBase16(96,112),this.getBitsBase16(112,128),``,`/16`].join(`:`);return new e(t)}toByteArray(){let e=this.bigInt().toString(16),t=`0`.repeat(e.length%2),n=`${t}${e}`,r=[];for(let e=0,t=n.length;e<t;e+=2)r.push(parseInt(n.substring(e,e+2),16));return r}toUnsignedByteArray(){return this.toByteArray().map(w)}static fromByteArray(e){return this.fromUnsignedByteArray(e.map(w))}static fromUnsignedByteArray(t){let n=BigInt(`256`),r=BigInt(`0`),i=BigInt(`1`);for(let e=t.length-1;e>=0;e--)r+=i*BigInt(t[e].toString(10)),i*=n;return e.fromBigInt(r)}isCanonical(){return this.addressMinusSuffix===this.canonicalForm()}isLinkLocal(){return this.getBitsBase2(0,64)===`1111111010000000000000000000000000000000000000000000000000000000`}isMulticast(){return this.getType()===`Multicast`}is4(){return this.v4}isTeredo(){return this.isInSubnet(new e(`2001::/32`))}is6to4(){return this.isInSubnet(new e(`2002::/16`))}isLoopback(){return this.getType()===`Loopback`}href(e){return e=e===void 0?``:`:${e}`,`http://[${this.correctForm()}]${e}/`}link(e){e||={},e.className===void 0&&(e.className=``),e.prefix===void 0&&(e.prefix=`/#address=`),e.v4===void 0&&(e.v4=!1);let t=this.correctForm;e.v4&&(t=this.to4in6);let n=t.call(this);return e.className?`<a href="${e.prefix}${n}" class="${e.className}">${n}</a>`:`<a href="${e.prefix}${n}">${n}</a>`}group(){if(this.elidedGroups===0)return s.simpleGroup(this.address).join(`:`);y(typeof this.elidedGroups==`number`),y(typeof this.elisionBegin==`number`);let e=[],[t,n]=this.address.split(`::`);t.length?e.push(...s.simpleGroup(t)):e.push(``);let r=[`hover-group`];for(let e=this.elisionBegin;e<this.elisionBegin+this.elidedGroups;e++)r.push(`group-${e}`);return e.push(`<span class="${r.join(` `)}"></span>`),n.length?e.push(...s.simpleGroup(n,this.elisionEnd)):e.push(``),this.is4()&&(y(this.address4 instanceof c.Address4),e.pop(),e.push(this.address4.groupForV6())),e.join(`:`)}regularExpressionString(t=!1){let n=[],r=new e(this.correctForm());if(r.elidedGroups===0)n.push((0,g.simpleRegularExpression)(r.parsedAddress));else if(r.elidedGroups===o.GROUPS)n.push((0,g.possibleElisions)(o.GROUPS));else{let e=r.address.split(`::`);e[0].length&&n.push((0,g.simpleRegularExpression)(e[0].split(`:`))),y(typeof r.elidedGroups==`number`),n.push((0,g.possibleElisions)(r.elidedGroups,e[0].length!==0,e[1].length!==0)),e[1].length&&n.push((0,g.simpleRegularExpression)(e[1].split(`:`))),n=[n.join(`:`)]}return t||(n=[`(?=^|`,g.ADDRESS_BOUNDARY,`|[^\\w\\:])(`,...n,`)(?=[^\\w\\:]|`,g.ADDRESS_BOUNDARY,`|$)`]),n.join(``)}regularExpression(e=!1){return new RegExp(this.regularExpressionString(e),`i`)}};exports.Address6=T}),_=e.__commonJSMin(exports=>{var t=Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]},n=Object.create?function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}:function(e,t){e.default=t},r=function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i in e)i!==`default`&&Object.prototype.hasOwnProperty.call(e,i)&&t(r,e,i);return n(r,e),r};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.v6=exports.AddressError=exports.Address6=exports.Address4=void 0;var i=f();Object.defineProperty(exports,`Address4`,{enumerable:!0,get:function(){return i.Address4}});var a=g();Object.defineProperty(exports,`Address6`,{enumerable:!0,get:function(){return a.Address6}});var o=d();Object.defineProperty(exports,`AddressError`,{enumerable:!0,get:function(){return o.AddressError}});let s=r(m());exports.v6={helpers:s}}),v=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.ipToBuffer=exports.int32ToIpv4=exports.ipv4ToInt32=exports.validateSocksClientChainOptions=exports.validateSocksClientOptions=void 0;let t=c(),n=s(),r=require(`stream`),i=_(),a=require(`net`);function o(e,i=[`connect`,`bind`,`associate`]){if(!n.SocksCommand[e.command])throw new t.SocksClientError(n.ERRORS.InvalidSocksCommand,e);if(i.indexOf(e.command)===-1)throw new t.SocksClientError(n.ERRORS.InvalidSocksCommandForOperation,e);if(!d(e.destination))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsDestination,e);if(!f(e.proxy))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsProxy,e);if(u(e.proxy,e),e.timeout&&!p(e.timeout))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsTimeout,e);if(e.existing_socket&&!(e.existing_socket instanceof r.Duplex))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsExistingSocket,e)}exports.validateSocksClientOptions=o;function l(e){if(e.command!==`connect`)throw new t.SocksClientError(n.ERRORS.InvalidSocksCommandChain,e);if(!d(e.destination))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsDestination,e);if(!(e.proxies&&Array.isArray(e.proxies)&&e.proxies.length>=2))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsProxiesLength,e);if(e.proxies.forEach(r=>{if(!f(r))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsProxy,e);u(r,e)}),e.timeout&&!p(e.timeout))throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsTimeout,e)}exports.validateSocksClientChainOptions=l;function u(e,r){if(e.custom_auth_method!==void 0){if(e.custom_auth_method<n.SOCKS5_CUSTOM_AUTH_START||e.custom_auth_method>n.SOCKS5_CUSTOM_AUTH_END)throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsCustomAuthRange,r);if(e.custom_auth_request_handler===void 0||typeof e.custom_auth_request_handler!=`function`||e.custom_auth_response_size===void 0||e.custom_auth_response_handler===void 0||typeof e.custom_auth_response_handler!=`function`)throw new t.SocksClientError(n.ERRORS.InvalidSocksClientOptionsCustomAuthOptions,r)}}function d(e){return e&&typeof e.host==`string`&&Buffer.byteLength(e.host)<256&&typeof e.port==`number`&&e.port>=0&&e.port<=65535}function f(e){return e&&(typeof e.host==`string`||typeof e.ipaddress==`string`)&&typeof e.port==`number`&&e.port>=0&&e.port<=65535&&(e.type===4||e.type===5)}function p(e){return typeof e==`number`&&e>0}function m(e){let t=new i.Address4(e);return t.toArray().reduce((e,t)=>(e<<8)+t,0)>>>0}exports.ipv4ToInt32=m;function h(e){let t=e>>>24&255,n=e>>>16&255,r=e>>>8&255,i=e&255;return[t,n,r,i].join(`.`)}exports.int32ToIpv4=h;function g(e){if(a.isIPv4(e)){let t=new i.Address4(e);return Buffer.from(t.toArray())}else if(a.isIPv6(e)){let t=new i.Address6(e);return Buffer.from(t.canonicalForm().split(`:`).map(e=>e.padStart(4,`0`)).join(``),`hex`)}else throw Error(`Invalid IP address format`)}exports.ipToBuffer=g}),y=e.__commonJSMin(exports=>{Object.defineProperty(exports,`__esModule`,{value:!0}),exports.ReceiveBuffer=void 0;var t=class{constructor(e=4096){this.buffer=Buffer.allocUnsafe(e),this.offset=0,this.originalSize=e}get length(){return this.offset}append(e){if(!Buffer.isBuffer(e))throw Error(`Attempted to append a non-buffer instance to ReceiveBuffer.`);if(this.offset+e.length>=this.buffer.length){let t=this.buffer;this.buffer=Buffer.allocUnsafe(Math.max(this.buffer.length+this.originalSize,this.buffer.length+e.length)),t.copy(this.buffer)}return e.copy(this.buffer,this.offset),this.offset+=e.length}peek(e){if(e>this.offset)throw Error(`Attempted to read beyond the bounds of the managed internal data.`);return this.buffer.slice(0,e)}get(e){if(e>this.offset)throw Error(`Attempted to read beyond the bounds of the managed internal data.`);let t=Buffer.allocUnsafe(e);return this.buffer.slice(0,e).copy(t),this.buffer.copyWithin(0,e,e+this.offset-e),this.offset-=e,t}};exports.ReceiveBuffer=t}),b=e.__commonJSMin(exports=>{var t=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})};Object.defineProperty(exports,`__esModule`,{value:!0}),exports.SocksClientError=exports.SocksClient=void 0;let n=require(`events`),r=require(`net`),i=o(),a=s(),l=v(),u=y(),d=c();Object.defineProperty(exports,`SocksClientError`,{enumerable:!0,get:function(){return d.SocksClientError}});let f=_();var p=class e extends n.EventEmitter{constructor(e){super(),this.options=Object.assign({},e),(0,l.validateSocksClientOptions)(e),this.setState(a.SocksClientState.Created)}static createConnection(t,n){return new Promise((r,i)=>{try{(0,l.validateSocksClientOptions)(t,[`connect`])}catch(e){return typeof n==`function`?(n(e),r(e)):i(e)}let a=new e(t);a.connect(t.existing_socket),a.once(`established`,e=>{a.removeAllListeners(),typeof n==`function`&&n(null,e),r(e)}),a.once(`error`,e=>{a.removeAllListeners(),typeof n==`function`?(n(e),r(e)):i(e)})})}static createConnectionChain(n,r){return new Promise((i,a)=>t(this,void 0,void 0,function*(){try{(0,l.validateSocksClientChainOptions)(n)}catch(e){return typeof r==`function`?(r(e),i(e)):a(e)}n.randomizeChain&&(0,d.shuffleArray)(n.proxies);try{let t;for(let r=0;r<n.proxies.length;r++){let i=n.proxies[r],a=r===n.proxies.length-1?n.destination:{host:n.proxies[r+1].host||n.proxies[r+1].ipaddress,port:n.proxies[r+1].port},o=yield e.createConnection({command:`connect`,proxy:i,destination:a,existing_socket:t});t||=o.socket}typeof r==`function`&&r(null,{socket:t}),i({socket:t})}catch(e){typeof r==`function`?(r(e),i(e)):a(e)}}))}static createUDPFrame(e){let t=new i.SmartBuffer;return t.writeUInt16BE(0),t.writeUInt8(e.frameNumber||0),r.isIPv4(e.remoteHost.host)?(t.writeUInt8(a.Socks5HostType.IPv4),t.writeUInt32BE((0,l.ipv4ToInt32)(e.remoteHost.host))):r.isIPv6(e.remoteHost.host)?(t.writeUInt8(a.Socks5HostType.IPv6),t.writeBuffer((0,l.ipToBuffer)(e.remoteHost.host))):(t.writeUInt8(a.Socks5HostType.Hostname),t.writeUInt8(Buffer.byteLength(e.remoteHost.host)),t.writeString(e.remoteHost.host)),t.writeUInt16BE(e.remoteHost.port),t.writeBuffer(e.data),t.toBuffer()}static parseUDPFrame(e){let t=i.SmartBuffer.fromBuffer(e);t.readOffset=2;let n=t.readUInt8(),r=t.readUInt8(),o;o=r===a.Socks5HostType.IPv4?(0,l.int32ToIpv4)(t.readUInt32BE()):r===a.Socks5HostType.IPv6?f.Address6.fromByteArray(Array.from(t.readBuffer(16))).canonicalForm():t.readString(t.readUInt8());let s=t.readUInt16BE();return{frameNumber:n,remoteHost:{host:o,port:s},data:t.readBuffer()}}setState(e){this.state!==a.SocksClientState.Error&&(this.state=e)}connect(e){this.onDataReceived=e=>this.onDataReceivedHandler(e),this.onClose=()=>this.onCloseHandler(),this.onError=e=>this.onErrorHandler(e),this.onConnect=()=>this.onConnectHandler();let t=setTimeout(()=>this.onEstablishedTimeout(),this.options.timeout||a.DEFAULT_TIMEOUT);t.unref&&typeof t.unref==`function`&&t.unref(),e?this.socket=e:this.socket=new r.Socket,this.socket.once(`close`,this.onClose),this.socket.once(`error`,this.onError),this.socket.once(`connect`,this.onConnect),this.socket.on(`data`,this.onDataReceived),this.setState(a.SocksClientState.Connecting),this.receiveBuffer=new u.ReceiveBuffer,e?this.socket.emit(`connect`):(this.socket.connect(this.getSocketOptions()),this.options.set_tcp_nodelay!==void 0&&this.options.set_tcp_nodelay!==null&&this.socket.setNoDelay(!!this.options.set_tcp_nodelay)),this.prependOnceListener(`established`,e=>{setImmediate(()=>{if(this.receiveBuffer.length>0){let t=this.receiveBuffer.get(this.receiveBuffer.length);e.socket.emit(`data`,t)}e.socket.resume()})})}getSocketOptions(){return Object.assign(Object.assign({},this.options.socket_options),{host:this.options.proxy.host||this.options.proxy.ipaddress,port:this.options.proxy.port})}onEstablishedTimeout(){this.state!==a.SocksClientState.Established&&this.state!==a.SocksClientState.BoundWaitingForConnection&&this.closeSocket(a.ERRORS.ProxyConnectionTimedOut)}onConnectHandler(){this.setState(a.SocksClientState.Connected),this.options.proxy.type===4?this.sendSocks4InitialHandshake():this.sendSocks5InitialHandshake(),this.setState(a.SocksClientState.SentInitialHandshake)}onDataReceivedHandler(e){this.receiveBuffer.append(e),this.processData()}processData(){for(;this.state!==a.SocksClientState.Established&&this.state!==a.SocksClientState.Error&&this.receiveBuffer.length>=this.nextRequiredPacketBufferSize;)if(this.state===a.SocksClientState.SentInitialHandshake)this.options.proxy.type===4?this.handleSocks4FinalHandshakeResponse():this.handleInitialSocks5HandshakeResponse();else if(this.state===a.SocksClientState.SentAuthentication)this.handleInitialSocks5AuthenticationHandshakeResponse();else if(this.state===a.SocksClientState.SentFinalHandshake)this.handleSocks5FinalHandshakeResponse();else if(this.state===a.SocksClientState.BoundWaitingForConnection)this.options.proxy.type===4?this.handleSocks4IncomingConnectionResponse():this.handleSocks5IncomingConnectionResponse();else{this.closeSocket(a.ERRORS.InternalError);break}}onCloseHandler(){this.closeSocket(a.ERRORS.SocketClosed)}onErrorHandler(e){this.closeSocket(e.message)}removeInternalSocketHandlers(){this.socket.pause(),this.socket.removeListener(`data`,this.onDataReceived),this.socket.removeListener(`close`,this.onClose),this.socket.removeListener(`error`,this.onError),this.socket.removeListener(`connect`,this.onConnect)}closeSocket(e){this.state!==a.SocksClientState.Error&&(this.setState(a.SocksClientState.Error),this.socket.destroy(),this.removeInternalSocketHandlers(),this.emit(`error`,new d.SocksClientError(e,this.options)))}sendSocks4InitialHandshake(){let e=this.options.proxy.userId||``,t=new i.SmartBuffer;t.writeUInt8(4),t.writeUInt8(a.SocksCommand[this.options.command]),t.writeUInt16BE(this.options.destination.port),r.isIPv4(this.options.destination.host)?(t.writeBuffer((0,l.ipToBuffer)(this.options.destination.host)),t.writeStringNT(e)):(t.writeUInt8(0),t.writeUInt8(0),t.writeUInt8(0),t.writeUInt8(1),t.writeStringNT(e),t.writeStringNT(this.options.destination.host)),this.nextRequiredPacketBufferSize=a.SOCKS_INCOMING_PACKET_SIZES.Socks4Response,this.socket.write(t.toBuffer())}handleSocks4FinalHandshakeResponse(){let e=this.receiveBuffer.get(8);if(e[1]!==a.Socks4Response.Granted)this.closeSocket(`${a.ERRORS.Socks4ProxyRejectedConnection} - (${a.Socks4Response[e[1]]})`);else if(a.SocksCommand[this.options.command]===a.SocksCommand.bind){let t=i.SmartBuffer.fromBuffer(e);t.readOffset=2;let n={port:t.readUInt16BE(),host:(0,l.int32ToIpv4)(t.readUInt32BE())};n.host===`0.0.0.0`&&(n.host=this.options.proxy.ipaddress),this.setState(a.SocksClientState.BoundWaitingForConnection),this.emit(`bound`,{remoteHost:n,socket:this.socket})}else this.setState(a.SocksClientState.Established),this.removeInternalSocketHandlers(),this.emit(`established`,{socket:this.socket})}handleSocks4IncomingConnectionResponse(){let e=this.receiveBuffer.get(8);if(e[1]!==a.Socks4Response.Granted)this.closeSocket(`${a.ERRORS.Socks4ProxyRejectedIncomingBoundConnection} - (${a.Socks4Response[e[1]]})`);else{let t=i.SmartBuffer.fromBuffer(e);t.readOffset=2;let n={port:t.readUInt16BE(),host:(0,l.int32ToIpv4)(t.readUInt32BE())};this.setState(a.SocksClientState.Established),this.removeInternalSocketHandlers(),this.emit(`established`,{remoteHost:n,socket:this.socket})}}sendSocks5InitialHandshake(){let e=new i.SmartBuffer,t=[a.Socks5Auth.NoAuth];(this.options.proxy.userId||this.options.proxy.password)&&t.push(a.Socks5Auth.UserPass),this.options.proxy.custom_auth_method!==void 0&&t.push(this.options.proxy.custom_auth_method),e.writeUInt8(5),e.writeUInt8(t.length);for(let n of t)e.writeUInt8(n);this.nextRequiredPacketBufferSize=a.SOCKS_INCOMING_PACKET_SIZES.Socks5InitialHandshakeResponse,this.socket.write(e.toBuffer()),this.setState(a.SocksClientState.SentInitialHandshake)}handleInitialSocks5HandshakeResponse(){let e=this.receiveBuffer.get(2);e[0]===5?e[1]===a.SOCKS5_NO_ACCEPTABLE_AUTH?this.closeSocket(a.ERRORS.InvalidSocks5InitialHandshakeNoAcceptedAuthType):e[1]===a.Socks5Auth.NoAuth?(this.socks5ChosenAuthType=a.Socks5Auth.NoAuth,this.sendSocks5CommandRequest()):e[1]===a.Socks5Auth.UserPass?(this.socks5ChosenAuthType=a.Socks5Auth.UserPass,this.sendSocks5UserPassAuthentication()):e[1]===this.options.proxy.custom_auth_method?(this.socks5ChosenAuthType=this.options.proxy.custom_auth_method,this.sendSocks5CustomAuthentication()):this.closeSocket(a.ERRORS.InvalidSocks5InitialHandshakeUnknownAuthType):this.closeSocket(a.ERRORS.InvalidSocks5IntiailHandshakeSocksVersion)}sendSocks5UserPassAuthentication(){let e=this.options.proxy.userId||``,t=this.options.proxy.password||``,n=new i.SmartBuffer;n.writeUInt8(1),n.writeUInt8(Buffer.byteLength(e)),n.writeString(e),n.writeUInt8(Buffer.byteLength(t)),n.writeString(t),this.nextRequiredPacketBufferSize=a.SOCKS_INCOMING_PACKET_SIZES.Socks5UserPassAuthenticationResponse,this.socket.write(n.toBuffer()),this.setState(a.SocksClientState.SentAuthentication)}sendSocks5CustomAuthentication(){return t(this,void 0,void 0,function*(){this.nextRequiredPacketBufferSize=this.options.proxy.custom_auth_response_size,this.socket.write(yield this.options.proxy.custom_auth_request_handler()),this.setState(a.SocksClientState.SentAuthentication)})}handleSocks5CustomAuthHandshakeResponse(e){return t(this,void 0,void 0,function*(){return yield this.options.proxy.custom_auth_response_handler(e)})}handleSocks5AuthenticationNoAuthHandshakeResponse(e){return t(this,void 0,void 0,function*(){return e[1]===0})}handleSocks5AuthenticationUserPassHandshakeResponse(e){return t(this,void 0,void 0,function*(){return e[1]===0})}handleInitialSocks5AuthenticationHandshakeResponse(){return t(this,void 0,void 0,function*(){this.setState(a.SocksClientState.ReceivedAuthenticationResponse);let e=!1;this.socks5ChosenAuthType===a.Socks5Auth.NoAuth?e=yield this.handleSocks5AuthenticationNoAuthHandshakeResponse(this.receiveBuffer.get(2)):this.socks5ChosenAuthType===a.Socks5Auth.UserPass?e=yield this.handleSocks5AuthenticationUserPassHandshakeResponse(this.receiveBuffer.get(2)):this.socks5ChosenAuthType===this.options.proxy.custom_auth_method&&(e=yield this.handleSocks5CustomAuthHandshakeResponse(this.receiveBuffer.get(this.options.proxy.custom_auth_response_size))),e?this.sendSocks5CommandRequest():this.closeSocket(a.ERRORS.Socks5AuthenticationFailed)})}sendSocks5CommandRequest(){let e=new i.SmartBuffer;e.writeUInt8(5),e.writeUInt8(a.SocksCommand[this.options.command]),e.writeUInt8(0),r.isIPv4(this.options.destination.host)?(e.writeUInt8(a.Socks5HostType.IPv4),e.writeBuffer((0,l.ipToBuffer)(this.options.destination.host))):r.isIPv6(this.options.destination.host)?(e.writeUInt8(a.Socks5HostType.IPv6),e.writeBuffer((0,l.ipToBuffer)(this.options.destination.host))):(e.writeUInt8(a.Socks5HostType.Hostname),e.writeUInt8(this.options.destination.host.length),e.writeString(this.options.destination.host)),e.writeUInt16BE(this.options.destination.port),this.nextRequiredPacketBufferSize=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader,this.socket.write(e.toBuffer()),this.setState(a.SocksClientState.SentFinalHandshake)}handleSocks5FinalHandshakeResponse(){let e=this.receiveBuffer.peek(5);if(e[0]!==5||e[1]!==a.Socks5Response.Granted)this.closeSocket(`${a.ERRORS.InvalidSocks5FinalHandshakeRejected} - ${a.Socks5Response[e[1]]}`);else{let t=e[3],n,r;if(t===a.Socks5HostType.IPv4){let e=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;if(this.receiveBuffer.length<e){this.nextRequiredPacketBufferSize=e;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(e).slice(4)),n={host:(0,l.int32ToIpv4)(r.readUInt32BE()),port:r.readUInt16BE()},n.host===`0.0.0.0`&&(n.host=this.options.proxy.ipaddress)}else if(t===a.Socks5HostType.Hostname){let t=e[4],o=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(t);if(this.receiveBuffer.length<o){this.nextRequiredPacketBufferSize=o;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(o).slice(5)),n={host:r.readString(t),port:r.readUInt16BE()}}else if(t===a.Socks5HostType.IPv6){let e=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;if(this.receiveBuffer.length<e){this.nextRequiredPacketBufferSize=e;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(e).slice(4)),n={host:f.Address6.fromByteArray(Array.from(r.readBuffer(16))).canonicalForm(),port:r.readUInt16BE()}}this.setState(a.SocksClientState.ReceivedFinalResponse),a.SocksCommand[this.options.command]===a.SocksCommand.connect?(this.setState(a.SocksClientState.Established),this.removeInternalSocketHandlers(),this.emit(`established`,{remoteHost:n,socket:this.socket})):a.SocksCommand[this.options.command]===a.SocksCommand.bind?(this.setState(a.SocksClientState.BoundWaitingForConnection),this.nextRequiredPacketBufferSize=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader,this.emit(`bound`,{remoteHost:n,socket:this.socket})):a.SocksCommand[this.options.command]===a.SocksCommand.associate&&(this.setState(a.SocksClientState.Established),this.removeInternalSocketHandlers(),this.emit(`established`,{remoteHost:n,socket:this.socket}))}}handleSocks5IncomingConnectionResponse(){let e=this.receiveBuffer.peek(5);if(e[0]!==5||e[1]!==a.Socks5Response.Granted)this.closeSocket(`${a.ERRORS.Socks5ProxyRejectedIncomingBoundConnection} - ${a.Socks5Response[e[1]]}`);else{let t=e[3],n,r;if(t===a.Socks5HostType.IPv4){let e=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;if(this.receiveBuffer.length<e){this.nextRequiredPacketBufferSize=e;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(e).slice(4)),n={host:(0,l.int32ToIpv4)(r.readUInt32BE()),port:r.readUInt16BE()},n.host===`0.0.0.0`&&(n.host=this.options.proxy.ipaddress)}else if(t===a.Socks5HostType.Hostname){let t=e[4],o=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(t);if(this.receiveBuffer.length<o){this.nextRequiredPacketBufferSize=o;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(o).slice(5)),n={host:r.readString(t),port:r.readUInt16BE()}}else if(t===a.Socks5HostType.IPv6){let e=a.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;if(this.receiveBuffer.length<e){this.nextRequiredPacketBufferSize=e;return}r=i.SmartBuffer.fromBuffer(this.receiveBuffer.get(e).slice(4)),n={host:f.Address6.fromByteArray(Array.from(r.readBuffer(16))).canonicalForm(),port:r.readUInt16BE()}}this.setState(a.SocksClientState.Established),this.removeInternalSocketHandlers(),this.emit(`established`,{remoteHost:n,socket:this.socket})}}get socksClientOptions(){return Object.assign({},this.options)}};exports.SocksClient=p}),x=e.__commonJSMin(exports=>{var t=Object.create?function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]},n=function(e,n){for(var r in e)r!==`default`&&!Object.prototype.hasOwnProperty.call(n,r)&&t(n,e,r)};Object.defineProperty(exports,`__esModule`,{value:!0}),n(b(),exports)}),S=e.__toESM(x(),1),C=e.__toESM(e.require_src(),1);const w=(0,C.default)(`socks-proxy-agent`),T=e=>e.servername===void 0&&e.host&&!n.isIP(e.host)?{...e,servername:e.host}:e;function E(e){let t=!1,n=5,r=e.hostname,i=parseInt(e.port,10)||1080;switch(e.protocol.replace(`:`,``)){case`socks4`:t=!0,n=4;break;case`socks4a`:n=4;break;case`socks5`:t=!0,n=5;break;case`socks`:n=5;break;case`socks5h`:n=5;break;default:throw TypeError(`A "socks" protocol must be specified! Got: ${String(e.protocol)}`)}let a={host:r,port:i,type:n};return e.username&&Object.defineProperty(a,`userId`,{value:decodeURIComponent(e.username),enumerable:!1}),e.password!=null&&Object.defineProperty(a,`password`,{value:decodeURIComponent(e.password),enumerable:!1}),{lookup:t,proxy:a}}var D=class extends e.Agent{constructor(e,n){super(n);let r=typeof e==`string`?new t.URL(e):e,{proxy:i,lookup:a}=E(r);this.shouldLookup=a,this.proxy=i,this.timeout=n?.timeout??null,this.socketOptions=n?.socketOptions??null}async connect(e,t){let{shouldLookup:n,proxy:a,timeout:o}=this;if(!t.host)throw Error("No `host` defined!");let{host:s}=t,{port:c,lookup:l=i.lookup}=t;n&&(s=await new Promise((e,t)=>{l(s,{},(n,r)=>{n?t(n):e(typeof r==`string`?r:r[0].address)})}));let u={proxy:a,destination:{host:s,port:typeof c==`number`?c:parseInt(c,10)},command:`connect`,timeout:o??void 0,socket_options:this.socketOptions??void 0},d=t=>{e.destroy(),f.destroy(),t&&t.destroy()};w(`Creating socks proxy connection: %o`,u);let{socket:f}=await S.SocksClient.createConnection(u);if(w(`Successfully created socks proxy connection`),o!==null&&(f.setTimeout(o),f.on(`timeout`,()=>d())),t.secureEndpoint){w(`Upgrading socket connection to TLS`);let e=r.connect({...O(T(t),`host`,`path`,`port`),socket:f});return e.once(`error`,t=>{w(`Socket TLS error`,t.message),d(e)}),e}return f}};D.protocols=[`socks`,`socks4`,`socks4a`,`socks5`,`socks5h`];function O(e,...t){let n={},r;for(r in e)t.includes(r)||(n[r]=e[r]);return n}exports.SocksProxyAgent=D;
|