sroosh 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/CryptoFile-BROWSER.d.ts +2 -0
- package/CryptoFile-BROWSER.js +23 -0
- package/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +23 -0
- package/Helpers.d.ts +151 -0
- package/Helpers.js +480 -0
- package/Password.d.ts +15 -0
- package/Password.js +271 -0
- package/README.md +105 -0
- package/Utils.d.ts +228 -0
- package/Utils.js +1248 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +109 -0
- package/client/TelegramClient.d.ts +1042 -0
- package/client/TelegramClient.js +1244 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +93 -0
- package/client/auth.js +363 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +24 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +87 -0
- package/client/chats.d.ts +46 -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 +157 -0
- package/client/downloads.js +598 -0
- package/client/fs-BROWSER.d.ts +10 -0
- package/client/fs-BROWSER.js +13 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +13 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +50 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +259 -0
- package/client/messages.js +804 -0
- package/client/os-BROWSER.d.ts +5 -0
- package/client/os-BROWSER.js +10 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +23 -0
- package/client/path-BROWSER.d.ts +7 -0
- package/client/path-BROWSER.js +8 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +239 -0
- package/client/telegramBaseClient.js +369 -0
- package/client/updates.d.ts +31 -0
- package/client/updates.js +254 -0
- package/client/uploads.d.ts +137 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +491 -0
- package/crypto/AuthKey.d.ts +20 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +6 -0
- package/crypto/CTR.js +35 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +18 -0
- package/crypto/IGE.js +34 -0
- package/crypto/RSA.d.ts +15 -0
- package/crypto/RSA.js +150 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +27 -0
- package/crypto/crypto.js +117 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +48 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +72 -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 +29 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +74 -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 +100 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +7 -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 +58 -0
- package/extensions/Logger.js +127 -0
- package/extensions/MessagePacker.d.ts +22 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets-BROWSER.d.ts +8 -0
- package/extensions/PromisedNetSockets-BROWSER.js +12 -0
- package/extensions/PromisedNetSockets.d.ts +25 -0
- package/extensions/PromisedNetSockets.js +178 -0
- package/extensions/PromisedWebSockets.d.ts +19 -0
- package/extensions/PromisedWebSockets.js +134 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +213 -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-BROWSER.d.ts +8 -0
- package/extensions/net-BROWSER.js +11 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +13 -0
- package/extensions/socks-BROWSER.d.ts +3 -0
- package/extensions/socks-BROWSER.js +6 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +13 -0
- package/index.d.ts +14 -0
- package/index.js +48 -0
- package/inspect-BROWSER.d.ts +3 -0
- package/inspect-BROWSER.js +6 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +193 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +291 -0
- package/network/MTProtoSender.js +854 -0
- package/network/MTProtoState.d.ts +103 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +19 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +71 -0
- package/network/connection/Connection.js +157 -0
- package/network/connection/ConnectionWebSocket.d.ts +19 -0
- package/network/connection/ConnectionWebSocket.js +77 -0
- package/network/connection/CustomIntermediatePacketCodec.d.ts +8 -0
- package/network/connection/CustomIntermediatePacketCodec.js +25 -0
- package/network/connection/CustomPromisedWebSockets.d.ts +22 -0
- package/network/connection/CustomPromisedWebSockets.js +170 -0
- package/network/connection/ObfuscatedIO.d.ts +12 -0
- package/network/connection/ObfuscatedIO.js +64 -0
- package/network/connection/TCPAbridged.d.ts +20 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +17 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +50 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +79 -0
- package/network/connection/index.d.ts +5 -0
- package/network/connection/index.js +13 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +24 -0
- package/package.json +73 -0
- package/platform.d.ts +3 -0
- package/platform.js +6 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +107 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/CacheApiSession.d.ts +18 -0
- package/sessions/CacheApiSession.js +99 -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 +33 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +13 -0
- package/sessions/localStorage-BROWSER.d.ts +3 -0
- package/sessions/localStorage-BROWSER.js +9 -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 +19 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +2 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +1638 -0
- package/tl/core/GZIPPacked.d.ts +16 -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 +15 -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 +25 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +30 -0
- package/tl/custom/chatGetter.js +114 -0
- package/tl/custom/dialog.d.ts +31 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +22 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +22 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +16 -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 +33 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +21 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +428 -0
- package/tl/custom/message.js +702 -0
- package/tl/custom/messageButton.d.ts +55 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +29 -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 +12 -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 +77 -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,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
|
+
/// <reference types="node" />
|
|
2
|
+
import { ObfuscatedConnection } from "./Connection";
|
|
3
|
+
import { AbridgedPacketCodec } from "./TCPAbridged";
|
|
4
|
+
export declare class ObfuscatedIO {
|
|
5
|
+
header?: Buffer;
|
|
6
|
+
private connection;
|
|
7
|
+
private _encrypt?;
|
|
8
|
+
private _decrypt?;
|
|
9
|
+
private _packetClass;
|
|
10
|
+
constructor(connection: ConnectionTCPObfuscated);
|
|
11
|
+
initHeader(): Promise<void>;
|
|
12
|
+
read(n: number): Promise<Buffer>;
|
|
13
|
+
write(data: Buffer): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class ConnectionTCPObfuscated extends ObfuscatedConnection {
|
|
16
|
+
ObfuscatedIO: typeof ObfuscatedIO;
|
|
17
|
+
PacketCodecClass: typeof AbridgedPacketCodec;
|
|
18
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionTCPObfuscated = exports.ObfuscatedIO = 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
|
+
exports.ObfuscatedIO = ObfuscatedIO;
|
|
72
|
+
class ConnectionTCPObfuscated extends Connection_1.ObfuscatedConnection {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(...arguments);
|
|
75
|
+
this.ObfuscatedIO = ObfuscatedIO;
|
|
76
|
+
this.PacketCodecClass = TCPAbridged_1.AbridgedPacketCodec;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ConnectionTCPObfuscated = ConnectionTCPObfuscated;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Connection } from "./Connection";
|
|
2
|
+
export { ConnectionTCPFull } from "./TCPFull";
|
|
3
|
+
export { ConnectionTCPAbridged } from "./TCPAbridged";
|
|
4
|
+
export { ConnectionTCPObfuscated } from "./TCPObfuscated";
|
|
5
|
+
export { ConnectionWebSocket } from "./ConnectionWebSocket";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionWebSocket = 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; } });
|
|
12
|
+
var ConnectionWebSocket_1 = require("./ConnectionWebSocket");
|
|
13
|
+
Object.defineProperty(exports, "ConnectionWebSocket", { enumerable: true, get: function () { return ConnectionWebSocket_1.ConnectionWebSocket; } });
|
|
@@ -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, ConnectionWebSocket } from "./connection";
|
package/network/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionWebSocket = 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; } });
|
|
24
|
+
Object.defineProperty(exports, "ConnectionWebSocket", { enumerable: true, get: function () { return connection_1.ConnectionWebSocket; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sroosh",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "NodeJS/Browser MTProto API Sroosh client library,",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/gram-js/gramjs.git"
|
|
13
|
+
},
|
|
14
|
+
"browser": {
|
|
15
|
+
"fs": false
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/gram-js/gramjs/issues"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"telegram",
|
|
23
|
+
"mtproto",
|
|
24
|
+
"userbot",
|
|
25
|
+
"api"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://github.com/gram-js/gramjs#readme",
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"bufferutil": "^4.0.3",
|
|
30
|
+
"utf-8-validate": "^5.0.5"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/core": "^7.12.13",
|
|
34
|
+
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
35
|
+
"@babel/preset-env": "^7.12.16",
|
|
36
|
+
"@types/jest": "^29.5.1",
|
|
37
|
+
"@types/mime": "^2.0.3",
|
|
38
|
+
"@types/node": "^15.12.0",
|
|
39
|
+
"@types/node-localstorage": "^1.3.0",
|
|
40
|
+
"@types/pako": "^1.0.1",
|
|
41
|
+
"@types/websocket": "^1.0.4",
|
|
42
|
+
"babel-loader": "^8.2.2",
|
|
43
|
+
"jest": "^29.5.0",
|
|
44
|
+
"os-browserify": "^0.3.0",
|
|
45
|
+
"prettier": "2.3.1",
|
|
46
|
+
"process": "^0.11.10",
|
|
47
|
+
"ts-jest": "^29.1.0",
|
|
48
|
+
"ts-loader": "^8.0.16",
|
|
49
|
+
"ts-node": "^9.1.1",
|
|
50
|
+
"typedoc": "^0.22.18",
|
|
51
|
+
"typedoc-plugin-missing-exports": "^0.22.6",
|
|
52
|
+
"typescript": "^4.2.4",
|
|
53
|
+
"util": "^0.12.4",
|
|
54
|
+
"webpack": "^5.69.0",
|
|
55
|
+
"webpack-cli": "^4.9.2"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@cryptography/aes": "^0.1.1",
|
|
59
|
+
"async-mutex": "^0.3.0",
|
|
60
|
+
"big-integer": "^1.6.48",
|
|
61
|
+
"buffer": "^6.0.3",
|
|
62
|
+
"htmlparser2": "^6.1.0",
|
|
63
|
+
"mime": "^3.0.0",
|
|
64
|
+
"pako": "^2.0.3",
|
|
65
|
+
"path-browserify": "^1.0.1",
|
|
66
|
+
"real-cancellable-promise": "^1.1.1",
|
|
67
|
+
"store2": "^2.13.0",
|
|
68
|
+
"ts-custom-error": "^3.2.0",
|
|
69
|
+
"websocket": "^1.0.34",
|
|
70
|
+
"node-localstorage": "^2.2.1",
|
|
71
|
+
"socks": "^2.6.2"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/platform.d.ts
ADDED
package/platform.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNode = exports.isBrowser = exports.isDeno = void 0;
|
|
4
|
+
exports.isDeno = "Deno" in globalThis;
|
|
5
|
+
exports.isBrowser = !exports.isDeno && typeof window !== "undefined";
|
|
6
|
+
exports.isNode = !exports.isBrowser;
|
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,107 @@
|
|
|
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 e_1, _a;
|
|
86
|
+
const result = new _1.helpers.TotalList();
|
|
87
|
+
try {
|
|
88
|
+
for (var _b = __asyncValues(this), _c; _c = await _b.next(), !_c.done;) {
|
|
89
|
+
const message = _c.value;
|
|
90
|
+
result.push(message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
94
|
+
finally {
|
|
95
|
+
try {
|
|
96
|
+
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
|
|
97
|
+
}
|
|
98
|
+
finally { if (e_1) throw e_1.error; }
|
|
99
|
+
}
|
|
100
|
+
result.total = this.total;
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
async _loadNextChunk() {
|
|
104
|
+
throw new Error("Not Implemented");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.RequestIter = RequestIter;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AuthKey } from "../crypto/AuthKey";
|
|
2
|
+
import type { EntityLike } from "../define";
|
|
3
|
+
import { Api } from "../tl";
|
|
4
|
+
export declare abstract class Session {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a clone of this session file
|
|
7
|
+
* @param toInstance {Session|null}
|
|
8
|
+
* @returns {Session}
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Sets the information of the data center address and port that
|
|
12
|
+
* the library should connect to, as well as the data center ID,
|
|
13
|
+
* which is currently unused.
|
|
14
|
+
* @param dcId {number}
|
|
15
|
+
* @param serverAddress {string}
|
|
16
|
+
* @param port {number}
|
|
17
|
+
*/
|
|
18
|
+
abstract setDC(dcId: number, serverAddress: string, port: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the currently-used data center ID.
|
|
21
|
+
*/
|
|
22
|
+
abstract get dcId(): number;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the server address where the library should connect to.
|
|
25
|
+
*/
|
|
26
|
+
abstract get serverAddress(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the port to which the library should connect to.
|
|
29
|
+
*/
|
|
30
|
+
abstract get port(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Returns an ``AuthKey`` instance associated with the saved
|
|
33
|
+
* data center, or `undefined` if a new one should be generated.
|
|
34
|
+
*/
|
|
35
|
+
abstract get authKey(): AuthKey | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the ``AuthKey`` to be used for the saved data center.
|
|
38
|
+
* @param value
|
|
39
|
+
*/
|
|
40
|
+
abstract set authKey(value: AuthKey | undefined);
|
|
41
|
+
/**
|
|
42
|
+
* Called before using the session
|
|
43
|
+
*/
|
|
44
|
+
abstract load(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* sets auth key for a dc
|
|
47
|
+
*/
|
|
48
|
+
abstract setAuthKey(authKey?: AuthKey, dcId?: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* gets auth key for a dc
|
|
51
|
+
*/
|
|
52
|
+
abstract getAuthKey(dcId?: number): AuthKey | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
|
|
55
|
+
* The library uses this method whenever an ``InputPeer`` is needed
|
|
56
|
+
* to suit several purposes (e.g. user only provided its ID or wishes
|
|
57
|
+
* to use a cached username to avoid extra RPC).
|
|
58
|
+
*/
|
|
59
|
+
abstract getInputEntity(key: EntityLike): Api.TypeInputPeer;
|
|
60
|
+
/**
|
|
61
|
+
* Returns an ID of the takeout process initialized for this session,
|
|
62
|
+
* or `None` if there's no were any unfinished takeout requests.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Sets the ID of the unfinished takeout process for this session.
|
|
66
|
+
* @param value
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Returns the ``UpdateState`` associated with the given `entity_id`.
|
|
70
|
+
* If the `entity_id` is 0, it should return the ``UpdateState`` for
|
|
71
|
+
* no specific channel (the "general" state). If no state is known
|
|
72
|
+
* it should ``return None``.
|
|
73
|
+
* @param entityId
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Sets the given ``UpdateState`` for the specified `entity_id`, which
|
|
77
|
+
* should be 0 if the ``UpdateState`` is the "general" state (and not
|
|
78
|
+
* for any specific channel).
|
|
79
|
+
* @param entityId
|
|
80
|
+
* @param state
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Called on client disconnection. Should be used to
|
|
84
|
+
* free any used resources. Can be left empty if none.
|
|
85
|
+
*/
|
|
86
|
+
abstract close(): void;
|
|
87
|
+
/**
|
|
88
|
+
* called whenever important properties change. It should
|
|
89
|
+
* make persist the relevant session information to disk.
|
|
90
|
+
*/
|
|
91
|
+
abstract save(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Called upon client.log_out(). Should delete the stored
|
|
94
|
+
* information from disk since it's not valid anymore.
|
|
95
|
+
*/
|
|
96
|
+
abstract delete(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Processes the input ``TLObject`` or ``list`` and saves
|
|
99
|
+
* whatever information is relevant (e.g., ID or access hash).
|
|
100
|
+
* @param tlo
|
|
101
|
+
*/
|
|
102
|
+
abstract processEntities(tlo: any): void;
|
|
103
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export = CacheApi;
|
|
2
|
+
declare class CacheApi {
|
|
3
|
+
constructor(sessionId: any);
|
|
4
|
+
_storageKey: any;
|
|
5
|
+
_authKeys: {};
|
|
6
|
+
load(): Promise<void>;
|
|
7
|
+
setDC(dcId: any, serverAddress: any, port: any, skipUpdateStorage?: boolean): void;
|
|
8
|
+
_dcId: any;
|
|
9
|
+
_serverAddress: any;
|
|
10
|
+
_port: any;
|
|
11
|
+
save(): Promise<any>;
|
|
12
|
+
set authKey(arg: void);
|
|
13
|
+
get authKey(): void;
|
|
14
|
+
getAuthKey(dcId?: any): any;
|
|
15
|
+
setAuthKey(authKey: any, dcId?: any): void;
|
|
16
|
+
_updateStorage(): Promise<void>;
|
|
17
|
+
delete(): Promise<void>;
|
|
18
|
+
}
|