@armatofik/tgsnake-core 1.0.0
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/COPYING +674 -0
- package/COPYING.lesser +165 -0
- package/README.md +88 -0
- package/lib/package.json +46 -0
- package/lib/src/Logger.d.ts +3 -0
- package/lib/src/Logger.js +9 -0
- package/lib/src/Queue.d.ts +19 -0
- package/lib/src/Queue.js +52 -0
- package/lib/src/Timeout.d.ts +9 -0
- package/lib/src/Timeout.js +44 -0
- package/lib/src/Version.node.d.ts +4 -0
- package/lib/src/Version.node.js +26 -0
- package/lib/src/client/Auth.d.ts +40 -0
- package/lib/src/client/Auth.js +317 -0
- package/lib/src/client/Client.d.ts +83 -0
- package/lib/src/client/Client.js +461 -0
- package/lib/src/client/Session.d.ts +9 -0
- package/lib/src/client/Session.js +132 -0
- package/lib/src/client/index.d.ts +3 -0
- package/lib/src/client/index.js +39 -0
- package/lib/src/connection/TCP/TCPAbridged.d.ts +9 -0
- package/lib/src/connection/TCP/TCPAbridged.js +47 -0
- package/lib/src/connection/TCP/TCPAbridgedO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPAbridgedO.js +140 -0
- package/lib/src/connection/TCP/TCPFull.d.ts +10 -0
- package/lib/src/connection/TCP/TCPFull.js +43 -0
- package/lib/src/connection/TCP/TCPIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPIntermediate.js +31 -0
- package/lib/src/connection/TCP/TCPIntermediateO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPIntermediateO.js +123 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.js +38 -0
- package/lib/src/connection/TCP/index.d.ts +7 -0
- package/lib/src/connection/TCP/index.js +17 -0
- package/lib/src/connection/TCP/tcp.d.ts +17 -0
- package/lib/src/connection/TCP/tcp.js +98 -0
- package/lib/src/connection/WebSocket.d.ts +21 -0
- package/lib/src/connection/WebSocket.js +279 -0
- package/lib/src/connection/connection.d.ts +53 -0
- package/lib/src/connection/connection.js +189 -0
- package/lib/src/connection/index.d.ts +4 -0
- package/lib/src/connection/index.js +41 -0
- package/lib/src/crypto/Aes.d.ts +10 -0
- package/lib/src/crypto/Aes.js +135 -0
- package/lib/src/crypto/Mtproto.d.ts +5 -0
- package/lib/src/crypto/Mtproto.js +123 -0
- package/lib/src/crypto/Password.d.ts +5 -0
- package/lib/src/crypto/Password.js +92 -0
- package/lib/src/crypto/Prime.d.ts +4 -0
- package/lib/src/crypto/Prime.js +64 -0
- package/lib/src/crypto/RSA.d.ts +7 -0
- package/lib/src/crypto/RSA.js +99 -0
- package/lib/src/crypto/SecretChat.d.ts +5 -0
- package/lib/src/crypto/SecretChat.js +136 -0
- package/lib/src/crypto/index.d.ts +6 -0
- package/lib/src/crypto/index.js +42 -0
- package/lib/src/errors/Base.d.ts +9 -0
- package/lib/src/errors/Base.js +50 -0
- package/lib/src/errors/Client.d.ts +21 -0
- package/lib/src/errors/Client.js +29 -0
- package/lib/src/errors/File.d.ts +13 -0
- package/lib/src/errors/File.js +30 -0
- package/lib/src/errors/RpcError.d.ts +22 -0
- package/lib/src/errors/RpcError.js +120 -0
- package/lib/src/errors/SecretChat.d.ts +13 -0
- package/lib/src/errors/SecretChat.js +30 -0
- package/lib/src/errors/WebSocket.d.ts +13 -0
- package/lib/src/errors/WebSocket.js +30 -0
- package/lib/src/errors/exceptions/All.d.ts +774 -0
- package/lib/src/errors/exceptions/All.js +778 -0
- package/lib/src/errors/exceptions/BadRequest400.d.ts +2345 -0
- package/lib/src/errors/exceptions/BadRequest400.js +2945 -0
- package/lib/src/errors/exceptions/Flood420.d.ts +37 -0
- package/lib/src/errors/exceptions/Flood420.js +49 -0
- package/lib/src/errors/exceptions/Forbidden403.d.ts +205 -0
- package/lib/src/errors/exceptions/Forbidden403.js +260 -0
- package/lib/src/errors/exceptions/InternalServerError500.d.ts +221 -0
- package/lib/src/errors/exceptions/InternalServerError500.js +280 -0
- package/lib/src/errors/exceptions/NotAcceptable406.d.ts +117 -0
- package/lib/src/errors/exceptions/NotAcceptable406.js +149 -0
- package/lib/src/errors/exceptions/NotFound404.d.ts +9 -0
- package/lib/src/errors/exceptions/NotFound404.js +14 -0
- package/lib/src/errors/exceptions/SeeOther303.d.ts +25 -0
- package/lib/src/errors/exceptions/SeeOther303.js +34 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.d.ts +17 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.js +24 -0
- package/lib/src/errors/exceptions/Unauthorized401.d.ts +41 -0
- package/lib/src/errors/exceptions/Unauthorized401.js +54 -0
- package/lib/src/errors/exceptions/index.d.ts +10 -0
- package/lib/src/errors/exceptions/index.js +48 -0
- package/lib/src/errors/index.d.ts +31 -0
- package/lib/src/errors/index.js +111 -0
- package/lib/src/file/Download.d.ts +11 -0
- package/lib/src/file/Download.js +118 -0
- package/lib/src/file/File.d.ts +20 -0
- package/lib/src/file/File.js +82 -0
- package/lib/src/file/Upload.d.ts +19 -0
- package/lib/src/file/Upload.js +250 -0
- package/lib/src/file/index.d.ts +3 -0
- package/lib/src/file/index.js +11 -0
- package/lib/src/helpers.d.ts +34 -0
- package/lib/src/helpers.js +358 -0
- package/lib/src/index.d.ts +16 -0
- package/lib/src/index.js +56 -0
- package/lib/src/platform.node.d.ts +36 -0
- package/lib/src/platform.node.js +109 -0
- package/lib/src/raw/All.d.ts +2400 -0
- package/lib/src/raw/All.js +2403 -0
- package/lib/src/raw/Raw.d.ts +29195 -0
- package/lib/src/raw/Raw.js +97277 -0
- package/lib/src/raw/core/BytesIO.d.ts +33 -0
- package/lib/src/raw/core/BytesIO.js +145 -0
- package/lib/src/raw/core/GzipPacked.d.ts +10 -0
- package/lib/src/raw/core/GzipPacked.js +60 -0
- package/lib/src/raw/core/Message.d.ts +13 -0
- package/lib/src/raw/core/Message.js +81 -0
- package/lib/src/raw/core/MsgContainer.d.ts +11 -0
- package/lib/src/raw/core/MsgContainer.js +69 -0
- package/lib/src/raw/core/TLObject.d.ts +19 -0
- package/lib/src/raw/core/TLObject.js +108 -0
- package/lib/src/raw/core/UpdateSecretChat.d.ts +40 -0
- package/lib/src/raw/core/UpdateSecretChat.js +88 -0
- package/lib/src/raw/core/index.d.ts +8 -0
- package/lib/src/raw/core/index.js +52 -0
- package/lib/src/raw/core/primitive/Bool.d.ts +20 -0
- package/lib/src/raw/core/primitive/Bool.js +41 -0
- package/lib/src/raw/core/primitive/Bytes.d.ts +7 -0
- package/lib/src/raw/core/primitive/Bytes.js +41 -0
- package/lib/src/raw/core/primitive/Double.d.ts +7 -0
- package/lib/src/raw/core/primitive/Double.js +24 -0
- package/lib/src/raw/core/primitive/Float.d.ts +7 -0
- package/lib/src/raw/core/primitive/Float.js +24 -0
- package/lib/src/raw/core/primitive/Int.d.ts +23 -0
- package/lib/src/raw/core/primitive/Int.js +122 -0
- package/lib/src/raw/core/primitive/String.d.ts +7 -0
- package/lib/src/raw/core/primitive/String.js +15 -0
- package/lib/src/raw/core/primitive/Vector.d.ts +9 -0
- package/lib/src/raw/core/primitive/Vector.js +50 -0
- package/lib/src/raw/core/primitive/index.d.ts +7 -0
- package/lib/src/raw/core/primitive/index.js +22 -0
- package/lib/src/raw/index.d.ts +3 -0
- package/lib/src/raw/index.js +17 -0
- package/lib/src/session/Auth.d.ts +15 -0
- package/lib/src/session/Auth.js +254 -0
- package/lib/src/session/Session.d.ts +58 -0
- package/lib/src/session/Session.js +571 -0
- package/lib/src/session/index.d.ts +7 -0
- package/lib/src/session/index.js +49 -0
- package/lib/src/session/internals/DataCenter.d.ts +42 -0
- package/lib/src/session/internals/DataCenter.js +80 -0
- package/lib/src/session/internals/MsgFactory.d.ts +3 -0
- package/lib/src/session/internals/MsgFactory.js +23 -0
- package/lib/src/session/internals/MsgId.d.ts +9 -0
- package/lib/src/session/internals/MsgId.js +24 -0
- package/lib/src/session/internals/SeqNo.d.ts +6 -0
- package/lib/src/session/internals/SeqNo.js +18 -0
- package/lib/src/session/secretChats/SecretChat.d.ts +29 -0
- package/lib/src/session/secretChats/SecretChat.js +527 -0
- package/lib/src/session/secretChats/index.d.ts +1 -0
- package/lib/src/session/secretChats/index.js +5 -0
- package/lib/src/storage/Abstract.d.ts +68 -0
- package/lib/src/storage/Abstract.js +6 -0
- package/lib/src/storage/SecretChat.d.ts +42 -0
- package/lib/src/storage/SecretChat.js +99 -0
- package/lib/src/storage/Session.d.ts +63 -0
- package/lib/src/storage/Session.js +245 -0
- package/lib/src/storage/StringSession.d.ts +4 -0
- package/lib/src/storage/StringSession.js +77 -0
- package/lib/src/storage/index.d.ts +4 -0
- package/lib/src/storage/index.js +12 -0
- package/package.json +46 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPAbridged = void 0;
|
|
4
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
5
|
+
const tcp_js_1 = require("./tcp.js");
|
|
6
|
+
const helpers_js_1 = require("../../helpers.js");
|
|
7
|
+
class TCPAbridged extends tcp_js_1.TCP {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
async connect(ip, port, proxy, dcId) {
|
|
12
|
+
await super.connect(ip, port, proxy, dcId);
|
|
13
|
+
return await super.send(platform_node_js_1.Buffer.from('ef', 'hex'));
|
|
14
|
+
}
|
|
15
|
+
async send(data) {
|
|
16
|
+
const length = Math.round(platform_node_js_1.Buffer.byteLength(data) / 4);
|
|
17
|
+
if (length <= 126) {
|
|
18
|
+
const mark = platform_node_js_1.Buffer.from([length]);
|
|
19
|
+
return await super.send(platform_node_js_1.Buffer.concat([mark, data]));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return await super.send(platform_node_js_1.Buffer.concat([
|
|
23
|
+
platform_node_js_1.Buffer.concat([
|
|
24
|
+
platform_node_js_1.Buffer.from('7f', 'hex'),
|
|
25
|
+
(0, helpers_js_1.bigintToBuffer)(BigInt(length), 3),
|
|
26
|
+
]),
|
|
27
|
+
data,
|
|
28
|
+
]));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async recv(_length = 0) {
|
|
32
|
+
let length = await super.recv(1);
|
|
33
|
+
if (!length)
|
|
34
|
+
return;
|
|
35
|
+
if (length.equals(platform_node_js_1.Buffer.from('7f', 'hex'))) {
|
|
36
|
+
length = await super.recv(3);
|
|
37
|
+
if (!length)
|
|
38
|
+
return;
|
|
39
|
+
return await super.recv(platform_node_js_1.Buffer.concat([
|
|
40
|
+
length,
|
|
41
|
+
platform_node_js_1.Buffer.alloc(1),
|
|
42
|
+
]).readInt32LE(0) * 4);
|
|
43
|
+
}
|
|
44
|
+
return await super.recv(length[0] * 4);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.TCPAbridged = TCPAbridged;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TCP } from './tcp.js';
|
|
2
|
+
import { Buffer } from '../../platform.node.js';
|
|
3
|
+
import type { ProxyInterface } from '../connection.js';
|
|
4
|
+
export declare class TCPAbridgedO extends TCP {
|
|
5
|
+
private _reserved;
|
|
6
|
+
private _encryptor;
|
|
7
|
+
private _decryptor;
|
|
8
|
+
constructor();
|
|
9
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, dcId?: number): Promise<void>;
|
|
10
|
+
send(data: Buffer): Promise<void>;
|
|
11
|
+
recv(_length?: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPAbridgedO = void 0;
|
|
4
|
+
const tcp_js_1 = require("./tcp.js");
|
|
5
|
+
const helpers_js_1 = require("../../helpers.js");
|
|
6
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
7
|
+
const Aes_js_1 = require("../../crypto/Aes.js");
|
|
8
|
+
class TCPAbridgedO extends tcp_js_1.TCP {
|
|
9
|
+
_reserved;
|
|
10
|
+
_encryptor;
|
|
11
|
+
_decryptor;
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this._reserved = [
|
|
15
|
+
platform_node_js_1.Buffer.from('HEAD'),
|
|
16
|
+
platform_node_js_1.Buffer.from('POST'),
|
|
17
|
+
platform_node_js_1.Buffer.from('GET'),
|
|
18
|
+
platform_node_js_1.Buffer.from('OPTI'),
|
|
19
|
+
platform_node_js_1.Buffer.from('eeeeeeee', 'hex'),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
async connect(ip, port, proxy, dcId) {
|
|
23
|
+
await super.connect(ip, port, proxy, dcId);
|
|
24
|
+
let nonce;
|
|
25
|
+
if (proxy && 'secret' in proxy && 'port' in proxy && 'server' in proxy && dcId) {
|
|
26
|
+
let secret = typeof proxy.secret === 'string'
|
|
27
|
+
? (0, helpers_js_1.normalizeSecretString)(proxy.secret)
|
|
28
|
+
: platform_node_js_1.Buffer.from(proxy.secret);
|
|
29
|
+
secret =
|
|
30
|
+
platform_node_js_1.Buffer.byteLength(secret) === 17 && secret[0] === 0xdd
|
|
31
|
+
? secret.subarray(1)
|
|
32
|
+
: secret;
|
|
33
|
+
while (true) {
|
|
34
|
+
nonce = platform_node_js_1.crypto.randomBytes(64);
|
|
35
|
+
if (!platform_node_js_1.Buffer.from([nonce[0]]).equals(platform_node_js_1.Buffer.from('ef', 'hex')) &&
|
|
36
|
+
!(0, helpers_js_1.includesBuffer)(this._reserved, nonce) &&
|
|
37
|
+
!nonce.subarray(4, 8).equals(platform_node_js_1.Buffer.alloc(4))) {
|
|
38
|
+
nonce[56] =
|
|
39
|
+
nonce[57] =
|
|
40
|
+
nonce[58] =
|
|
41
|
+
nonce[59] =
|
|
42
|
+
0xef;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const temp = (0, helpers_js_1.sliceBuffer)(nonce, 55, 7, -1);
|
|
47
|
+
const encryptionKey = sha256(platform_node_js_1.Buffer.concat([
|
|
48
|
+
nonce.subarray(8, 40),
|
|
49
|
+
secret,
|
|
50
|
+
]));
|
|
51
|
+
const encryptionIv = nonce.subarray(40, 56);
|
|
52
|
+
const decryptionKey = sha256(platform_node_js_1.Buffer.concat([
|
|
53
|
+
temp.subarray(0, 32),
|
|
54
|
+
secret,
|
|
55
|
+
]));
|
|
56
|
+
const decryptionIv = temp.subarray(32, 48);
|
|
57
|
+
this._encryptor = (0, Aes_js_1.ctr256Cipher)(encryptionKey, encryptionIv);
|
|
58
|
+
this._decryptor = (0, Aes_js_1.ctr256Cipher)(decryptionKey, decryptionIv);
|
|
59
|
+
const _dcId = platform_node_js_1.Buffer.alloc(2);
|
|
60
|
+
_dcId.writeInt8(dcId, 0);
|
|
61
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
62
|
+
nonce.subarray(0, 60),
|
|
63
|
+
_dcId,
|
|
64
|
+
nonce.subarray(62),
|
|
65
|
+
]);
|
|
66
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
67
|
+
nonce.subarray(0, 56),
|
|
68
|
+
this._encryptor(nonce).subarray(56, 64),
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
while (true) {
|
|
73
|
+
nonce = platform_node_js_1.crypto.randomBytes(64);
|
|
74
|
+
if (!platform_node_js_1.Buffer.from([nonce[0]]).equals(platform_node_js_1.Buffer.from('ef', 'hex')) &&
|
|
75
|
+
!(0, helpers_js_1.includesBuffer)(this._reserved, nonce) &&
|
|
76
|
+
!nonce.subarray(4, 8).equals(platform_node_js_1.Buffer.alloc(4))) {
|
|
77
|
+
nonce[56] =
|
|
78
|
+
nonce[57] =
|
|
79
|
+
nonce[58] =
|
|
80
|
+
nonce[59] =
|
|
81
|
+
0xef;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const temp = (0, helpers_js_1.sliceBuffer)(nonce, 55, 7, -1);
|
|
86
|
+
const encryptionKey = nonce.subarray(8, 40);
|
|
87
|
+
const encryptionIv = nonce.subarray(40, 56);
|
|
88
|
+
const decryptionKey = temp.subarray(0, 32);
|
|
89
|
+
const decryptionIv = temp.subarray(32, 48);
|
|
90
|
+
this._encryptor = (0, Aes_js_1.ctr256Cipher)(encryptionKey, encryptionIv);
|
|
91
|
+
this._decryptor = (0, Aes_js_1.ctr256Cipher)(decryptionKey, decryptionIv);
|
|
92
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
93
|
+
nonce.subarray(0, 56),
|
|
94
|
+
this._encryptor(nonce).subarray(56, 64),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
await super.send(nonce);
|
|
98
|
+
}
|
|
99
|
+
async send(data) {
|
|
100
|
+
const length = Math.round(platform_node_js_1.Buffer.byteLength(data) / 4);
|
|
101
|
+
if (length <= 126) {
|
|
102
|
+
return await super.send(this._encryptor(platform_node_js_1.Buffer.concat([
|
|
103
|
+
platform_node_js_1.Buffer.from([length]),
|
|
104
|
+
data,
|
|
105
|
+
])));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return await super.send(this._encryptor(platform_node_js_1.Buffer.concat([
|
|
109
|
+
platform_node_js_1.Buffer.concat([
|
|
110
|
+
platform_node_js_1.Buffer.from('7f', 'hex'),
|
|
111
|
+
(0, helpers_js_1.bigintToBuffer)(BigInt(length), 3),
|
|
112
|
+
]),
|
|
113
|
+
data,
|
|
114
|
+
])));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async recv(_length = 0) {
|
|
118
|
+
let length = await super.recv(1);
|
|
119
|
+
if (!length)
|
|
120
|
+
return;
|
|
121
|
+
length = platform_node_js_1.Buffer.from(this._decryptor(length));
|
|
122
|
+
if (length.equals(platform_node_js_1.Buffer.from('7f', 'hex'))) {
|
|
123
|
+
length = await super.recv(3);
|
|
124
|
+
if (!length)
|
|
125
|
+
return;
|
|
126
|
+
length = platform_node_js_1.Buffer.from(this._decryptor(length));
|
|
127
|
+
return platform_node_js_1.Buffer.from(this._decryptor((await super.recv(platform_node_js_1.Buffer.concat([
|
|
128
|
+
length,
|
|
129
|
+
platform_node_js_1.Buffer.alloc(1),
|
|
130
|
+
]).readInt32LE(0) * 4))));
|
|
131
|
+
}
|
|
132
|
+
return platform_node_js_1.Buffer.from(this._decryptor((await super.recv(length[0] * 4))));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.TCPAbridgedO = TCPAbridgedO;
|
|
136
|
+
function sha256(data) {
|
|
137
|
+
const hash = platform_node_js_1.crypto.createHash('sha256');
|
|
138
|
+
hash.update(data);
|
|
139
|
+
return hash.digest();
|
|
140
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Buffer } from '../../platform.node.js';
|
|
2
|
+
import { TCP } from './tcp.js';
|
|
3
|
+
import type { ProxyInterface } from '../connection.js';
|
|
4
|
+
export declare class TCPFull extends TCP {
|
|
5
|
+
private _seq;
|
|
6
|
+
constructor();
|
|
7
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, dcId?: number): Promise<void>;
|
|
8
|
+
send(data: Buffer): Promise<void>;
|
|
9
|
+
recv(_length?: number): Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPFull = void 0;
|
|
4
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
5
|
+
const tcp_js_1 = require("./tcp.js");
|
|
6
|
+
const helpers_js_1 = require("../../helpers.js");
|
|
7
|
+
class TCPFull extends tcp_js_1.TCP {
|
|
8
|
+
_seq;
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
async connect(ip, port, proxy, dcId) {
|
|
13
|
+
await super.connect(ip, port, proxy, dcId);
|
|
14
|
+
this._seq = 0;
|
|
15
|
+
}
|
|
16
|
+
async send(data) {
|
|
17
|
+
const allocSum = platform_node_js_1.Buffer.alloc(8);
|
|
18
|
+
allocSum.writeInt32LE(platform_node_js_1.Buffer.byteLength(data) + 12, 0);
|
|
19
|
+
allocSum.writeInt32LE(this._seq, 4);
|
|
20
|
+
data = platform_node_js_1.Buffer.concat([allocSum, data]);
|
|
21
|
+
const crc = (0, helpers_js_1.crc32)(data);
|
|
22
|
+
const bcrc = platform_node_js_1.Buffer.alloc(4);
|
|
23
|
+
bcrc.writeUInt32LE(crc, 0);
|
|
24
|
+
data = platform_node_js_1.Buffer.concat([data, bcrc]);
|
|
25
|
+
this._seq += 1;
|
|
26
|
+
await super.send(data);
|
|
27
|
+
}
|
|
28
|
+
async recv(_length = 0) {
|
|
29
|
+
const length = await super.recv(4);
|
|
30
|
+
if (!length)
|
|
31
|
+
return;
|
|
32
|
+
let packet = await super.recv(length.readInt32LE(0) - 4);
|
|
33
|
+
if (!packet)
|
|
34
|
+
return;
|
|
35
|
+
packet = platform_node_js_1.Buffer.concat([length, packet]);
|
|
36
|
+
const checksum = packet.subarray(-4);
|
|
37
|
+
packet = packet.subarray(0, -4);
|
|
38
|
+
if ((0, helpers_js_1.crc32)(packet) !== checksum.readUInt32LE(0))
|
|
39
|
+
return;
|
|
40
|
+
return packet.subarray(8);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.TCPFull = TCPFull;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Buffer } from '../../platform.node.js';
|
|
2
|
+
import { TCP } from './tcp.js';
|
|
3
|
+
import type { ProxyInterface } from '../connection.js';
|
|
4
|
+
export declare class TCPIntermediate extends TCP {
|
|
5
|
+
constructor();
|
|
6
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, dcId?: number): Promise<void>;
|
|
7
|
+
send(data: Buffer): Promise<void>;
|
|
8
|
+
recv(_length?: number): Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPIntermediate = void 0;
|
|
4
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
5
|
+
const tcp_js_1 = require("./tcp.js");
|
|
6
|
+
class TCPIntermediate extends tcp_js_1.TCP {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
async connect(ip, port, proxy, dcId) {
|
|
11
|
+
await super.connect(ip, port, proxy, dcId);
|
|
12
|
+
await super.send(platform_node_js_1.Buffer.concat([
|
|
13
|
+
platform_node_js_1.Buffer.from('ee', 'hex'),
|
|
14
|
+
platform_node_js_1.Buffer.from('ee', 'hex'),
|
|
15
|
+
platform_node_js_1.Buffer.from('ee', 'hex'),
|
|
16
|
+
platform_node_js_1.Buffer.from('ee', 'hex'),
|
|
17
|
+
]));
|
|
18
|
+
}
|
|
19
|
+
async send(data) {
|
|
20
|
+
const allocLength = platform_node_js_1.Buffer.alloc(4);
|
|
21
|
+
allocLength.writeInt32LE(platform_node_js_1.Buffer.byteLength(data), 0);
|
|
22
|
+
await super.send(platform_node_js_1.Buffer.concat([allocLength, data]));
|
|
23
|
+
}
|
|
24
|
+
async recv(_length = 0) {
|
|
25
|
+
const length = await super.recv(4);
|
|
26
|
+
if (!length)
|
|
27
|
+
return;
|
|
28
|
+
return await super.recv(length.readInt32LE(0));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.TCPIntermediate = TCPIntermediate;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TCP } from './tcp.js';
|
|
2
|
+
import { Buffer } from '../../platform.node.js';
|
|
3
|
+
import type { ProxyInterface } from '../connection.js';
|
|
4
|
+
export declare class TCPIntermediateO extends TCP {
|
|
5
|
+
private _reserved;
|
|
6
|
+
private _encryptor;
|
|
7
|
+
private _decryptor;
|
|
8
|
+
constructor();
|
|
9
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, dcId?: number): Promise<void>;
|
|
10
|
+
send(data: Buffer): Promise<void>;
|
|
11
|
+
recv(_length?: number): Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPIntermediateO = void 0;
|
|
4
|
+
const tcp_js_1 = require("./tcp.js");
|
|
5
|
+
const helpers_js_1 = require("../../helpers.js");
|
|
6
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
7
|
+
const Aes_js_1 = require("../../crypto/Aes.js");
|
|
8
|
+
const index_js_1 = require("../../raw/core/index.js");
|
|
9
|
+
class TCPIntermediateO extends tcp_js_1.TCP {
|
|
10
|
+
_reserved;
|
|
11
|
+
_encryptor;
|
|
12
|
+
_decryptor;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this._reserved = [
|
|
16
|
+
platform_node_js_1.Buffer.from('HEAD'),
|
|
17
|
+
platform_node_js_1.Buffer.from('POST'),
|
|
18
|
+
platform_node_js_1.Buffer.from('GET'),
|
|
19
|
+
platform_node_js_1.Buffer.from('OPTI'),
|
|
20
|
+
platform_node_js_1.Buffer.from('eeeeeeee', 'hex'),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
async connect(ip, port, proxy, dcId) {
|
|
24
|
+
await super.connect(ip, port, proxy, dcId);
|
|
25
|
+
let nonce;
|
|
26
|
+
if (proxy && 'secret' in proxy && 'port' in proxy && 'server' in proxy && dcId) {
|
|
27
|
+
let secret = typeof proxy.secret === 'string'
|
|
28
|
+
? (0, helpers_js_1.normalizeSecretString)(proxy.secret)
|
|
29
|
+
: platform_node_js_1.Buffer.from(proxy.secret);
|
|
30
|
+
secret =
|
|
31
|
+
platform_node_js_1.Buffer.byteLength(secret) === 17 && secret[0] === 0xdd
|
|
32
|
+
? secret.subarray(1)
|
|
33
|
+
: secret;
|
|
34
|
+
while (true) {
|
|
35
|
+
nonce = platform_node_js_1.crypto.randomBytes(64);
|
|
36
|
+
if (!platform_node_js_1.Buffer.from([nonce[0]]).equals(platform_node_js_1.Buffer.from('ef', 'hex')) &&
|
|
37
|
+
!(0, helpers_js_1.includesBuffer)(this._reserved, nonce) &&
|
|
38
|
+
!nonce.subarray(4, 8).equals(platform_node_js_1.Buffer.alloc(4))) {
|
|
39
|
+
nonce[56] =
|
|
40
|
+
nonce[57] =
|
|
41
|
+
nonce[58] =
|
|
42
|
+
nonce[59] =
|
|
43
|
+
0xee;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const temp = (0, helpers_js_1.sliceBuffer)(nonce, 55, 7, -1);
|
|
48
|
+
const encryptionKey = sha256(platform_node_js_1.Buffer.concat([
|
|
49
|
+
nonce.subarray(8, 40),
|
|
50
|
+
secret,
|
|
51
|
+
]));
|
|
52
|
+
const encryptionIv = nonce.subarray(40, 56);
|
|
53
|
+
const decryptionIv = sha256(platform_node_js_1.Buffer.concat([
|
|
54
|
+
temp.subarray(0, 32),
|
|
55
|
+
secret,
|
|
56
|
+
]));
|
|
57
|
+
const decryptionKey = temp.subarray(32, 48);
|
|
58
|
+
this._encryptor = (0, Aes_js_1.ctr256Cipher)(encryptionKey, encryptionIv);
|
|
59
|
+
this._decryptor = (0, Aes_js_1.ctr256Cipher)(decryptionKey, decryptionIv);
|
|
60
|
+
const _dcId = platform_node_js_1.Buffer.alloc(2);
|
|
61
|
+
_dcId.writeInt8(dcId, 0);
|
|
62
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
63
|
+
nonce.subarray(0, 60),
|
|
64
|
+
_dcId,
|
|
65
|
+
nonce.subarray(62),
|
|
66
|
+
]);
|
|
67
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
68
|
+
nonce.subarray(0, 56),
|
|
69
|
+
this._encryptor(nonce).subarray(56, 64),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
while (true) {
|
|
74
|
+
nonce = platform_node_js_1.crypto.randomBytes(64);
|
|
75
|
+
if (!platform_node_js_1.Buffer.from([nonce[0]]).equals(platform_node_js_1.Buffer.from('ef', 'hex')) &&
|
|
76
|
+
!(0, helpers_js_1.includesBuffer)(this._reserved, nonce) &&
|
|
77
|
+
!nonce.subarray(4, 8).equals(platform_node_js_1.Buffer.alloc(4))) {
|
|
78
|
+
nonce[56] =
|
|
79
|
+
nonce[57] =
|
|
80
|
+
nonce[58] =
|
|
81
|
+
nonce[59] =
|
|
82
|
+
0xee;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const temp = (0, helpers_js_1.sliceBuffer)(nonce, 55, 7, -1);
|
|
87
|
+
const encryptionKey = nonce.subarray(8, 40);
|
|
88
|
+
const encryptionIv = nonce.subarray(40, 56);
|
|
89
|
+
const decryptionKey = temp.subarray(0, 32);
|
|
90
|
+
const decryptionIv = temp.subarray(32, 48);
|
|
91
|
+
this._encryptor = (0, Aes_js_1.ctr256Cipher)(encryptionKey, encryptionIv);
|
|
92
|
+
this._decryptor = (0, Aes_js_1.ctr256Cipher)(decryptionKey, decryptionIv);
|
|
93
|
+
nonce = platform_node_js_1.Buffer.concat([
|
|
94
|
+
nonce.subarray(0, 56),
|
|
95
|
+
this._encryptor(nonce).subarray(56, 64),
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
await super.send(nonce);
|
|
99
|
+
}
|
|
100
|
+
async send(data) {
|
|
101
|
+
const payload = this._encryptor(platform_node_js_1.Buffer.concat([
|
|
102
|
+
index_js_1.Primitive.Int.write(platform_node_js_1.Buffer.byteLength(data)),
|
|
103
|
+
data,
|
|
104
|
+
]));
|
|
105
|
+
return await super.send(payload);
|
|
106
|
+
}
|
|
107
|
+
async recv(_length = 0) {
|
|
108
|
+
let length = await super.recv(4);
|
|
109
|
+
if (!length)
|
|
110
|
+
return;
|
|
111
|
+
length = this._decryptor(length);
|
|
112
|
+
const data = await super.recv(length.readInt32LE(0));
|
|
113
|
+
if (!data)
|
|
114
|
+
return;
|
|
115
|
+
return this._decryptor(data);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.TCPIntermediateO = TCPIntermediateO;
|
|
119
|
+
function sha256(data) {
|
|
120
|
+
const hash = platform_node_js_1.crypto.createHash('sha256');
|
|
121
|
+
hash.update(data);
|
|
122
|
+
return hash.digest();
|
|
123
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Buffer } from '../../platform.node.js';
|
|
2
|
+
import { TCP } from './tcp.js';
|
|
3
|
+
import type { ProxyInterface } from '../connection.js';
|
|
4
|
+
export declare class TCPPaddedIntermediate extends TCP {
|
|
5
|
+
constructor();
|
|
6
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, dcId?: number): Promise<void>;
|
|
7
|
+
send(data: Buffer): Promise<void>;
|
|
8
|
+
recv(_length?: number): Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPPaddedIntermediate = void 0;
|
|
4
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
5
|
+
const tcp_js_1 = require("./tcp.js");
|
|
6
|
+
class TCPPaddedIntermediate extends tcp_js_1.TCP {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
async connect(ip, port, proxy, dcId) {
|
|
11
|
+
await super.connect(ip, port, proxy, dcId);
|
|
12
|
+
await super.send(platform_node_js_1.Buffer.concat([
|
|
13
|
+
platform_node_js_1.Buffer.from('dd', 'hex'),
|
|
14
|
+
platform_node_js_1.Buffer.from('dd', 'hex'),
|
|
15
|
+
platform_node_js_1.Buffer.from('dd', 'hex'),
|
|
16
|
+
platform_node_js_1.Buffer.from('dd', 'hex'),
|
|
17
|
+
]));
|
|
18
|
+
}
|
|
19
|
+
async send(data) {
|
|
20
|
+
data = platform_node_js_1.Buffer.concat([
|
|
21
|
+
data,
|
|
22
|
+
platform_node_js_1.Buffer.alloc(platform_node_js_1.Buffer.byteLength(data) % 4),
|
|
23
|
+
]);
|
|
24
|
+
const allocLength = platform_node_js_1.Buffer.alloc(4);
|
|
25
|
+
allocLength.writeInt32LE(platform_node_js_1.Buffer.byteLength(data), 0);
|
|
26
|
+
await super.send(platform_node_js_1.Buffer.concat([allocLength, data]));
|
|
27
|
+
}
|
|
28
|
+
async recv(_length = 0) {
|
|
29
|
+
const length = await super.recv(4);
|
|
30
|
+
if (!length)
|
|
31
|
+
return;
|
|
32
|
+
const data = await super.recv(length.readInt32LE(0));
|
|
33
|
+
if (!data)
|
|
34
|
+
return;
|
|
35
|
+
return data.subarray(0, platform_node_js_1.Buffer.byteLength(data) - (platform_node_js_1.Buffer.byteLength(data) % 4));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.TCPPaddedIntermediate = TCPPaddedIntermediate;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { TCP } from './tcp.js';
|
|
2
|
+
export { TCPAbridged } from './TCPAbridged.js';
|
|
3
|
+
export { TCPAbridgedO } from './TCPAbridgedO.js';
|
|
4
|
+
export { TCPFull } from './TCPFull.js';
|
|
5
|
+
export { TCPIntermediate } from './TCPIntermediate.js';
|
|
6
|
+
export { TCPIntermediateO } from './TCPIntermediateO.js';
|
|
7
|
+
export { TCPPaddedIntermediate } from './TCPPaddedIntermediate.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCPPaddedIntermediate = exports.TCPIntermediateO = exports.TCPIntermediate = exports.TCPFull = exports.TCPAbridgedO = exports.TCPAbridged = exports.TCP = void 0;
|
|
4
|
+
var tcp_js_1 = require("./tcp.js");
|
|
5
|
+
Object.defineProperty(exports, "TCP", { enumerable: true, get: function () { return tcp_js_1.TCP; } });
|
|
6
|
+
var TCPAbridged_js_1 = require("./TCPAbridged.js");
|
|
7
|
+
Object.defineProperty(exports, "TCPAbridged", { enumerable: true, get: function () { return TCPAbridged_js_1.TCPAbridged; } });
|
|
8
|
+
var TCPAbridgedO_js_1 = require("./TCPAbridgedO.js");
|
|
9
|
+
Object.defineProperty(exports, "TCPAbridgedO", { enumerable: true, get: function () { return TCPAbridgedO_js_1.TCPAbridgedO; } });
|
|
10
|
+
var TCPFull_js_1 = require("./TCPFull.js");
|
|
11
|
+
Object.defineProperty(exports, "TCPFull", { enumerable: true, get: function () { return TCPFull_js_1.TCPFull; } });
|
|
12
|
+
var TCPIntermediate_js_1 = require("./TCPIntermediate.js");
|
|
13
|
+
Object.defineProperty(exports, "TCPIntermediate", { enumerable: true, get: function () { return TCPIntermediate_js_1.TCPIntermediate; } });
|
|
14
|
+
var TCPIntermediateO_js_1 = require("./TCPIntermediateO.js");
|
|
15
|
+
Object.defineProperty(exports, "TCPIntermediateO", { enumerable: true, get: function () { return TCPIntermediateO_js_1.TCPIntermediateO; } });
|
|
16
|
+
var TCPPaddedIntermediate_js_1 = require("./TCPPaddedIntermediate.js");
|
|
17
|
+
Object.defineProperty(exports, "TCPPaddedIntermediate", { enumerable: true, get: function () { return TCPPaddedIntermediate_js_1.TCPPaddedIntermediate; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Buffer } from '../../platform.node.js';
|
|
2
|
+
import type { ProxyInterface } from '../connection.js';
|
|
3
|
+
export declare class TCP {
|
|
4
|
+
private _socks;
|
|
5
|
+
private _task;
|
|
6
|
+
private _mutex;
|
|
7
|
+
connected: boolean;
|
|
8
|
+
constructor();
|
|
9
|
+
connect(ip: string, port: number, proxy?: ProxyInterface, _dcId?: number): Promise<void>;
|
|
10
|
+
close(): Promise<boolean | undefined>;
|
|
11
|
+
send(data: Buffer): Promise<void>;
|
|
12
|
+
recv(length?: number): Promise<Buffer<ArrayBufferLike> | undefined>;
|
|
13
|
+
toJSON(): {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
toString(): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TCP = void 0;
|
|
4
|
+
const WebSocket_js_1 = require("../WebSocket.js");
|
|
5
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
6
|
+
const Timeout_js_1 = require("../../Timeout.js");
|
|
7
|
+
const helpers_js_1 = require("../../helpers.js");
|
|
8
|
+
class TCP {
|
|
9
|
+
_socks;
|
|
10
|
+
_task;
|
|
11
|
+
_mutex = new platform_node_js_1.Mutex();
|
|
12
|
+
connected;
|
|
13
|
+
constructor() {
|
|
14
|
+
this._task = new Timeout_js_1.Timeout();
|
|
15
|
+
this._socks = new WebSocket_js_1.Socket(10 * 1000);
|
|
16
|
+
}
|
|
17
|
+
async connect(ip, port, proxy, _dcId) {
|
|
18
|
+
const release = await this._mutex.acquire();
|
|
19
|
+
try {
|
|
20
|
+
await this._socks.connect(ip, port, proxy);
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
release();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async close() {
|
|
27
|
+
await this._task.clear();
|
|
28
|
+
await (0, helpers_js_1.sleep)(1);
|
|
29
|
+
if (!this._socks)
|
|
30
|
+
return;
|
|
31
|
+
return await this._socks.destroy();
|
|
32
|
+
}
|
|
33
|
+
async send(data) {
|
|
34
|
+
const release = await this._mutex.acquire();
|
|
35
|
+
try {
|
|
36
|
+
await this._socks.send(data);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
release();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async recv(length = 0) {
|
|
43
|
+
let data = platform_node_js_1.Buffer.alloc(0);
|
|
44
|
+
while (platform_node_js_1.Buffer.byteLength(data) < length) {
|
|
45
|
+
const chunk = await this._task.run(this._socks.read(length - platform_node_js_1.Buffer.byteLength(data)), this._socks.timeout, () => { });
|
|
46
|
+
if (chunk) {
|
|
47
|
+
data = platform_node_js_1.Buffer.concat([data, chunk]);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
56
|
+
const toPrint = {
|
|
57
|
+
_: this.constructor.name,
|
|
58
|
+
};
|
|
59
|
+
for (const key in this) {
|
|
60
|
+
if (this.hasOwnProperty(key)) {
|
|
61
|
+
const value = this[key];
|
|
62
|
+
if (!key.startsWith('_') && value !== undefined && value !== null) {
|
|
63
|
+
toPrint[key] = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return toPrint;
|
|
68
|
+
}
|
|
69
|
+
[Symbol.for('Deno.customInspect')]() {
|
|
70
|
+
return String((0, platform_node_js_1.inspect)(this[Symbol.for('nodejs.util.inspect.custom')](), { colors: true }));
|
|
71
|
+
}
|
|
72
|
+
toJSON() {
|
|
73
|
+
const toPrint = {
|
|
74
|
+
_: this.constructor.name,
|
|
75
|
+
};
|
|
76
|
+
for (const key in this) {
|
|
77
|
+
if (this.hasOwnProperty(key)) {
|
|
78
|
+
const value = this[key];
|
|
79
|
+
if (!key.startsWith('_') && value !== undefined && value !== null) {
|
|
80
|
+
if (typeof value === 'bigint') {
|
|
81
|
+
toPrint[key] = String(value);
|
|
82
|
+
}
|
|
83
|
+
else if (Array.isArray(value)) {
|
|
84
|
+
toPrint[key] = value.map((v) => (typeof v === 'bigint' ? String(v) : v));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
toPrint[key] = value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return toPrint;
|
|
93
|
+
}
|
|
94
|
+
toString() {
|
|
95
|
+
return `[constructor of ${this.constructor.name}] ${JSON.stringify(this, null, 2)}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.TCP = TCP;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Buffer } from '../platform.node.js';
|
|
2
|
+
import type { ProxyInterface } from './connection.js';
|
|
3
|
+
export declare class Socket {
|
|
4
|
+
private _client;
|
|
5
|
+
private _data;
|
|
6
|
+
private _read;
|
|
7
|
+
private _promisedReading;
|
|
8
|
+
timeout: number;
|
|
9
|
+
_connectionClosed: boolean;
|
|
10
|
+
constructor(timeout: number);
|
|
11
|
+
connect(ip: string, port: number, proxy?: ProxyInterface): Promise<unknown>;
|
|
12
|
+
destroy(): Promise<boolean>;
|
|
13
|
+
recv(): void;
|
|
14
|
+
send(data: Buffer): Promise<void>;
|
|
15
|
+
read(length: number): Promise<Buffer<ArrayBufferLike>>;
|
|
16
|
+
reading(length: number): Promise<Buffer<ArrayBuffer> | undefined>;
|
|
17
|
+
toJSON(): {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
toString(): string;
|
|
21
|
+
}
|