1/// <reference types="node" /> 2import { Duplex } from 'stream'; 3import { Socket, SocketConnectOpts } from 'net'; 4import { RequireOnlyOne } from './util'; 5declare const DEFAULT_TIMEOUT = 30000; 6declare type SocksProxyType = 4 | 5; 7declare const ERRORS: { 8 InvalidSocksCommand: string; 9 InvalidSocksCommandForOperation: string; 10 InvalidSocksCommandChain: string; 11 InvalidSocksClientOptionsDestination: string; 12 InvalidSocksClientOptionsExistingSocket: string; 13 InvalidSocksClientOptionsProxy: string; 14 InvalidSocksClientOptionsTimeout: string; 15 InvalidSocksClientOptionsProxiesLength: string; 16 NegotiationError: string; 17 SocketClosed: string; 18 ProxyConnectionTimedOut: string; 19 InternalError: string; 20 InvalidSocks4HandshakeResponse: string; 21 Socks4ProxyRejectedConnection: string; 22 InvalidSocks4IncomingConnectionResponse: string; 23 Socks4ProxyRejectedIncomingBoundConnection: string; 24 InvalidSocks5InitialHandshakeResponse: string; 25 InvalidSocks5IntiailHandshakeSocksVersion: string; 26 InvalidSocks5InitialHandshakeNoAcceptedAuthType: string; 27 InvalidSocks5InitialHandshakeUnknownAuthType: string; 28 Socks5AuthenticationFailed: string; 29 InvalidSocks5FinalHandshake: string; 30 InvalidSocks5FinalHandshakeRejected: string; 31 InvalidSocks5IncomingConnectionResponse: string; 32 Socks5ProxyRejectedIncomingBoundConnection: string; 33}; 34declare const SOCKS_INCOMING_PACKET_SIZES: { 35 Socks5InitialHandshakeResponse: number; 36 Socks5UserPassAuthenticationResponse: number; 37 Socks5ResponseHeader: number; 38 Socks5ResponseIPv4: number; 39 Socks5ResponseIPv6: number; 40 Socks5ResponseHostname: (hostNameLength: number) => number; 41 Socks4Response: number; 42}; 43declare type SocksCommandOption = 'connect' | 'bind' | 'associate'; 44declare enum SocksCommand { 45 connect = 1, 46 bind = 2, 47 associate = 3 48} 49declare enum Socks4Response { 50 Granted = 90, 51 Failed = 91, 52 Rejected = 92, 53 RejectedIdent = 93 54} 55declare enum Socks5Auth { 56 NoAuth = 0, 57 GSSApi = 1, 58 UserPass = 2 59} 60declare enum Socks5Response { 61 Granted = 0, 62 Failure = 1, 63 NotAllowed = 2, 64 NetworkUnreachable = 3, 65 HostUnreachable = 4, 66 ConnectionRefused = 5, 67 TTLExpired = 6, 68 CommandNotSupported = 7, 69 AddressNotSupported = 8 70} 71declare enum Socks5HostType { 72 IPv4 = 1, 73 Hostname = 3, 74 IPv6 = 4 75} 76declare enum SocksClientState { 77 Created = 0, 78 Connecting = 1, 79 Connected = 2, 80 SentInitialHandshake = 3, 81 ReceivedInitialHandshakeResponse = 4, 82 SentAuthentication = 5, 83 ReceivedAuthenticationResponse = 6, 84 SentFinalHandshake = 7, 85 ReceivedFinalResponse = 8, 86 BoundWaitingForConnection = 9, 87 Established = 10, 88 Disconnected = 11, 89 Error = 99 90} 91/** 92 * Represents a SocksProxy 93 */ 94declare type SocksProxy = RequireOnlyOne<{ 95 ipaddress?: string; 96 host?: string; 97 port: number; 98 type: SocksProxyType; 99 userId?: string; 100 password?: string; 101}, 'host' | 'ipaddress'>; 102/** 103 * Represents a remote host 104 */ 105interface SocksRemoteHost { 106 host: string; 107 port: number; 108} 109/** 110 * SocksClient connection options. 111 */ 112interface SocksClientOptions { 113 command: SocksCommandOption; 114 destination: SocksRemoteHost; 115 proxy: SocksProxy; 116 timeout?: number; 117 existing_socket?: Duplex; 118 set_tcp_nodelay?: boolean; 119 socket_options?: SocketConnectOpts; 120} 121/** 122 * SocksClient chain connection options. 123 */ 124interface SocksClientChainOptions { 125 command: 'connect'; 126 destination: SocksRemoteHost; 127 proxies: SocksProxy[]; 128 timeout?: number; 129 randomizeChain?: false; 130} 131interface SocksClientEstablishedEvent { 132 socket: Socket; 133 remoteHost?: SocksRemoteHost; 134} 135declare type SocksClientBoundEvent = SocksClientEstablishedEvent; 136interface SocksUDPFrameDetails { 137 frameNumber?: number; 138 remoteHost: SocksRemoteHost; 139 data: Buffer; 140} 141export { DEFAULT_TIMEOUT, ERRORS, SocksProxyType, SocksCommand, Socks4Response, Socks5Auth, Socks5HostType, Socks5Response, SocksClientState, SocksProxy, SocksRemoteHost, SocksCommandOption, SocksClientOptions, SocksClientChainOptions, SocksClientEstablishedEvent, SocksClientBoundEvent, SocksUDPFrameDetails, SOCKS_INCOMING_PACKET_SIZES }; 142