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