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