teleproto 1.214.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/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConnectionTCPAbridged = exports.AbridgedPacketCodec = void 0;
|
|
7
|
+
const Helpers_1 = require("../../Helpers");
|
|
8
|
+
const Connection_1 = require("./Connection");
|
|
9
|
+
const big_integer_1 = __importDefault(require("big-integer"));
|
|
10
|
+
class AbridgedPacketCodec extends Connection_1.PacketCodec {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.tag = AbridgedPacketCodec.tag;
|
|
14
|
+
this.obfuscateTag = AbridgedPacketCodec.obfuscateTag;
|
|
15
|
+
}
|
|
16
|
+
encodePacket(data) {
|
|
17
|
+
let length = data.length >> 2;
|
|
18
|
+
let temp;
|
|
19
|
+
if (length < 127) {
|
|
20
|
+
const b = Buffer.alloc(1);
|
|
21
|
+
b.writeUInt8(length, 0);
|
|
22
|
+
temp = b;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
temp = Buffer.concat([
|
|
26
|
+
Buffer.from("7f", "hex"),
|
|
27
|
+
(0, Helpers_1.readBufferFromBigInt)((0, big_integer_1.default)(length), 3),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
return Buffer.concat([temp, data]);
|
|
31
|
+
}
|
|
32
|
+
async readPacket(reader) {
|
|
33
|
+
const readData = await reader.read(1);
|
|
34
|
+
let length = readData[0];
|
|
35
|
+
if (length >= 127) {
|
|
36
|
+
length = Buffer.concat([
|
|
37
|
+
await reader.read(3),
|
|
38
|
+
Buffer.alloc(1),
|
|
39
|
+
]).readInt32LE(0);
|
|
40
|
+
}
|
|
41
|
+
return reader.read(length << 2);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.AbridgedPacketCodec = AbridgedPacketCodec;
|
|
45
|
+
AbridgedPacketCodec.tag = Buffer.from("ef", "hex");
|
|
46
|
+
AbridgedPacketCodec.obfuscateTag = Buffer.from("efefefef", "hex");
|
|
47
|
+
/**
|
|
48
|
+
* This is the mode with the lowest overhead, as it will
|
|
49
|
+
* only require 1 byte if the packet length is less than
|
|
50
|
+
* 508 bytes (127 << 2, which is very common).
|
|
51
|
+
*/
|
|
52
|
+
class ConnectionTCPAbridged extends Connection_1.Connection {
|
|
53
|
+
constructor() {
|
|
54
|
+
super(...arguments);
|
|
55
|
+
this.PacketCodecClass = AbridgedPacketCodec;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ConnectionTCPAbridged = ConnectionTCPAbridged;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Connection, PacketCodec } from "./Connection";
|
|
2
|
+
import type { PromisedNetSockets, PromisedWebSockets } from "../../extensions";
|
|
3
|
+
export declare class FullPacketCodec extends PacketCodec {
|
|
4
|
+
private _sendCounter;
|
|
5
|
+
constructor(connection: any);
|
|
6
|
+
encodePacket(data: Buffer): Buffer<ArrayBuffer>;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param reader {PromisedWebSockets}
|
|
10
|
+
* @returns {Promise<*>}
|
|
11
|
+
*/
|
|
12
|
+
readPacket(reader: PromisedNetSockets | PromisedWebSockets): Promise<Buffer>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ConnectionTCPFull extends Connection {
|
|
15
|
+
PacketCodecClass: typeof FullPacketCodec;
|
|
16
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPFull = exports.FullPacketCodec = void 0;
|
|
4
|
+
const Connection_1 = require("./Connection");
|
|
5
|
+
const Helpers_1 = require("../../Helpers");
|
|
6
|
+
const errors_1 = require("../../errors");
|
|
7
|
+
class FullPacketCodec extends Connection_1.PacketCodec {
|
|
8
|
+
constructor(connection) {
|
|
9
|
+
super(connection);
|
|
10
|
+
this._sendCounter = 0; // Telegram will ignore us otherwise
|
|
11
|
+
}
|
|
12
|
+
encodePacket(data) {
|
|
13
|
+
// https://core.telegram.org/mtproto#tcp-transport
|
|
14
|
+
// total length, sequence number, packet and checksum (CRC32)
|
|
15
|
+
const length = data.length + 12;
|
|
16
|
+
const e = Buffer.alloc(8);
|
|
17
|
+
e.writeInt32LE(length, 0);
|
|
18
|
+
e.writeInt32LE(this._sendCounter, 4);
|
|
19
|
+
data = Buffer.concat([e, data]);
|
|
20
|
+
const crc = Buffer.alloc(4);
|
|
21
|
+
crc.writeUInt32LE((0, Helpers_1.crc32)(data), 0);
|
|
22
|
+
this._sendCounter += 1;
|
|
23
|
+
return Buffer.concat([data, crc]);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param reader {PromisedWebSockets}
|
|
28
|
+
* @returns {Promise<*>}
|
|
29
|
+
*/
|
|
30
|
+
async readPacket(reader) {
|
|
31
|
+
const packetLenSeq = await reader.readExactly(8); // 4 and 4
|
|
32
|
+
if (packetLenSeq === undefined) {
|
|
33
|
+
// Return empty buffer in case of issue
|
|
34
|
+
return Buffer.alloc(0);
|
|
35
|
+
}
|
|
36
|
+
const packetLen = packetLenSeq.readInt32LE(0);
|
|
37
|
+
if (packetLen < 0) {
|
|
38
|
+
// # It has been observed that the length and seq can be -429,
|
|
39
|
+
// # followed by the body of 4 bytes also being -429.
|
|
40
|
+
// # See https://github.com/LonamiWebs/Telethon/issues/4042.
|
|
41
|
+
const body = await reader.readExactly(4);
|
|
42
|
+
throw new errors_1.InvalidBufferError(body);
|
|
43
|
+
}
|
|
44
|
+
let body = await reader.readExactly(packetLen - 8);
|
|
45
|
+
const checksum = body.slice(-4).readUInt32LE(0);
|
|
46
|
+
body = body.slice(0, -4);
|
|
47
|
+
const validChecksum = (0, Helpers_1.crc32)(Buffer.concat([packetLenSeq, body]));
|
|
48
|
+
if (!(validChecksum === checksum)) {
|
|
49
|
+
throw new errors_1.InvalidChecksumError(checksum, validChecksum);
|
|
50
|
+
}
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.FullPacketCodec = FullPacketCodec;
|
|
55
|
+
class ConnectionTCPFull extends Connection_1.Connection {
|
|
56
|
+
constructor() {
|
|
57
|
+
super(...arguments);
|
|
58
|
+
this.PacketCodecClass = FullPacketCodec;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ConnectionTCPFull = ConnectionTCPFull;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ObfuscatedConnection } from "./Connection";
|
|
2
|
+
import { AbridgedPacketCodec } from "./TCPAbridged";
|
|
3
|
+
import { Logger, PromisedNetSockets, PromisedWebSockets } from "../../extensions";
|
|
4
|
+
interface BasicProxyInterface {
|
|
5
|
+
ip: string;
|
|
6
|
+
port: number;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
username?: string;
|
|
9
|
+
password?: string;
|
|
10
|
+
}
|
|
11
|
+
export type MTProxyType = BasicProxyInterface & {
|
|
12
|
+
secret: string;
|
|
13
|
+
MTProxy: true;
|
|
14
|
+
};
|
|
15
|
+
export type SocksProxyType = BasicProxyInterface & {
|
|
16
|
+
socksType: 4 | 5;
|
|
17
|
+
};
|
|
18
|
+
export type ProxyInterface = MTProxyType | SocksProxyType;
|
|
19
|
+
declare class MTProxyIO {
|
|
20
|
+
header?: Buffer;
|
|
21
|
+
private connection;
|
|
22
|
+
private _encrypt?;
|
|
23
|
+
private _decrypt?;
|
|
24
|
+
private _packetClass;
|
|
25
|
+
private _secret;
|
|
26
|
+
private _dcId;
|
|
27
|
+
constructor(connection: TCPMTProxy);
|
|
28
|
+
initHeader(): Promise<void>;
|
|
29
|
+
read(n: number): Promise<Buffer<any>>;
|
|
30
|
+
write(data: Buffer): void;
|
|
31
|
+
}
|
|
32
|
+
interface TCPMTProxyInterfaceParams {
|
|
33
|
+
ip: string;
|
|
34
|
+
port: number;
|
|
35
|
+
dcId: number;
|
|
36
|
+
loggers: Logger;
|
|
37
|
+
proxy: ProxyInterface;
|
|
38
|
+
socket: typeof PromisedNetSockets | typeof PromisedWebSockets;
|
|
39
|
+
testServers: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare class TCPMTProxy extends ObfuscatedConnection {
|
|
42
|
+
ObfuscatedIO: typeof MTProxyIO;
|
|
43
|
+
_secret: Buffer;
|
|
44
|
+
constructor({ ip, port, dcId, loggers, proxy, socket, testServers, }: TCPMTProxyInterfaceParams);
|
|
45
|
+
}
|
|
46
|
+
export declare class ConnectionTCPMTProxyAbridged extends TCPMTProxy {
|
|
47
|
+
PacketCodecClass: typeof AbridgedPacketCodec;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPMTProxyAbridged = exports.TCPMTProxy = void 0;
|
|
4
|
+
const Connection_1 = require("./Connection");
|
|
5
|
+
const TCPAbridged_1 = require("./TCPAbridged");
|
|
6
|
+
const Helpers_1 = require("../../Helpers");
|
|
7
|
+
const CTR_1 = require("../../crypto/CTR");
|
|
8
|
+
class MTProxyIO {
|
|
9
|
+
constructor(connection) {
|
|
10
|
+
this.header = undefined;
|
|
11
|
+
this.connection = connection.socket;
|
|
12
|
+
this._packetClass =
|
|
13
|
+
connection.PacketCodecClass;
|
|
14
|
+
this._secret = connection._secret;
|
|
15
|
+
this._dcId = connection._dcId;
|
|
16
|
+
}
|
|
17
|
+
async initHeader() {
|
|
18
|
+
let secret = this._secret;
|
|
19
|
+
const isDD = secret.length == 17 && secret[0] == 0xdd;
|
|
20
|
+
secret = isDD ? secret.slice(1) : secret;
|
|
21
|
+
if (secret.length != 16) {
|
|
22
|
+
throw new Error("MTProxy secret must be a hex-string representing 16 bytes");
|
|
23
|
+
}
|
|
24
|
+
const keywords = [
|
|
25
|
+
Buffer.from("50567247", "hex"),
|
|
26
|
+
Buffer.from("474554", "hex"),
|
|
27
|
+
Buffer.from("504f5354", "hex"),
|
|
28
|
+
Buffer.from("eeeeeeee", "hex"),
|
|
29
|
+
];
|
|
30
|
+
let random;
|
|
31
|
+
// eslint-disable-next-line no-constant-condition
|
|
32
|
+
while (true) {
|
|
33
|
+
random = (0, Helpers_1.generateRandomBytes)(64);
|
|
34
|
+
if (random[0] !== 0xef &&
|
|
35
|
+
!random.slice(4, 8).equals(Buffer.alloc(4))) {
|
|
36
|
+
let ok = true;
|
|
37
|
+
for (const key of keywords) {
|
|
38
|
+
if (key.equals(random.slice(0, 4))) {
|
|
39
|
+
ok = false;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (ok) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
random = random.toJSON().data;
|
|
49
|
+
const randomReversed = Buffer.from(random.slice(8, 56)).reverse();
|
|
50
|
+
// Encryption has "continuous buffer" enabled
|
|
51
|
+
const encryptKey = await (0, Helpers_1.sha256)(Buffer.concat([Buffer.from(random.slice(8, 40)), secret]));
|
|
52
|
+
const encryptIv = Buffer.from(random.slice(40, 56));
|
|
53
|
+
const decryptKey = await (0, Helpers_1.sha256)(Buffer.concat([Buffer.from(randomReversed.slice(0, 32)), secret]));
|
|
54
|
+
const decryptIv = Buffer.from(randomReversed.slice(32, 48));
|
|
55
|
+
const encryptor = new CTR_1.CTR(encryptKey, encryptIv);
|
|
56
|
+
const decryptor = new CTR_1.CTR(decryptKey, decryptIv);
|
|
57
|
+
random = Buffer.concat([
|
|
58
|
+
Buffer.from(random.slice(0, 56)),
|
|
59
|
+
this._packetClass.obfuscateTag,
|
|
60
|
+
Buffer.from(random.slice(60)),
|
|
61
|
+
]);
|
|
62
|
+
const dcIdBytes = Buffer.alloc(2);
|
|
63
|
+
dcIdBytes.writeInt8(this._dcId, 0);
|
|
64
|
+
random = Buffer.concat([
|
|
65
|
+
Buffer.from(random.slice(0, 60)),
|
|
66
|
+
dcIdBytes,
|
|
67
|
+
Buffer.from(random.slice(62)),
|
|
68
|
+
]);
|
|
69
|
+
random = Buffer.concat([
|
|
70
|
+
Buffer.from(random.slice(0, 56)),
|
|
71
|
+
Buffer.from(encryptor.encrypt(random).slice(56, 64)),
|
|
72
|
+
Buffer.from(random.slice(64)),
|
|
73
|
+
]);
|
|
74
|
+
this.header = random;
|
|
75
|
+
this._encrypt = encryptor;
|
|
76
|
+
this._decrypt = decryptor;
|
|
77
|
+
}
|
|
78
|
+
async read(n) {
|
|
79
|
+
const data = await this.connection.readExactly(n);
|
|
80
|
+
return this._decrypt.encrypt(data);
|
|
81
|
+
}
|
|
82
|
+
write(data) {
|
|
83
|
+
this.connection.write(this._encrypt.encrypt(data));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class TCPMTProxy extends Connection_1.ObfuscatedConnection {
|
|
87
|
+
constructor({ ip, port, dcId, loggers, proxy, socket, testServers, }) {
|
|
88
|
+
super({
|
|
89
|
+
ip: proxy.ip,
|
|
90
|
+
port: proxy.port,
|
|
91
|
+
dcId: dcId,
|
|
92
|
+
loggers: loggers,
|
|
93
|
+
socket: socket,
|
|
94
|
+
proxy: proxy,
|
|
95
|
+
testServers: testServers,
|
|
96
|
+
});
|
|
97
|
+
this.ObfuscatedIO = MTProxyIO;
|
|
98
|
+
if (!("MTProxy" in proxy)) {
|
|
99
|
+
throw new Error("This connection only supports MPTProxies");
|
|
100
|
+
}
|
|
101
|
+
if (!proxy.secret) {
|
|
102
|
+
throw new Error("You need to provide the secret for the MTProxy");
|
|
103
|
+
}
|
|
104
|
+
if (proxy.secret && proxy.secret.match(/^[0-9a-f]+$/i)) {
|
|
105
|
+
// probably hex
|
|
106
|
+
this._secret = Buffer.from(proxy.secret, "hex");
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// probably b64
|
|
110
|
+
this._secret = Buffer.from(proxy.secret, "base64");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.TCPMTProxy = TCPMTProxy;
|
|
115
|
+
class ConnectionTCPMTProxyAbridged extends TCPMTProxy {
|
|
116
|
+
constructor() {
|
|
117
|
+
super(...arguments);
|
|
118
|
+
this.PacketCodecClass = TCPAbridged_1.AbridgedPacketCodec;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ConnectionTCPMTProxyAbridged = ConnectionTCPMTProxyAbridged;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ObfuscatedConnection } from "./Connection";
|
|
2
|
+
import { AbridgedPacketCodec } from "./TCPAbridged";
|
|
3
|
+
declare class ObfuscatedIO {
|
|
4
|
+
header?: Buffer;
|
|
5
|
+
private connection;
|
|
6
|
+
private _encrypt?;
|
|
7
|
+
private _decrypt?;
|
|
8
|
+
private _packetClass;
|
|
9
|
+
constructor(connection: ConnectionTCPObfuscated);
|
|
10
|
+
initHeader(): Promise<void>;
|
|
11
|
+
read(n: number): Promise<Buffer<any>>;
|
|
12
|
+
write(data: Buffer): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class ConnectionTCPObfuscated extends ObfuscatedConnection {
|
|
15
|
+
ObfuscatedIO: typeof ObfuscatedIO;
|
|
16
|
+
PacketCodecClass: typeof AbridgedPacketCodec;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPObfuscated = void 0;
|
|
4
|
+
const Helpers_1 = require("../../Helpers");
|
|
5
|
+
const Connection_1 = require("./Connection");
|
|
6
|
+
const TCPAbridged_1 = require("./TCPAbridged");
|
|
7
|
+
const CTR_1 = require("../../crypto/CTR");
|
|
8
|
+
class ObfuscatedIO {
|
|
9
|
+
constructor(connection) {
|
|
10
|
+
this.header = undefined;
|
|
11
|
+
this.connection = connection.socket;
|
|
12
|
+
this._packetClass = connection.PacketCodecClass;
|
|
13
|
+
}
|
|
14
|
+
async initHeader() {
|
|
15
|
+
// Obfuscated messages secrets cannot start with any of these
|
|
16
|
+
const keywords = [
|
|
17
|
+
Buffer.from("50567247", "hex"),
|
|
18
|
+
Buffer.from("474554", "hex"),
|
|
19
|
+
Buffer.from("504f5354", "hex"),
|
|
20
|
+
Buffer.from("eeeeeeee", "hex"),
|
|
21
|
+
];
|
|
22
|
+
let random;
|
|
23
|
+
// eslint-disable-next-line no-constant-condition
|
|
24
|
+
while (true) {
|
|
25
|
+
random = (0, Helpers_1.generateRandomBytes)(64);
|
|
26
|
+
if (random[0] !== 0xef &&
|
|
27
|
+
!random.slice(4, 8).equals(Buffer.alloc(4))) {
|
|
28
|
+
let ok = true;
|
|
29
|
+
for (const key of keywords) {
|
|
30
|
+
if (key.equals(random.slice(0, 4))) {
|
|
31
|
+
ok = false;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (ok) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
random = random.toJSON().data;
|
|
41
|
+
const randomReversed = Buffer.from(random.slice(8, 56)).reverse();
|
|
42
|
+
// Encryption has "continuous buffer" enabled
|
|
43
|
+
const encryptKey = Buffer.from(random.slice(8, 40));
|
|
44
|
+
const encryptIv = Buffer.from(random.slice(40, 56));
|
|
45
|
+
const decryptKey = Buffer.from(randomReversed.slice(0, 32));
|
|
46
|
+
const decryptIv = Buffer.from(randomReversed.slice(32, 48));
|
|
47
|
+
const encryptor = new CTR_1.CTR(encryptKey, encryptIv);
|
|
48
|
+
const decryptor = new CTR_1.CTR(decryptKey, decryptIv);
|
|
49
|
+
random = Buffer.concat([
|
|
50
|
+
Buffer.from(random.slice(0, 56)),
|
|
51
|
+
this._packetClass.obfuscateTag,
|
|
52
|
+
Buffer.from(random.slice(60)),
|
|
53
|
+
]);
|
|
54
|
+
random = Buffer.concat([
|
|
55
|
+
Buffer.from(random.slice(0, 56)),
|
|
56
|
+
Buffer.from(encryptor.encrypt(random).slice(56, 64)),
|
|
57
|
+
Buffer.from(random.slice(64)),
|
|
58
|
+
]);
|
|
59
|
+
this.header = random;
|
|
60
|
+
this._encrypt = encryptor;
|
|
61
|
+
this._decrypt = decryptor;
|
|
62
|
+
}
|
|
63
|
+
async read(n) {
|
|
64
|
+
const data = await this.connection.readExactly(n);
|
|
65
|
+
return this._decrypt.encrypt(data);
|
|
66
|
+
}
|
|
67
|
+
write(data) {
|
|
68
|
+
this.connection.write(this._encrypt.encrypt(data));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class ConnectionTCPObfuscated extends Connection_1.ObfuscatedConnection {
|
|
72
|
+
constructor() {
|
|
73
|
+
super(...arguments);
|
|
74
|
+
this.ObfuscatedIO = ObfuscatedIO;
|
|
75
|
+
this.PacketCodecClass = TCPAbridged_1.AbridgedPacketCodec;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ConnectionTCPObfuscated = ConnectionTCPObfuscated;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPObfuscated = exports.ConnectionTCPAbridged = exports.ConnectionTCPFull = exports.Connection = void 0;
|
|
4
|
+
var Connection_1 = require("./Connection");
|
|
5
|
+
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return Connection_1.Connection; } });
|
|
6
|
+
var TCPFull_1 = require("./TCPFull");
|
|
7
|
+
Object.defineProperty(exports, "ConnectionTCPFull", { enumerable: true, get: function () { return TCPFull_1.ConnectionTCPFull; } });
|
|
8
|
+
var TCPAbridged_1 = require("./TCPAbridged");
|
|
9
|
+
Object.defineProperty(exports, "ConnectionTCPAbridged", { enumerable: true, get: function () { return TCPAbridged_1.ConnectionTCPAbridged; } });
|
|
10
|
+
var TCPObfuscated_1 = require("./TCPObfuscated");
|
|
11
|
+
Object.defineProperty(exports, "ConnectionTCPObfuscated", { enumerable: true, get: function () { return TCPObfuscated_1.ConnectionTCPObfuscated; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { MTProtoPlainSender } from "./MTProtoPlainSender";
|
|
2
|
+
export { doAuthentication } from "./Authenticator";
|
|
3
|
+
export { MTProtoSender } from "./MTProtoSender";
|
|
4
|
+
export declare class UpdateConnectionState {
|
|
5
|
+
static disconnected: number;
|
|
6
|
+
static connected: number;
|
|
7
|
+
static broken: number;
|
|
8
|
+
state: number;
|
|
9
|
+
constructor(state: number);
|
|
10
|
+
}
|
|
11
|
+
export { Connection, ConnectionTCPFull, ConnectionTCPAbridged, ConnectionTCPObfuscated, } from "./connection";
|
package/network/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPObfuscated = exports.ConnectionTCPAbridged = exports.ConnectionTCPFull = exports.Connection = exports.UpdateConnectionState = exports.MTProtoSender = exports.doAuthentication = exports.MTProtoPlainSender = void 0;
|
|
4
|
+
var MTProtoPlainSender_1 = require("./MTProtoPlainSender");
|
|
5
|
+
Object.defineProperty(exports, "MTProtoPlainSender", { enumerable: true, get: function () { return MTProtoPlainSender_1.MTProtoPlainSender; } });
|
|
6
|
+
var Authenticator_1 = require("./Authenticator");
|
|
7
|
+
Object.defineProperty(exports, "doAuthentication", { enumerable: true, get: function () { return Authenticator_1.doAuthentication; } });
|
|
8
|
+
var MTProtoSender_1 = require("./MTProtoSender");
|
|
9
|
+
Object.defineProperty(exports, "MTProtoSender", { enumerable: true, get: function () { return MTProtoSender_1.MTProtoSender; } });
|
|
10
|
+
class UpdateConnectionState {
|
|
11
|
+
constructor(state) {
|
|
12
|
+
this.state = state;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.UpdateConnectionState = UpdateConnectionState;
|
|
16
|
+
UpdateConnectionState.disconnected = -1;
|
|
17
|
+
UpdateConnectionState.connected = 1;
|
|
18
|
+
UpdateConnectionState.broken = 0;
|
|
19
|
+
var connection_1 = require("./connection");
|
|
20
|
+
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
|
|
21
|
+
Object.defineProperty(exports, "ConnectionTCPFull", { enumerable: true, get: function () { return connection_1.ConnectionTCPFull; } });
|
|
22
|
+
Object.defineProperty(exports, "ConnectionTCPAbridged", { enumerable: true, get: function () { return connection_1.ConnectionTCPAbridged; } });
|
|
23
|
+
Object.defineProperty(exports, "ConnectionTCPObfuscated", { enumerable: true, get: function () { return connection_1.ConnectionTCPObfuscated; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "teleproto",
|
|
3
|
+
"version": "1.214.0",
|
|
4
|
+
"description": "NodeJS MTProto API Telegram client library,",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/sanyok12345/teleproto.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"docs": "typedoc"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sanyok12345/teleproto/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"telegram",
|
|
20
|
+
"mtproto",
|
|
21
|
+
"teleproto",
|
|
22
|
+
"client",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"typescript",
|
|
25
|
+
"api"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://github.com/sanyok12345/teleproto#readme",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/mime": "^2.0.3",
|
|
30
|
+
"@types/node": "^22.15.18",
|
|
31
|
+
"@types/node-localstorage": "^1.3.0",
|
|
32
|
+
"@types/pako": "^1.0.1",
|
|
33
|
+
"@types/websocket": "^1.0.4",
|
|
34
|
+
"ts-node": "^9.1.1",
|
|
35
|
+
"typedoc": "^0.28.7",
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"util": "^0.12.4"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"async-mutex": "^0.3.0",
|
|
41
|
+
"big-integer": "^1.6.48",
|
|
42
|
+
"mime": "^3.0.0",
|
|
43
|
+
"node-localstorage": "^2.2.1",
|
|
44
|
+
"pako": "^2.0.3",
|
|
45
|
+
"socks": "^2.6.2",
|
|
46
|
+
"store2": "^2.13.0",
|
|
47
|
+
"ts-custom-error": "^3.2.0",
|
|
48
|
+
"websocket": "^1.0.34"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/requestIter.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TelegramClient } from "./client/TelegramClient";
|
|
2
|
+
import { helpers } from ".";
|
|
3
|
+
interface BaseRequestIterInterface {
|
|
4
|
+
reverse?: boolean;
|
|
5
|
+
waitTime?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class RequestIter implements AsyncIterable<any> {
|
|
8
|
+
client: TelegramClient;
|
|
9
|
+
reverse: boolean | undefined;
|
|
10
|
+
waitTime: number | undefined;
|
|
11
|
+
protected readonly limit: number;
|
|
12
|
+
protected left: number;
|
|
13
|
+
protected buffer: Array<any> | undefined;
|
|
14
|
+
private index;
|
|
15
|
+
protected total: number | undefined;
|
|
16
|
+
private lastLoad;
|
|
17
|
+
kwargs: {};
|
|
18
|
+
constructor(client: TelegramClient, limit?: number, params?: BaseRequestIterInterface, args?: {});
|
|
19
|
+
_init(kwargs: any): Promise<boolean | void>;
|
|
20
|
+
[Symbol.asyncIterator](): AsyncIterator<any, any, undefined>;
|
|
21
|
+
collect(): Promise<helpers.TotalList<unknown>>;
|
|
22
|
+
_loadNextChunk(): Promise<boolean | undefined>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
package/requestIter.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.RequestIter = void 0;
|
|
11
|
+
const Helpers_1 = require("./Helpers");
|
|
12
|
+
const _1 = require(".");
|
|
13
|
+
class RequestIter {
|
|
14
|
+
constructor(client, limit, params = {}, args = {}) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.reverse = params.reverse;
|
|
17
|
+
this.waitTime = params.waitTime;
|
|
18
|
+
this.limit = Math.max(!limit ? Number.MAX_SAFE_INTEGER : limit, 0);
|
|
19
|
+
this.left = this.limit;
|
|
20
|
+
this.buffer = undefined;
|
|
21
|
+
this.kwargs = args;
|
|
22
|
+
this.index = 0;
|
|
23
|
+
this.total = undefined;
|
|
24
|
+
this.lastLoad = 0;
|
|
25
|
+
}
|
|
26
|
+
async _init(kwargs) {
|
|
27
|
+
// for overload
|
|
28
|
+
}
|
|
29
|
+
[Symbol.asyncIterator]() {
|
|
30
|
+
this.buffer = undefined;
|
|
31
|
+
this.index = 0;
|
|
32
|
+
this.lastLoad = 0;
|
|
33
|
+
this.left = this.limit;
|
|
34
|
+
return {
|
|
35
|
+
next: async () => {
|
|
36
|
+
if (this.buffer == undefined) {
|
|
37
|
+
this.buffer = [];
|
|
38
|
+
if (await this._init(this.kwargs)) {
|
|
39
|
+
this.left = this.buffer.length;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (this.left <= 0) {
|
|
43
|
+
return {
|
|
44
|
+
value: undefined,
|
|
45
|
+
done: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (this.index == this.buffer.length) {
|
|
49
|
+
if (this.waitTime) {
|
|
50
|
+
await (0, Helpers_1.sleep)(this.waitTime -
|
|
51
|
+
(new Date().getTime() / 1000 - this.lastLoad));
|
|
52
|
+
}
|
|
53
|
+
this.lastLoad = new Date().getTime() / 1000;
|
|
54
|
+
this.index = 0;
|
|
55
|
+
this.buffer = [];
|
|
56
|
+
const nextChunk = await this._loadNextChunk();
|
|
57
|
+
if (nextChunk === false) {
|
|
58
|
+
// we exit;
|
|
59
|
+
return {
|
|
60
|
+
value: undefined,
|
|
61
|
+
done: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (nextChunk) {
|
|
65
|
+
this.left = this.buffer.length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!this.buffer || !this.buffer.length) {
|
|
69
|
+
return {
|
|
70
|
+
value: undefined,
|
|
71
|
+
done: true,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const result = this.buffer[this.index];
|
|
75
|
+
this.left -= 1;
|
|
76
|
+
this.index += 1;
|
|
77
|
+
return {
|
|
78
|
+
value: result,
|
|
79
|
+
done: false,
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async collect() {
|
|
85
|
+
var _a, e_1, _b, _c;
|
|
86
|
+
const result = new _1.helpers.TotalList();
|
|
87
|
+
try {
|
|
88
|
+
for (var _d = true, _e = __asyncValues(this), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
|
|
89
|
+
_c = _f.value;
|
|
90
|
+
_d = false;
|
|
91
|
+
const message = _c;
|
|
92
|
+
result.push(message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
96
|
+
finally {
|
|
97
|
+
try {
|
|
98
|
+
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
99
|
+
}
|
|
100
|
+
finally { if (e_1) throw e_1.error; }
|
|
101
|
+
}
|
|
102
|
+
result.total = this.total;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
async _loadNextChunk() {
|
|
106
|
+
throw new Error("Not Implemented");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.RequestIter = RequestIter;
|