telegram-tghub-better-new 0.3.4 → 0.4.2

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