telegram-tghub-better-new 0.2.2 → 0.2.3
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 +1 -1
- package/CryptoFile.js +1 -1
- package/Helpers.d.ts +0 -1
- package/Helpers.js +13 -14
- package/Password.d.ts +0 -1
- package/Password.js +9 -10
- package/Utils.d.ts +3 -4
- package/Utils.js +8 -13
- package/Version.d.ts +1 -1
- package/Version.js +1 -1
- package/client/2fa.js +2 -3
- package/client/TelegramClient.d.ts +5 -1
- package/client/TelegramClient.js +0 -1
- package/client/auth.d.ts +0 -1
- package/client/chats.d.ts +4 -0
- package/client/downloads.d.ts +0 -1
- package/client/downloads.js +12 -13
- package/client/fs.d.ts +1 -10
- package/client/fs.js +15 -11
- package/client/os.d.ts +2 -5
- package/client/os.js +25 -8
- package/client/path.d.ts +2 -7
- package/client/path.js +5 -6
- package/client/telegramBaseClient.d.ts +1 -8
- package/client/telegramBaseClient.js +0 -2
- package/client/uploads.d.ts +0 -1
- package/client/uploads.js +7 -8
- package/client/users.js +0 -3
- package/crypto/AuthKey.d.ts +0 -1
- package/crypto/AuthKey.js +4 -5
- package/crypto/CTR.d.ts +0 -1
- package/crypto/CTR.js +2 -3
- package/crypto/IGE.d.ts +0 -1
- package/crypto/IGE.js +1 -2
- package/crypto/RSA.d.ts +0 -1
- package/crypto/RSA.js +1 -2
- package/crypto/crypto.d.ts +0 -1
- package/crypto/crypto.js +7 -8
- package/errors/Common.d.ts +0 -1
- package/errors/Common.js +3 -0
- package/events/CallbackQuery.d.ts +0 -1
- package/extensions/BinaryReader.d.ts +0 -1
- package/extensions/BinaryWriter.d.ts +0 -1
- package/extensions/BinaryWriter.js +1 -2
- package/extensions/MessagePacker.d.ts +0 -1
- package/extensions/MessagePacker.js +4 -5
- package/extensions/PromisedNetSockets.d.ts +22 -6
- package/extensions/PromisedNetSockets.js +176 -6
- package/extensions/PromisedWebSockets.d.ts +0 -1
- package/extensions/PromisedWebSockets.js +7 -8
- package/extensions/net.d.ts +1 -8
- package/extensions/net.js +15 -9
- package/extensions/socks.d.ts +3 -3
- package/extensions/socks.js +17 -3
- package/inspect.d.ts +1 -3
- package/inspect.js +2 -3
- package/network/Authenticator.js +7 -8
- package/network/MTProtoPlainSender.js +3 -4
- package/network/MTProtoSender.d.ts +0 -4
- package/network/MTProtoSender.js +1 -14
- package/network/MTProtoState.d.ts +0 -1
- package/network/MTProtoState.js +12 -13
- package/network/RequestState.d.ts +0 -1
- package/network/connection/Connection.d.ts +0 -1
- package/network/connection/TCPAbridged.d.ts +0 -1
- package/network/connection/TCPAbridged.js +8 -9
- package/network/connection/TCPFull.d.ts +0 -1
- package/network/connection/TCPFull.js +6 -7
- package/network/connection/TCPMTProxy.d.ts +0 -1
- package/network/connection/TCPMTProxy.js +23 -24
- package/network/connection/TCPObfuscated.d.ts +0 -1
- package/network/connection/TCPObfuscated.js +17 -18
- package/package.json +1 -1
- package/sessions/CacheApiSession.d.ts +18 -1
- package/sessions/CacheApiSession.js +1 -3
- package/sessions/StoreSession.js +1 -2
- package/sessions/StringSession.d.ts +0 -1
- package/sessions/StringSession.js +6 -7
- package/sessions/localStorage.d.ts +1 -3
- package/sessions/localStorage.js +1 -6
- package/tl/AllTLObjects.d.ts +1 -1
- package/tl/AllTLObjects.js +1 -1
- package/tl/MTProtoRequest.d.ts +0 -1
- package/tl/api.js +13 -15
- package/tl/apiTl.js +337 -86
- package/tl/core/GZIPPacked.d.ts +0 -1
- package/tl/core/GZIPPacked.js +4 -5
- package/tl/core/RPCResult.d.ts +0 -1
- package/tl/custom/button.d.ts +4 -1
- package/tl/custom/button.js +1 -2
- package/tl/custom/chatGetter.d.ts +4 -0
- package/tl/custom/dialog.d.ts +4 -0
- package/tl/custom/draft.d.ts +4 -0
- package/tl/custom/file.d.ts +4 -0
- package/tl/custom/forward.d.ts +4 -0
- package/tl/custom/inlineResult.d.ts +4 -0
- package/tl/custom/inlineResults.d.ts +4 -0
- package/tl/custom/message.d.ts +4 -1
- package/tl/custom/message.js +1 -3
- package/tl/custom/messageButton.d.ts +5 -1
- package/tl/custom/senderGetter.d.ts +4 -0
- package/tl/generationHelpers.d.ts +0 -1
- package/tl/generationHelpers.js +9 -10
- package/tl/schemaTl.js +1 -2
- package/tl/types-generator/template.d.ts +6 -1
- package/tl/types-generator/template.js +0 -2
package/CryptoFile.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as crypto from "
|
|
1
|
+
import * as crypto from "crypto";
|
|
2
2
|
export default crypto;
|
package/CryptoFile.js
CHANGED
|
@@ -23,5 +23,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const crypto = __importStar(require("
|
|
26
|
+
const crypto = __importStar(require("crypto"));
|
|
27
27
|
exports.default = crypto;
|
package/Helpers.d.ts
CHANGED
package/Helpers.js
CHANGED
|
@@ -28,7 +28,6 @@ exports.getRandomInt = getRandomInt;
|
|
|
28
28
|
exports.bufferXor = bufferXor;
|
|
29
29
|
exports.crc32 = crc32;
|
|
30
30
|
exports._entityType = _entityType;
|
|
31
|
-
const buffer_1 = require("buffer/");
|
|
32
31
|
const big_integer_1 = __importDefault(require("big-integer"));
|
|
33
32
|
const CryptoFile_1 = __importDefault(require("./CryptoFile"));
|
|
34
33
|
const platform_1 = require("./platform");
|
|
@@ -40,7 +39,7 @@ const platform_1 = require("./platform");
|
|
|
40
39
|
* @returns {bigInt.BigInteger}
|
|
41
40
|
*/
|
|
42
41
|
function readBigIntFromBuffer(buffer, little = true, signed = false) {
|
|
43
|
-
let randBuffer =
|
|
42
|
+
let randBuffer = Buffer.from(buffer);
|
|
44
43
|
const bytesNumber = randBuffer.length;
|
|
45
44
|
if (little) {
|
|
46
45
|
randBuffer = randBuffer.reverse();
|
|
@@ -124,7 +123,7 @@ function toSignedLittleBuffer(big, number = 8) {
|
|
|
124
123
|
byteArray[i] = bigNumber.shiftRight(8 * i).and(255);
|
|
125
124
|
}
|
|
126
125
|
// smh hacks
|
|
127
|
-
return
|
|
126
|
+
return Buffer.from(byteArray);
|
|
128
127
|
}
|
|
129
128
|
/**
|
|
130
129
|
* converts a big int to a buffer
|
|
@@ -150,7 +149,7 @@ function readBufferFromBigInt(bigIntVar, bytesNumber, little = true, signed = fa
|
|
|
150
149
|
.add(bigIntVar);
|
|
151
150
|
}
|
|
152
151
|
const hex = bigIntVar.toString(16).padStart(bytesNumber * 2, "0");
|
|
153
|
-
let buffer =
|
|
152
|
+
let buffer = Buffer.from(hex, "hex");
|
|
154
153
|
if (little) {
|
|
155
154
|
buffer = buffer.reverse();
|
|
156
155
|
}
|
|
@@ -187,7 +186,7 @@ function bigIntMod(n, m) {
|
|
|
187
186
|
* @returns {Buffer}
|
|
188
187
|
*/
|
|
189
188
|
function generateRandomBytes(count) {
|
|
190
|
-
return
|
|
189
|
+
return Buffer.from(CryptoFile_1.default.randomBytes(count));
|
|
191
190
|
}
|
|
192
191
|
/**
|
|
193
192
|
* Calculate the key based on Telegram guidelines, specifying whether it's the client or not
|
|
@@ -265,12 +264,12 @@ async function generateKeyDataFromNonce(serverNonceBigInt, newNonceBigInt) {
|
|
|
265
264
|
const serverNonce = toSignedLittleBuffer(serverNonceBigInt, 16);
|
|
266
265
|
const newNonce = toSignedLittleBuffer(newNonceBigInt, 32);
|
|
267
266
|
const [hash1, hash2, hash3] = await Promise.all([
|
|
268
|
-
sha1(
|
|
269
|
-
sha1(
|
|
270
|
-
sha1(
|
|
267
|
+
sha1(Buffer.concat([newNonce, serverNonce])),
|
|
268
|
+
sha1(Buffer.concat([serverNonce, newNonce])),
|
|
269
|
+
sha1(Buffer.concat([newNonce, newNonce])),
|
|
271
270
|
]);
|
|
272
|
-
const keyBuffer =
|
|
273
|
-
const ivBuffer =
|
|
271
|
+
const keyBuffer = Buffer.concat([hash1, hash2.slice(0, 12)]);
|
|
272
|
+
const ivBuffer = Buffer.concat([
|
|
274
273
|
hash2.slice(12, 20),
|
|
275
274
|
hash3,
|
|
276
275
|
newNonce.slice(0, 4),
|
|
@@ -281,7 +280,7 @@ async function generateKeyDataFromNonce(serverNonceBigInt, newNonceBigInt) {
|
|
|
281
280
|
};
|
|
282
281
|
}
|
|
283
282
|
function convertToLittle(buf) {
|
|
284
|
-
const correct =
|
|
283
|
+
const correct = Buffer.alloc(buf.length * 4);
|
|
285
284
|
for (let i = 0; i < buf.length; i++) {
|
|
286
285
|
correct.writeUInt32BE(buf[i], i * 4);
|
|
287
286
|
}
|
|
@@ -404,7 +403,7 @@ function bufferXor(a, b) {
|
|
|
404
403
|
for (let i = 0; i < a.length; i++) {
|
|
405
404
|
res.push(a[i] ^ b[i]);
|
|
406
405
|
}
|
|
407
|
-
return
|
|
406
|
+
return Buffer.from(res);
|
|
408
407
|
}
|
|
409
408
|
// Taken from https://stackoverflow.com/questions/18638900/javascript-crc32/18639999#18639999
|
|
410
409
|
function makeCRCTable() {
|
|
@@ -424,8 +423,8 @@ function crc32(buf) {
|
|
|
424
423
|
if (!crcTable) {
|
|
425
424
|
crcTable = makeCRCTable();
|
|
426
425
|
}
|
|
427
|
-
if (!
|
|
428
|
-
buf =
|
|
426
|
+
if (!Buffer.isBuffer(buf)) {
|
|
427
|
+
buf = Buffer.from(buf);
|
|
429
428
|
}
|
|
430
429
|
let crc = -1;
|
|
431
430
|
for (let index = 0; index < buf.length; index++) {
|
package/Password.d.ts
CHANGED
package/Password.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.computeCheck = computeCheck;
|
|
7
7
|
exports.computeDigest = computeDigest;
|
|
8
|
-
const buffer_1 = require("buffer/");
|
|
9
8
|
const tl_1 = require("./tl");
|
|
10
9
|
const Helpers_1 = require("./Helpers");
|
|
11
10
|
const big_integer_1 = __importDefault(require("big-integer"));
|
|
@@ -68,7 +67,7 @@ function checkPrimeAndGoodCheck(prime, g) {
|
|
|
68
67
|
* @param g{number}
|
|
69
68
|
*/
|
|
70
69
|
function checkPrimeAndGood(primeBytes, g) {
|
|
71
|
-
const goodPrime =
|
|
70
|
+
const goodPrime = Buffer.from([
|
|
72
71
|
0xc7, 0x1c, 0xae, 0xb9, 0xc6, 0xb1, 0xc9, 0x04, 0x8e, 0x6c, 0x52, 0x2f,
|
|
73
72
|
0x70, 0xf1, 0x3f, 0x73, 0x98, 0x0d, 0x40, 0x23, 0x8e, 0x3e, 0x21, 0xc1,
|
|
74
73
|
0x49, 0x34, 0xd0, 0x37, 0x56, 0x3d, 0x93, 0x0f, 0x48, 0x19, 0x8a, 0x0a,
|
|
@@ -115,7 +114,7 @@ function isGoodLarge(number, p) {
|
|
|
115
114
|
* @returns {Buffer}
|
|
116
115
|
*/
|
|
117
116
|
function numBytesForHash(number) {
|
|
118
|
-
return
|
|
117
|
+
return Buffer.concat([Buffer.alloc(SIZE_FOR_HASH - number.length), number]);
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
120
|
*
|
|
@@ -164,10 +163,10 @@ function pbkdf2sha512(password, salt, iterations) {
|
|
|
164
163
|
* @returns {Buffer|*}
|
|
165
164
|
*/
|
|
166
165
|
async function computeHash(algo, password) {
|
|
167
|
-
const hash1 = await (0, Helpers_1.sha256)(
|
|
168
|
-
const hash2 = await (0, Helpers_1.sha256)(
|
|
166
|
+
const hash1 = await (0, Helpers_1.sha256)(Buffer.concat([algo.salt1, Buffer.from(password, "utf-8"), algo.salt1]));
|
|
167
|
+
const hash2 = await (0, Helpers_1.sha256)(Buffer.concat([algo.salt2, hash1, algo.salt2]));
|
|
169
168
|
const hash3 = await pbkdf2sha512(hash2, algo.salt1, 100000);
|
|
170
|
-
return (0, Helpers_1.sha256)(
|
|
169
|
+
return (0, Helpers_1.sha256)(Buffer.concat([algo.salt2, hash3, algo.salt2]));
|
|
171
170
|
}
|
|
172
171
|
/**
|
|
173
172
|
*
|
|
@@ -218,7 +217,7 @@ async function computeCheck(request, password) {
|
|
|
218
217
|
const gForHash = bigNumForHash((0, big_integer_1.default)(g));
|
|
219
218
|
const bForHash = numBytesForHash(srp_B);
|
|
220
219
|
const gX = (0, Helpers_1.modExp)((0, big_integer_1.default)(g), x, p);
|
|
221
|
-
const k = (0, Helpers_1.readBigIntFromBuffer)(await (0, Helpers_1.sha256)(
|
|
220
|
+
const k = (0, Helpers_1.readBigIntFromBuffer)(await (0, Helpers_1.sha256)(Buffer.concat([pForHash, gForHash])), false);
|
|
222
221
|
const kgX = (0, Helpers_1.bigIntMod)(k.multiply(gX), p);
|
|
223
222
|
const generateAndCheckRandom = async () => {
|
|
224
223
|
const randomSize = 256;
|
|
@@ -229,7 +228,7 @@ async function computeCheck(request, password) {
|
|
|
229
228
|
const A = (0, Helpers_1.modExp)((0, big_integer_1.default)(g), a, p);
|
|
230
229
|
if (isGoodModExpFirst(A, p)) {
|
|
231
230
|
const aForHash = bigNumForHash(A);
|
|
232
|
-
const u = (0, Helpers_1.readBigIntFromBuffer)(await (0, Helpers_1.sha256)(
|
|
231
|
+
const u = (0, Helpers_1.readBigIntFromBuffer)(await (0, Helpers_1.sha256)(Buffer.concat([aForHash, bForHash])), false);
|
|
233
232
|
if (u.greater((0, big_integer_1.default)(0))) {
|
|
234
233
|
return {
|
|
235
234
|
a: a,
|
|
@@ -255,7 +254,7 @@ async function computeCheck(request, password) {
|
|
|
255
254
|
(0, Helpers_1.sha256)(algo.salt1),
|
|
256
255
|
(0, Helpers_1.sha256)(algo.salt2),
|
|
257
256
|
]);
|
|
258
|
-
const M1 = await (0, Helpers_1.sha256)(
|
|
257
|
+
const M1 = await (0, Helpers_1.sha256)(Buffer.concat([
|
|
259
258
|
xor(pSha, gSha),
|
|
260
259
|
salt1Sha,
|
|
261
260
|
salt2Sha,
|
|
@@ -265,7 +264,7 @@ async function computeCheck(request, password) {
|
|
|
265
264
|
]));
|
|
266
265
|
return new tl_1.Api.InputCheckPasswordSRP({
|
|
267
266
|
srpId: srpId,
|
|
268
|
-
A:
|
|
267
|
+
A: Buffer.from(aForHash),
|
|
269
268
|
M1: M1,
|
|
270
269
|
});
|
|
271
270
|
}
|
package/Utils.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Entity, EntityLike, MessageIDLike } from "./define";
|
|
2
|
+
import { Api } from "./tl";
|
|
2
3
|
import bigInt from "big-integer";
|
|
4
|
+
import { EntityCache } from "./entityCache";
|
|
3
5
|
import type { ParseInterface } from "./client/messageParse";
|
|
4
6
|
import { CustomFile } from "./client/uploads";
|
|
5
|
-
import type { Entity, EntityLike, MessageIDLike } from "./define";
|
|
6
|
-
import { EntityCache } from "./entityCache";
|
|
7
|
-
import { Api } from "./tl";
|
|
8
7
|
export declare function getFileInfo(fileLocation: Api.Message | Api.MessageMediaDocument | Api.MessageMediaPhoto | Api.TypeInputFileLocation): {
|
|
9
8
|
dcId?: number;
|
|
10
9
|
location: Api.TypeInputFileLocation;
|
package/Utils.js
CHANGED
|
@@ -34,14 +34,11 @@ exports.resolveInviteLink = resolveInviteLink;
|
|
|
34
34
|
exports.parseUsername = parseUsername;
|
|
35
35
|
exports.rtrim = rtrim;
|
|
36
36
|
exports.getDisplayName = getDisplayName;
|
|
37
|
-
const
|
|
37
|
+
const tl_1 = require("./tl");
|
|
38
38
|
const big_integer_1 = __importDefault(require("big-integer"));
|
|
39
39
|
const mime_1 = __importDefault(require("mime"));
|
|
40
|
-
const html_1 = require("./extensions/html");
|
|
41
40
|
const markdown_1 = require("./extensions/markdown");
|
|
42
41
|
const markdownv2_1 = require("./extensions/markdownv2");
|
|
43
|
-
const Helpers_1 = require("./Helpers");
|
|
44
|
-
const tl_1 = require("./tl");
|
|
45
42
|
function getFileInfo(fileLocation) {
|
|
46
43
|
if (!fileLocation || !fileLocation.SUBCLASS_OF_ID) {
|
|
47
44
|
_raiseCastFail(fileLocation, "InputFileLocation");
|
|
@@ -98,10 +95,12 @@ function* chunks(arr, size = 100) {
|
|
|
98
95
|
yield arr.slice(i, i + size);
|
|
99
96
|
}
|
|
100
97
|
}
|
|
98
|
+
const html_1 = require("./extensions/html");
|
|
99
|
+
const Helpers_1 = require("./Helpers");
|
|
101
100
|
const USERNAME_RE = new RegExp("@|(?:https?:\\/\\/)?(?:www\\.)?" +
|
|
102
101
|
"(?:telegram\\.(?:me|dog)|t\\.me)\\/(@|joinchat\\/)?", "i");
|
|
103
|
-
const JPEG_HEADER =
|
|
104
|
-
const JPEG_FOOTER =
|
|
102
|
+
const JPEG_HEADER = Buffer.from("ffd8ffe000104a46494600010100000100010000ffdb004300281c1e231e19282321232d2b28303c64413c37373c7b585d4964918099968f808c8aa0b4e6c3a0aadaad8a8cc8ffcbdaeef5ffffff9bc1fffffffaffe6fdfff8ffdb0043012b2d2d3c353c76414176f8a58ca5f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8ffc00011080000000003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00", "hex");
|
|
103
|
+
const JPEG_FOOTER = Buffer.from("ffd9", "hex");
|
|
105
104
|
const TG_JOIN_RE = new RegExp("tg:\\/\\/(join)\\?invite=", "i");
|
|
106
105
|
const VALID_USERNAME_RE = new RegExp("^([a-z]((?!__)[\\w\\d]){3,30}[a-z\\d]|gif|vid|" +
|
|
107
106
|
"pic|bing|wiki|imdb|bold|vote|like|coub)$", "i");
|
|
@@ -447,10 +446,10 @@ function strippedPhotoToJpg(stripped) {
|
|
|
447
446
|
if (stripped.length < 3 || stripped[0] !== 1) {
|
|
448
447
|
return stripped;
|
|
449
448
|
}
|
|
450
|
-
const header =
|
|
449
|
+
const header = Buffer.from(JPEG_HEADER);
|
|
451
450
|
header[164] = stripped[1];
|
|
452
451
|
header[166] = stripped[2];
|
|
453
|
-
return
|
|
452
|
+
return Buffer.concat([header, stripped.slice(3), JPEG_FOOTER]);
|
|
454
453
|
}
|
|
455
454
|
/*CONTEST
|
|
456
455
|
function getInputLocation(location) {
|
|
@@ -676,11 +675,7 @@ function isVideo(file) {
|
|
|
676
675
|
*/
|
|
677
676
|
function getAttributes(file, { attributes = null, mimeType = undefined, forceDocument = false, voiceNote = false, videoNote = false, supportsStreaming = false, thumb = null, }) {
|
|
678
677
|
var _a, _b, _c, _d;
|
|
679
|
-
const name = typeof file == "string"
|
|
680
|
-
? file
|
|
681
|
-
: "name" in file
|
|
682
|
-
? file.name || "unnamed"
|
|
683
|
-
: "unnamed";
|
|
678
|
+
const name = typeof file == "string" ? file : file.name || "unnamed";
|
|
684
679
|
if (mimeType === undefined) {
|
|
685
680
|
mimeType = mime_1.default.getType(name) || "application/octet-stream";
|
|
686
681
|
}
|
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "0.2.2";
|
package/Version.js
CHANGED
package/client/2fa.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateTwoFaSettings = updateTwoFaSettings;
|
|
4
|
-
const buffer_1 = require("buffer/");
|
|
5
4
|
const Helpers_1 = require("../Helpers");
|
|
6
5
|
const Password_1 = require("../Password");
|
|
7
6
|
const tl_1 = require("../tl");
|
|
@@ -52,7 +51,7 @@ async function updateTwoFaSettings(client, { isCheckPassword, currentPassword, n
|
|
|
52
51
|
}
|
|
53
52
|
const pwd = await client.invoke(new tl_1.Api.account.GetPassword());
|
|
54
53
|
if (!(pwd.newAlgo instanceof tl_1.Api.PasswordKdfAlgoUnknown)) {
|
|
55
|
-
pwd.newAlgo.salt1 =
|
|
54
|
+
pwd.newAlgo.salt1 = Buffer.concat([
|
|
56
55
|
pwd.newAlgo.salt1,
|
|
57
56
|
(0, Helpers_1.generateRandomBytes)(32),
|
|
58
57
|
]);
|
|
@@ -77,7 +76,7 @@ async function updateTwoFaSettings(client, { isCheckPassword, currentPassword, n
|
|
|
77
76
|
newAlgo: pwd.newAlgo,
|
|
78
77
|
newPasswordHash: newPassword
|
|
79
78
|
? await (0, Password_1.computeDigest)(pwd.newAlgo, newPassword)
|
|
80
|
-
:
|
|
79
|
+
: Buffer.alloc(0),
|
|
81
80
|
hint,
|
|
82
81
|
email,
|
|
83
82
|
// not explained what it does and it seems to always be set to empty in tdesktop
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from "buffer/";
|
|
2
1
|
import { TelegramBaseClient, TelegramClientParams } from "./telegramBaseClient";
|
|
3
2
|
import * as authMethods from "./auth";
|
|
4
3
|
import * as downloadMethods from "./downloads";
|
|
@@ -19,6 +18,7 @@ import { Album, AlbumEvent } from "../events/Album";
|
|
|
19
18
|
import { CallbackQuery, CallbackQueryEvent } from "../events/CallbackQuery";
|
|
20
19
|
import { EditedMessage, EditedMessageEvent } from "../events/EditedMessage";
|
|
21
20
|
import { DeletedMessage, DeletedMessageEvent } from "../events/DeletedMessage";
|
|
21
|
+
import { inspect } from "../inspect";
|
|
22
22
|
/**
|
|
23
23
|
* The TelegramClient uses several methods in different files to provide all the common functionality in a nice interface.</br>
|
|
24
24
|
* **In short, to create a client you must do:**
|
|
@@ -1032,6 +1032,10 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
1032
1032
|
_removeSender(dcId: number): void;
|
|
1033
1033
|
/** @hidden */
|
|
1034
1034
|
_getResponseMessage(req: any, result: any, inputChat: any): Api.TypeMessage | Map<number, Api.Message> | (Api.Message | undefined)[] | undefined;
|
|
1035
|
+
/** @hidden */
|
|
1036
|
+
[inspect.custom](): {
|
|
1037
|
+
[key: string]: any;
|
|
1038
|
+
};
|
|
1035
1039
|
/**
|
|
1036
1040
|
* Small hack for using it in browsers
|
|
1037
1041
|
*/
|
package/client/TelegramClient.js
CHANGED
|
@@ -1073,7 +1073,6 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
1073
1073
|
securityChecks: this._securityChecks,
|
|
1074
1074
|
autoReconnectCallback: this._handleReconnect.bind(this),
|
|
1075
1075
|
_exportedSenderPromises: this._exportedSenderPromises,
|
|
1076
|
-
reconnectRetries: this._reconnectRetries,
|
|
1077
1076
|
});
|
|
1078
1077
|
}
|
|
1079
1078
|
const connection = new this._connection({
|
package/client/auth.d.ts
CHANGED
package/client/chats.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { EntityLike } from "../define";
|
|
|
3
3
|
import { TotalList } from "../Helpers";
|
|
4
4
|
import { RequestIter } from "../requestIter";
|
|
5
5
|
import { Api } from "../tl";
|
|
6
|
+
import { inspect } from "../inspect";
|
|
6
7
|
interface ParticipantsIterInterface {
|
|
7
8
|
entity: EntityLike;
|
|
8
9
|
filter: any;
|
|
@@ -13,6 +14,9 @@ interface ParticipantsIterInterface {
|
|
|
13
14
|
export declare class _ParticipantsIter extends RequestIter {
|
|
14
15
|
private filterEntity;
|
|
15
16
|
private requests?;
|
|
17
|
+
[inspect.custom](): {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
16
20
|
_init({ entity, filter, offset, search, showTotal, }: ParticipantsIterInterface): Promise<boolean | void>;
|
|
17
21
|
_loadNextChunk(): Promise<boolean | undefined>;
|
|
18
22
|
[Symbol.asyncIterator](): AsyncIterator<Api.User, any, undefined>;
|
package/client/downloads.d.ts
CHANGED
package/client/downloads.js
CHANGED
|
@@ -43,7 +43,6 @@ exports._downloadWebDocument = _downloadWebDocument;
|
|
|
43
43
|
exports._downloadCachedPhotoSize = _downloadCachedPhotoSize;
|
|
44
44
|
exports._downloadPhoto = _downloadPhoto;
|
|
45
45
|
exports.downloadProfilePhoto = downloadProfilePhoto;
|
|
46
|
-
const buffer_1 = require("buffer/");
|
|
47
46
|
const tl_1 = require("../tl");
|
|
48
47
|
const Utils_1 = require("../Utils");
|
|
49
48
|
const Helpers_1 = require("../Helpers");
|
|
@@ -143,7 +142,7 @@ exports.DirectDownloadIter = DirectDownloadIter;
|
|
|
143
142
|
class GenericDownloadIter extends DirectDownloadIter {
|
|
144
143
|
async _loadNextChunk() {
|
|
145
144
|
// 1. Fetch enough for one chunk
|
|
146
|
-
let data =
|
|
145
|
+
let data = Buffer.alloc(0);
|
|
147
146
|
// 1.1. ``bad`` is how much into the data we have we need to offset
|
|
148
147
|
const bad = this.request.offset.mod(this.request.limit).toJSNumber();
|
|
149
148
|
const before = this.request.offset;
|
|
@@ -153,7 +152,7 @@ class GenericDownloadIter extends DirectDownloadIter {
|
|
|
153
152
|
while (!done && data.length - bad < this._chunkSize) {
|
|
154
153
|
const current = await this._request();
|
|
155
154
|
this.request.offset = this.request.offset.add(this.request.limit);
|
|
156
|
-
data =
|
|
155
|
+
data = Buffer.concat([data, current]);
|
|
157
156
|
done = current.length < this.request.limit;
|
|
158
157
|
}
|
|
159
158
|
// 1.3 Restore our last desired offset
|
|
@@ -238,8 +237,8 @@ function iterDownload(client, { file, offset = big_integer_1.default.zero, strid
|
|
|
238
237
|
});
|
|
239
238
|
}
|
|
240
239
|
function getWriter(outputFile) {
|
|
241
|
-
if (!outputFile ||
|
|
242
|
-
return new extensions_1.BinaryWriter(
|
|
240
|
+
if (!outputFile || Buffer.isBuffer(outputFile)) {
|
|
241
|
+
return new extensions_1.BinaryWriter(Buffer.alloc(0));
|
|
243
242
|
}
|
|
244
243
|
else if (typeof outputFile == "string") {
|
|
245
244
|
// We want to make sure that the path exists.
|
|
@@ -263,7 +262,7 @@ function returnWriterValue(writer) {
|
|
|
263
262
|
return path_1.default.resolve(writer.path);
|
|
264
263
|
}
|
|
265
264
|
else {
|
|
266
|
-
return
|
|
265
|
+
return Buffer.from(writer.path);
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
268
|
}
|
|
@@ -389,19 +388,19 @@ async function downloadMedia(client, messageOrMedia, outputFile, thumb, progress
|
|
|
389
388
|
return _downloadWebDocument(client, media, {});
|
|
390
389
|
}
|
|
391
390
|
else {
|
|
392
|
-
return
|
|
391
|
+
return Buffer.alloc(0);
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
/** @hidden */
|
|
396
395
|
async function _downloadDocument(client, doc, outputFile, date, thumb, progressCallback, msgData) {
|
|
397
396
|
if (doc instanceof tl_1.Api.MessageMediaDocument) {
|
|
398
397
|
if (!doc.document) {
|
|
399
|
-
return
|
|
398
|
+
return Buffer.alloc(0);
|
|
400
399
|
}
|
|
401
400
|
doc = doc.document;
|
|
402
401
|
}
|
|
403
402
|
if (!(doc instanceof tl_1.Api.Document)) {
|
|
404
|
-
return
|
|
403
|
+
return Buffer.alloc(0);
|
|
405
404
|
}
|
|
406
405
|
let size;
|
|
407
406
|
if (thumb == undefined) {
|
|
@@ -530,17 +529,17 @@ function getProperFilename(file, fileType, extension, date) {
|
|
|
530
529
|
async function _downloadPhoto(client, photo, file, date, thumb, progressCallback) {
|
|
531
530
|
if (photo instanceof tl_1.Api.MessageMediaPhoto) {
|
|
532
531
|
if (photo.photo instanceof tl_1.Api.PhotoEmpty || !photo.photo) {
|
|
533
|
-
return
|
|
532
|
+
return Buffer.alloc(0);
|
|
534
533
|
}
|
|
535
534
|
photo = photo.photo;
|
|
536
535
|
}
|
|
537
536
|
if (!(photo instanceof tl_1.Api.Photo)) {
|
|
538
|
-
return
|
|
537
|
+
return Buffer.alloc(0);
|
|
539
538
|
}
|
|
540
539
|
const photoSizes = [...(photo.sizes || []), ...(photo.videoSizes || [])];
|
|
541
540
|
const size = getThumb(photoSizes, thumb);
|
|
542
541
|
if (!size || size instanceof tl_1.Api.PhotoSizeEmpty) {
|
|
543
|
-
return
|
|
542
|
+
return Buffer.alloc(0);
|
|
544
543
|
}
|
|
545
544
|
if (!date) {
|
|
546
545
|
date = Date.now();
|
|
@@ -596,7 +595,7 @@ async function downloadProfilePhoto(client, entity, fileParams) {
|
|
|
596
595
|
});
|
|
597
596
|
}
|
|
598
597
|
else {
|
|
599
|
-
return
|
|
598
|
+
return Buffer.alloc(0);
|
|
600
599
|
}
|
|
601
600
|
return client.downloadFile(loc, {
|
|
602
601
|
outputFile: fileParams.outputFile,
|
package/client/fs.d.ts
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
lstat: (...args: any) => any;
|
|
3
|
-
stat: (...args: any) => any;
|
|
4
|
-
readFile: (...args: any) => any;
|
|
5
|
-
open: (...args: any) => any;
|
|
6
|
-
};
|
|
7
|
-
export declare const createWriteStream: any;
|
|
8
|
-
export declare const WriteStream: any;
|
|
9
|
-
export declare const lstatSync: any;
|
|
10
|
-
export declare const existsSync: any;
|
|
1
|
+
export * from "fs";
|
package/client/fs.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
9
15
|
};
|
|
10
|
-
exports
|
|
11
|
-
exports
|
|
12
|
-
exports.lstatSync = {};
|
|
13
|
-
exports.existsSync = {};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("fs"), exports);
|
package/client/os.d.ts
CHANGED
package/client/os.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
10
24
|
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const os = __importStar(require("os"));
|
|
27
|
+
exports.default = os;
|
package/client/path.d.ts
CHANGED
package/client/path.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
basename(...args) { },
|
|
5
|
-
resolve(...args) { },
|
|
6
|
-
path(...args) { },
|
|
7
|
-
join(...args) { },
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
exports.default = path_1.default;
|
|
@@ -37,16 +37,11 @@ export interface TelegramClientParams {
|
|
|
37
37
|
*/
|
|
38
38
|
requestRetries?: number;
|
|
39
39
|
/**
|
|
40
|
-
* How many times the
|
|
40
|
+
* How many times the reconnection should retry, either on the initial connection or when Telegram disconnects us.<br/>
|
|
41
41
|
* May be set to a negative or undefined value for infinite retries, but this is not recommended, since the program can get stuck in an infinite loop.<br/>
|
|
42
42
|
* defaults to 5
|
|
43
43
|
*/
|
|
44
44
|
connectionRetries?: number;
|
|
45
|
-
/**
|
|
46
|
-
* How many times to reconnect before giving up. This happens after the initial connection is finished<br/>
|
|
47
|
-
* defaults to infinity
|
|
48
|
-
*/
|
|
49
|
-
reconnectRetries?: number;
|
|
50
45
|
/**
|
|
51
46
|
* Experimental proxy to be used for the connection. (only supports MTProxies)
|
|
52
47
|
*/
|
|
@@ -131,8 +126,6 @@ export declare abstract class TelegramBaseClient {
|
|
|
131
126
|
/** @hidden */
|
|
132
127
|
_connectionRetries: number;
|
|
133
128
|
/** @hidden */
|
|
134
|
-
_reconnectRetries: number;
|
|
135
|
-
/** @hidden */
|
|
136
129
|
_retryDelay: number;
|
|
137
130
|
/** @hidden */
|
|
138
131
|
_timeout: number;
|
|
@@ -81,7 +81,6 @@ class TelegramBaseClient {
|
|
|
81
81
|
this._requestRetries = clientParams.requestRetries;
|
|
82
82
|
this._downloadRetries = clientParams.downloadRetries;
|
|
83
83
|
this._connectionRetries = clientParams.connectionRetries;
|
|
84
|
-
this._reconnectRetries = clientParams.reconnectRetries;
|
|
85
84
|
this._retryDelay = clientParams.retryDelay || 0;
|
|
86
85
|
this._timeout = clientParams.timeout;
|
|
87
86
|
this._autoReconnect = clientParams.autoReconnect;
|
|
@@ -318,7 +317,6 @@ class TelegramBaseClient {
|
|
|
318
317
|
client: this,
|
|
319
318
|
securityChecks: this._securityChecks,
|
|
320
319
|
_exportedSenderPromises: this._exportedSenderPromises,
|
|
321
|
-
reconnectRetries: this._reconnectRetries,
|
|
322
320
|
});
|
|
323
321
|
}
|
|
324
322
|
/** @hidden */
|
package/client/uploads.d.ts
CHANGED