constants.d.ts 4.7 KB

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