teleproto 1.214.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/CryptoFile.d.ts +2 -0
  2. package/CryptoFile.js +37 -0
  3. package/Helpers.d.ts +150 -0
  4. package/Helpers.js +477 -0
  5. package/LICENSE +23 -0
  6. package/Password.d.ts +14 -0
  7. package/Password.js +270 -0
  8. package/README.md +98 -0
  9. package/Utils.d.ts +227 -0
  10. package/Utils.js +1247 -0
  11. package/Version.d.ts +1 -0
  12. package/Version.js +4 -0
  13. package/client/2fa.d.ts +48 -0
  14. package/client/2fa.js +108 -0
  15. package/client/TelegramClient.d.ts +1043 -0
  16. package/client/TelegramClient.js +1181 -0
  17. package/client/account.d.ts +0 -0
  18. package/client/account.js +1 -0
  19. package/client/auth.d.ts +92 -0
  20. package/client/auth.js +388 -0
  21. package/client/bots.d.ts +6 -0
  22. package/client/bots.js +23 -0
  23. package/client/buttons.d.ts +4 -0
  24. package/client/buttons.js +86 -0
  25. package/client/chats.d.ts +45 -0
  26. package/client/chats.js +350 -0
  27. package/client/dialogs.d.ts +52 -0
  28. package/client/dialogs.js +174 -0
  29. package/client/downloads.d.ts +156 -0
  30. package/client/downloads.js +614 -0
  31. package/client/fs.d.ts +1 -0
  32. package/client/fs.js +17 -0
  33. package/client/index.d.ts +15 -0
  34. package/client/index.js +64 -0
  35. package/client/messageParse.d.ts +17 -0
  36. package/client/messageParse.js +191 -0
  37. package/client/messages.d.ts +263 -0
  38. package/client/messages.js +813 -0
  39. package/client/os.d.ts +2 -0
  40. package/client/os.js +37 -0
  41. package/client/path.d.ts +2 -0
  42. package/client/path.js +7 -0
  43. package/client/telegramBaseClient.d.ts +237 -0
  44. package/client/telegramBaseClient.js +368 -0
  45. package/client/updates.d.ts +33 -0
  46. package/client/updates.js +260 -0
  47. package/client/uploads.d.ts +136 -0
  48. package/client/uploads.js +514 -0
  49. package/client/users.d.ts +29 -0
  50. package/client/users.js +490 -0
  51. package/crypto/AuthKey.d.ts +19 -0
  52. package/crypto/AuthKey.js +76 -0
  53. package/crypto/CTR.d.ts +5 -0
  54. package/crypto/CTR.js +16 -0
  55. package/crypto/Factorizator.d.ts +19 -0
  56. package/crypto/Factorizator.js +74 -0
  57. package/crypto/IGE.d.ts +11 -0
  58. package/crypto/IGE.js +115 -0
  59. package/crypto/RSA.d.ts +14 -0
  60. package/crypto/RSA.js +70 -0
  61. package/crypto/converters.d.ts +19 -0
  62. package/crypto/converters.js +52 -0
  63. package/crypto/crypto.d.ts +19 -0
  64. package/crypto/crypto.js +58 -0
  65. package/crypto/words.d.ts +6 -0
  66. package/crypto/words.js +47 -0
  67. package/define.d.ts +77 -0
  68. package/entityCache.d.ts +7 -0
  69. package/entityCache.js +79 -0
  70. package/errors/Common.d.ts +71 -0
  71. package/errors/Common.js +122 -0
  72. package/errors/RPCBaseErrors.d.ts +84 -0
  73. package/errors/RPCBaseErrors.js +134 -0
  74. package/errors/RPCErrorList.d.ts +37 -0
  75. package/errors/RPCErrorList.js +117 -0
  76. package/errors/index.d.ts +11 -0
  77. package/errors/index.js +32 -0
  78. package/events/Album.d.ts +36 -0
  79. package/events/Album.js +104 -0
  80. package/events/CallbackQuery.d.ts +73 -0
  81. package/events/CallbackQuery.js +193 -0
  82. package/events/DeletedMessage.d.ts +45 -0
  83. package/events/DeletedMessage.js +63 -0
  84. package/events/EditedMessage.d.ts +30 -0
  85. package/events/EditedMessage.js +41 -0
  86. package/events/NewMessage.d.ts +89 -0
  87. package/events/NewMessage.js +182 -0
  88. package/events/Raw.d.ts +29 -0
  89. package/events/Raw.js +43 -0
  90. package/events/common.d.ts +66 -0
  91. package/events/common.js +141 -0
  92. package/events/index.d.ts +2 -0
  93. package/events/index.js +8 -0
  94. package/extensions/AsyncQueue.d.ts +10 -0
  95. package/extensions/AsyncQueue.js +32 -0
  96. package/extensions/BinaryReader.d.ts +99 -0
  97. package/extensions/BinaryReader.js +242 -0
  98. package/extensions/BinaryWriter.d.ts +6 -0
  99. package/extensions/BinaryWriter.js +15 -0
  100. package/extensions/Deferred.d.ts +8 -0
  101. package/extensions/Deferred.js +16 -0
  102. package/extensions/Logger.d.ts +54 -0
  103. package/extensions/Logger.js +128 -0
  104. package/extensions/MessagePacker.d.ts +21 -0
  105. package/extensions/MessagePacker.js +154 -0
  106. package/extensions/PendingState.d.ts +12 -0
  107. package/extensions/PendingState.js +29 -0
  108. package/extensions/PromisedNetSockets.d.ts +24 -0
  109. package/extensions/PromisedNetSockets.js +192 -0
  110. package/extensions/PromisedWebSockets.d.ts +18 -0
  111. package/extensions/PromisedWebSockets.js +124 -0
  112. package/extensions/html.d.ts +5 -0
  113. package/extensions/html.js +228 -0
  114. package/extensions/index.d.ts +7 -0
  115. package/extensions/index.js +17 -0
  116. package/extensions/markdown.d.ts +5 -0
  117. package/extensions/markdown.js +76 -0
  118. package/extensions/markdownv2.d.ts +5 -0
  119. package/extensions/markdownv2.js +51 -0
  120. package/extensions/net.d.ts +1 -0
  121. package/extensions/net.js +17 -0
  122. package/extensions/socks.d.ts +1 -0
  123. package/extensions/socks.js +17 -0
  124. package/index.d.ts +14 -0
  125. package/index.js +62 -0
  126. package/inspect.d.ts +1 -0
  127. package/inspect.js +5 -0
  128. package/network/Authenticator.d.ts +12 -0
  129. package/network/Authenticator.js +192 -0
  130. package/network/MTProtoPlainSender.d.ts +19 -0
  131. package/network/MTProtoPlainSender.js +74 -0
  132. package/network/MTProtoSender.d.ts +290 -0
  133. package/network/MTProtoSender.js +873 -0
  134. package/network/MTProtoState.d.ts +102 -0
  135. package/network/MTProtoState.js +267 -0
  136. package/network/RequestState.d.ts +18 -0
  137. package/network/RequestState.js +35 -0
  138. package/network/connection/Connection.d.ts +69 -0
  139. package/network/connection/Connection.js +162 -0
  140. package/network/connection/TCPAbridged.d.ts +19 -0
  141. package/network/connection/TCPAbridged.js +58 -0
  142. package/network/connection/TCPFull.d.ts +16 -0
  143. package/network/connection/TCPFull.js +61 -0
  144. package/network/connection/TCPMTProxy.d.ts +49 -0
  145. package/network/connection/TCPMTProxy.js +121 -0
  146. package/network/connection/TCPObfuscated.d.ts +18 -0
  147. package/network/connection/TCPObfuscated.js +78 -0
  148. package/network/connection/index.d.ts +4 -0
  149. package/network/connection/index.js +11 -0
  150. package/network/index.d.ts +11 -0
  151. package/network/index.js +23 -0
  152. package/package.json +50 -0
  153. package/requestIter.d.ts +24 -0
  154. package/requestIter.js +109 -0
  155. package/sessions/Abstract.d.ts +103 -0
  156. package/sessions/Abstract.js +6 -0
  157. package/sessions/Memory.d.ts +38 -0
  158. package/sessions/Memory.js +272 -0
  159. package/sessions/StoreSession.d.ts +14 -0
  160. package/sessions/StoreSession.js +77 -0
  161. package/sessions/StringSession.d.ts +32 -0
  162. package/sessions/StringSession.js +116 -0
  163. package/sessions/index.d.ts +4 -0
  164. package/sessions/index.js +11 -0
  165. package/sessions/localStorage.d.ts +1 -0
  166. package/sessions/localStorage.js +4 -0
  167. package/tl/AllTLObjects.d.ts +3 -0
  168. package/tl/AllTLObjects.js +17 -0
  169. package/tl/MTProtoRequest.d.ts +18 -0
  170. package/tl/MTProtoRequest.js +38 -0
  171. package/tl/api.d.ts +32488 -0
  172. package/tl/api.js +507 -0
  173. package/tl/apiTl.d.ts +2 -0
  174. package/tl/apiTl.js +2209 -0
  175. package/tl/core/GZIPPacked.d.ts +15 -0
  176. package/tl/core/GZIPPacked.js +51 -0
  177. package/tl/core/MessageContainer.d.ts +12 -0
  178. package/tl/core/MessageContainer.js +42 -0
  179. package/tl/core/RPCResult.d.ts +14 -0
  180. package/tl/core/RPCResult.js +32 -0
  181. package/tl/core/TLMessage.d.ts +10 -0
  182. package/tl/core/TLMessage.js +14 -0
  183. package/tl/core/index.d.ts +6 -0
  184. package/tl/core/index.js +16 -0
  185. package/tl/custom/button.d.ts +24 -0
  186. package/tl/custom/button.js +78 -0
  187. package/tl/custom/chatGetter.d.ts +29 -0
  188. package/tl/custom/chatGetter.js +116 -0
  189. package/tl/custom/dialog.d.ts +30 -0
  190. package/tl/custom/dialog.js +40 -0
  191. package/tl/custom/draft.d.ts +21 -0
  192. package/tl/custom/draft.js +48 -0
  193. package/tl/custom/file.d.ts +21 -0
  194. package/tl/custom/file.js +68 -0
  195. package/tl/custom/forward.d.ts +15 -0
  196. package/tl/custom/forward.js +47 -0
  197. package/tl/custom/index.d.ts +1 -0
  198. package/tl/custom/index.js +5 -0
  199. package/tl/custom/inlineResult.d.ts +32 -0
  200. package/tl/custom/inlineResult.js +87 -0
  201. package/tl/custom/inlineResults.d.ts +20 -0
  202. package/tl/custom/inlineResults.js +26 -0
  203. package/tl/custom/message.d.ts +427 -0
  204. package/tl/custom/message.js +716 -0
  205. package/tl/custom/messageButton.d.ts +54 -0
  206. package/tl/custom/messageButton.js +152 -0
  207. package/tl/custom/senderGetter.d.ts +28 -0
  208. package/tl/custom/senderGetter.js +55 -0
  209. package/tl/generateModule.d.ts +1 -0
  210. package/tl/generateModule.js +17 -0
  211. package/tl/generationHelpers.d.ts +11 -0
  212. package/tl/generationHelpers.js +289 -0
  213. package/tl/index.d.ts +3 -0
  214. package/tl/index.js +10 -0
  215. package/tl/patched/index.d.ts +2 -0
  216. package/tl/patched/index.js +76 -0
  217. package/tl/schemaTl.d.ts +2 -0
  218. package/tl/schemaTl.js +64 -0
  219. package/tl/types-generator/generate.d.ts +1 -0
  220. package/tl/types-generator/generate.js +84 -0
  221. package/tl/types-generator/template.d.ts +6 -0
  222. package/tl/types-generator/template.js +257 -0
@@ -0,0 +1,2 @@
1
+ import * as crypto from "crypto";
2
+ export default crypto;
package/CryptoFile.js ADDED
@@ -0,0 +1,37 @@
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const crypto = __importStar(require("crypto"));
37
+ exports.default = crypto;
package/Helpers.d.ts ADDED
@@ -0,0 +1,150 @@
1
+ import bigInt from "big-integer";
2
+ import type { EntityLike } from "./define";
3
+ import type { Api } from "./tl";
4
+ /**
5
+ * converts a buffer to big int
6
+ * @param buffer
7
+ * @param little
8
+ * @param signed
9
+ * @returns {bigInt.BigInteger}
10
+ */
11
+ export declare function readBigIntFromBuffer(buffer: Buffer, little?: boolean, signed?: boolean): bigInt.BigInteger;
12
+ export declare function generateRandomBigInt(): bigInt.BigInteger;
13
+ export declare function escapeRegex(string: string): string;
14
+ export declare function groupBy(list: any[], keyGetter: Function): Map<any, any>;
15
+ /**
16
+ * Outputs the object in a better way by hiding all the private methods/attributes.
17
+ * @param object - the class to use
18
+ */
19
+ export declare function betterConsoleLog(object: {
20
+ [key: string]: any;
21
+ }): {
22
+ [key: string]: any;
23
+ };
24
+ /**
25
+ * Helper to find if a given object is an array (or similar)
26
+ */
27
+ export declare const isArrayLike: <T>(x: any) => x is Array<T>;
28
+ /**
29
+ * Special case signed little ints
30
+ * @param big
31
+ * @param number
32
+ * @returns {Buffer}
33
+ */
34
+ export declare function toSignedLittleBuffer(big: bigInt.BigInteger | string | number, number?: number): Buffer;
35
+ /**
36
+ * converts a big int to a buffer
37
+ * @param bigIntVar {BigInteger}
38
+ * @param bytesNumber
39
+ * @param little
40
+ * @param signed
41
+ * @returns {Buffer}
42
+ */
43
+ export declare function readBufferFromBigInt(bigIntVar: bigInt.BigInteger, bytesNumber: number, little?: boolean, signed?: boolean): Buffer;
44
+ /**
45
+ * Generates a random long integer (8 bytes), which is optionally signed
46
+ * @returns {BigInteger}
47
+ */
48
+ export declare function generateRandomLong(signed?: boolean): bigInt.BigInteger;
49
+ /**
50
+ * .... really javascript
51
+ * @param n {number}
52
+ * @param m {number}
53
+ * @returns {number}
54
+ */
55
+ export declare function mod(n: number, m: number): number;
56
+ /**
57
+ * returns a positive bigInt
58
+ * @param n {bigInt.BigInteger}
59
+ * @param m {bigInt.BigInteger}
60
+ * @returns {bigInt.BigInteger}
61
+ */
62
+ export declare function bigIntMod(n: bigInt.BigInteger, m: bigInt.BigInteger): bigInt.BigInteger;
63
+ /**
64
+ * Generates a random bytes array
65
+ * @param count
66
+ * @returns {Buffer}
67
+ */
68
+ export declare function generateRandomBytes(count: number): Buffer<ArrayBuffer>;
69
+ /**
70
+ * Calculate the key based on Telegram guidelines, specifying whether it's the client or not
71
+ * @param sharedKey
72
+ * @param msgKey
73
+ * @param client
74
+ * @returns {{iv: Buffer, key: Buffer}}
75
+ */
76
+ export declare function stripText(text: string, entities: Api.TypeMessageEntity[]): string;
77
+ /**
78
+ * Generates the key data corresponding to the given nonces
79
+ * @param serverNonceBigInt
80
+ * @param newNonceBigInt
81
+ * @returns {{key: Buffer, iv: Buffer}}
82
+ */
83
+ export declare function generateKeyDataFromNonce(serverNonceBigInt: bigInt.BigInteger, newNonceBigInt: bigInt.BigInteger): Promise<{
84
+ key: Buffer<ArrayBuffer>;
85
+ iv: Buffer<ArrayBuffer>;
86
+ }>;
87
+ export declare function convertToLittle(buf: Buffer): Buffer<ArrayBuffer>;
88
+ /**
89
+ * Calculates the SHA1 digest for the given data
90
+ * @param data
91
+ * @returns {Promise}
92
+ */
93
+ export declare function sha1(data: Buffer): Promise<Buffer>;
94
+ /**
95
+ * Calculates the SHA256 digest for the given data
96
+ * @param data
97
+ * @returns {Promise}
98
+ */
99
+ export declare function sha256(data: Buffer): Promise<Buffer>;
100
+ /**
101
+ * Fast mod pow for RSA calculation. a^b % n
102
+ * @param a
103
+ * @param b
104
+ * @param n
105
+ * @returns {bigInt.BigInteger}
106
+ */
107
+ export declare function modExp(a: bigInt.BigInteger, b: bigInt.BigInteger, n: bigInt.BigInteger): bigInt.BigInteger;
108
+ /**
109
+ * Gets the arbitrary-length byte array corresponding to the given integer
110
+ * @param integer {number,BigInteger}
111
+ * @param signed {boolean}
112
+ * @returns {Buffer}
113
+ */
114
+ export declare function getByteArray(integer: bigInt.BigInteger | number, signed?: boolean): Buffer<ArrayBufferLike>;
115
+ export declare function returnBigInt(num: bigInt.BigInteger | string | number | bigint): bigInt.BigInteger;
116
+ /**
117
+ * Helper function to return the smaller big int in an array
118
+ * @param arrayOfBigInts
119
+ */
120
+ export declare function getMinBigInt(arrayOfBigInts: (bigInt.BigInteger | string)[]): bigInt.BigInteger;
121
+ /**
122
+ * returns a random int from min (inclusive) and max (inclusive)
123
+ * @param min
124
+ * @param max
125
+ * @returns {number}
126
+ */
127
+ export declare function getRandomInt(min: number, max: number): number;
128
+ /**
129
+ * Sleeps a specified amount of time
130
+ * @param ms time in milliseconds
131
+ * @param isUnref make a timer unref'ed
132
+ * @returns {Promise}
133
+ */
134
+ export declare const sleep: (ms: number, isUnref?: boolean) => Promise<unknown>;
135
+ /**
136
+ * Helper to export two buffers of same length
137
+ * @returns {Buffer}
138
+ */
139
+ export declare function bufferXor(a: Buffer, b: Buffer): Buffer<ArrayBuffer>;
140
+ export declare function crc32(buf: Buffer | string): number;
141
+ export declare class TotalList<T> extends Array<T> {
142
+ total?: number;
143
+ constructor();
144
+ }
145
+ export declare const _EntityType: {
146
+ USER: number;
147
+ CHAT: number;
148
+ CHANNEL: number;
149
+ };
150
+ export declare function _entityType(entity: EntityLike): number;
package/Helpers.js ADDED
@@ -0,0 +1,477 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._EntityType = exports.TotalList = exports.sleep = exports.isArrayLike = void 0;
7
+ exports.readBigIntFromBuffer = readBigIntFromBuffer;
8
+ exports.generateRandomBigInt = generateRandomBigInt;
9
+ exports.escapeRegex = escapeRegex;
10
+ exports.groupBy = groupBy;
11
+ exports.betterConsoleLog = betterConsoleLog;
12
+ exports.toSignedLittleBuffer = toSignedLittleBuffer;
13
+ exports.readBufferFromBigInt = readBufferFromBigInt;
14
+ exports.generateRandomLong = generateRandomLong;
15
+ exports.mod = mod;
16
+ exports.bigIntMod = bigIntMod;
17
+ exports.generateRandomBytes = generateRandomBytes;
18
+ exports.stripText = stripText;
19
+ exports.generateKeyDataFromNonce = generateKeyDataFromNonce;
20
+ exports.convertToLittle = convertToLittle;
21
+ exports.sha1 = sha1;
22
+ exports.sha256 = sha256;
23
+ exports.modExp = modExp;
24
+ exports.getByteArray = getByteArray;
25
+ exports.returnBigInt = returnBigInt;
26
+ exports.getMinBigInt = getMinBigInt;
27
+ exports.getRandomInt = getRandomInt;
28
+ exports.bufferXor = bufferXor;
29
+ exports.crc32 = crc32;
30
+ exports._entityType = _entityType;
31
+ const big_integer_1 = __importDefault(require("big-integer"));
32
+ const CryptoFile_1 = __importDefault(require("./CryptoFile"));
33
+ /**
34
+ * converts a buffer to big int
35
+ * @param buffer
36
+ * @param little
37
+ * @param signed
38
+ * @returns {bigInt.BigInteger}
39
+ */
40
+ function readBigIntFromBuffer(buffer, little = true, signed = false) {
41
+ let randBuffer = Buffer.from(buffer);
42
+ const bytesNumber = randBuffer.length;
43
+ if (little) {
44
+ randBuffer = randBuffer.reverse();
45
+ }
46
+ let bigIntVar = (0, big_integer_1.default)(randBuffer.toString("hex"), 16);
47
+ if (signed && Math.floor(bigIntVar.toString(2).length / 8) >= bytesNumber) {
48
+ bigIntVar = bigIntVar.subtract((0, big_integer_1.default)(2).pow((0, big_integer_1.default)(bytesNumber * 8)));
49
+ }
50
+ return bigIntVar;
51
+ }
52
+ function generateRandomBigInt() {
53
+ return readBigIntFromBuffer(generateRandomBytes(8), false);
54
+ }
55
+ function escapeRegex(string) {
56
+ return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
57
+ }
58
+ function groupBy(list, keyGetter) {
59
+ const map = new Map();
60
+ list.forEach((item) => {
61
+ const key = keyGetter(item);
62
+ const collection = map.get(key);
63
+ if (!collection) {
64
+ map.set(key, [item]);
65
+ }
66
+ else {
67
+ collection.push(item);
68
+ }
69
+ });
70
+ return map;
71
+ }
72
+ /**
73
+ * Outputs the object in a better way by hiding all the private methods/attributes.
74
+ * @param object - the class to use
75
+ */
76
+ function betterConsoleLog(object) {
77
+ const toPrint = {};
78
+ for (const key in object) {
79
+ if (object.hasOwnProperty(key)) {
80
+ if (!key.startsWith("_") && key != "originalArgs") {
81
+ toPrint[key] = object[key];
82
+ }
83
+ }
84
+ }
85
+ return toPrint;
86
+ }
87
+ /**
88
+ * Helper to find if a given object is an array (or similar)
89
+ */
90
+ const isArrayLike = (x) => x &&
91
+ typeof x.length === "number" &&
92
+ typeof x !== "function" &&
93
+ typeof x !== "string";
94
+ exports.isArrayLike = isArrayLike;
95
+ /*
96
+ export function addSurrogate(text: string) {
97
+ let temp = "";
98
+ for (const letter of text) {
99
+ const t = letter.charCodeAt(0);
100
+ if (0x1000 < t && t < 0x10FFFF) {
101
+ const b = Buffer.from(letter, "utf16le");
102
+ const r = String.fromCharCode(b.readUInt16LE(0)) + String.fromCharCode(b.readUInt16LE(2));
103
+ temp += r;
104
+ } else {
105
+ text += letter;
106
+ }
107
+ }
108
+ return temp;
109
+ }
110
+
111
+ */
112
+ /**
113
+ * Special case signed little ints
114
+ * @param big
115
+ * @param number
116
+ * @returns {Buffer}
117
+ */
118
+ function toSignedLittleBuffer(big, number = 8) {
119
+ const bigNumber = returnBigInt(big);
120
+ const byteArray = [];
121
+ for (let i = 0; i < number; i++) {
122
+ byteArray[i] = bigNumber.shiftRight(8 * i).and(255);
123
+ }
124
+ // smh hacks
125
+ return Buffer.from(byteArray);
126
+ }
127
+ /**
128
+ * converts a big int to a buffer
129
+ * @param bigIntVar {BigInteger}
130
+ * @param bytesNumber
131
+ * @param little
132
+ * @param signed
133
+ * @returns {Buffer}
134
+ */
135
+ function readBufferFromBigInt(bigIntVar, bytesNumber, little = true, signed = false) {
136
+ bigIntVar = (0, big_integer_1.default)(bigIntVar);
137
+ const bitLength = bigIntVar.bitLength().toJSNumber();
138
+ const bytes = Math.ceil(bitLength / 8);
139
+ if (bytesNumber < bytes) {
140
+ throw new Error("OverflowError: int too big to convert");
141
+ }
142
+ if (!signed && bigIntVar.lesser((0, big_integer_1.default)(0))) {
143
+ throw new Error("Cannot convert to unsigned");
144
+ }
145
+ if (signed && bigIntVar.lesser((0, big_integer_1.default)(0))) {
146
+ bigIntVar = (0, big_integer_1.default)(2)
147
+ .pow((0, big_integer_1.default)(bytesNumber).multiply(8))
148
+ .add(bigIntVar);
149
+ }
150
+ const hex = bigIntVar.toString(16).padStart(bytesNumber * 2, "0");
151
+ let buffer = Buffer.from(hex, "hex");
152
+ if (little) {
153
+ buffer = buffer.reverse();
154
+ }
155
+ return buffer;
156
+ }
157
+ /**
158
+ * Generates a random long integer (8 bytes), which is optionally signed
159
+ * @returns {BigInteger}
160
+ */
161
+ function generateRandomLong(signed = true) {
162
+ return readBigIntFromBuffer(generateRandomBytes(8), true, signed);
163
+ }
164
+ /**
165
+ * .... really javascript
166
+ * @param n {number}
167
+ * @param m {number}
168
+ * @returns {number}
169
+ */
170
+ function mod(n, m) {
171
+ return ((n % m) + m) % m;
172
+ }
173
+ /**
174
+ * returns a positive bigInt
175
+ * @param n {bigInt.BigInteger}
176
+ * @param m {bigInt.BigInteger}
177
+ * @returns {bigInt.BigInteger}
178
+ */
179
+ function bigIntMod(n, m) {
180
+ return n.remainder(m).add(m).remainder(m);
181
+ }
182
+ /**
183
+ * Generates a random bytes array
184
+ * @param count
185
+ * @returns {Buffer}
186
+ */
187
+ function generateRandomBytes(count) {
188
+ return Buffer.from(CryptoFile_1.default.randomBytes(count));
189
+ }
190
+ /**
191
+ * Calculate the key based on Telegram guidelines, specifying whether it's the client or not
192
+ * @param sharedKey
193
+ * @param msgKey
194
+ * @param client
195
+ * @returns {{iv: Buffer, key: Buffer}}
196
+ */
197
+ /*CONTEST
198
+ this is mtproto 1 (mostly used for secret chats)
199
+ async function calcKey(sharedKey, msgKey, client) {
200
+ const x = client === true ? 0 : 8
201
+ const [sha1a, sha1b, sha1c, sha1d] = await Promise.all([
202
+ sha1(Buffer.concat([msgKey, sharedKey.slice(x, x + 32)])),
203
+ sha1(Buffer.concat([sharedKey.slice(x + 32, x + 48), msgKey, sharedKey.slice(x + 48, x + 64)])),
204
+ sha1(Buffer.concat([sharedKey.slice(x + 64, x + 96), msgKey])),
205
+ sha1(Buffer.concat([msgKey, sharedKey.slice(x + 96, x + 128)]))
206
+ ])
207
+ const key = Buffer.concat([sha1a.slice(0, 8), sha1b.slice(8, 20), sha1c.slice(4, 16)])
208
+ const iv = Buffer.concat([sha1a.slice(8, 20), sha1b.slice(0, 8), sha1c.slice(16, 20), sha1d.slice(0, 8)])
209
+ return {
210
+ key,
211
+ iv
212
+ }
213
+ }
214
+
215
+ */
216
+ function stripText(text, entities) {
217
+ if (!entities || !entities.length) {
218
+ return text.trim();
219
+ }
220
+ while (text && text[text.length - 1].trim() === "") {
221
+ const e = entities[entities.length - 1];
222
+ if (e.offset + e.length == text.length) {
223
+ if (e.length == 1) {
224
+ entities.pop();
225
+ if (!entities.length) {
226
+ return text.trim();
227
+ }
228
+ }
229
+ else {
230
+ e.length -= 1;
231
+ }
232
+ }
233
+ text = text.slice(0, -1);
234
+ }
235
+ while (text && text[0].trim() === "") {
236
+ for (let i = 0; i < entities.length; i++) {
237
+ const e = entities[i];
238
+ if (e.offset != 0) {
239
+ e.offset--;
240
+ continue;
241
+ }
242
+ if (e.length == 1) {
243
+ entities.shift();
244
+ if (!entities.length) {
245
+ return text.trimLeft();
246
+ }
247
+ }
248
+ else {
249
+ e.length -= 1;
250
+ }
251
+ }
252
+ text = text.slice(1);
253
+ }
254
+ return text;
255
+ }
256
+ /**
257
+ * Generates the key data corresponding to the given nonces
258
+ * @param serverNonceBigInt
259
+ * @param newNonceBigInt
260
+ * @returns {{key: Buffer, iv: Buffer}}
261
+ */
262
+ async function generateKeyDataFromNonce(serverNonceBigInt, newNonceBigInt) {
263
+ const serverNonce = toSignedLittleBuffer(serverNonceBigInt, 16);
264
+ const newNonce = toSignedLittleBuffer(newNonceBigInt, 32);
265
+ const [hash1, hash2, hash3] = await Promise.all([
266
+ sha1(Buffer.concat([newNonce, serverNonce])),
267
+ sha1(Buffer.concat([serverNonce, newNonce])),
268
+ sha1(Buffer.concat([newNonce, newNonce])),
269
+ ]);
270
+ const keyBuffer = Buffer.concat([hash1, hash2.slice(0, 12)]);
271
+ const ivBuffer = Buffer.concat([
272
+ hash2.slice(12, 20),
273
+ hash3,
274
+ newNonce.slice(0, 4),
275
+ ]);
276
+ return {
277
+ key: keyBuffer,
278
+ iv: ivBuffer,
279
+ };
280
+ }
281
+ function convertToLittle(buf) {
282
+ const correct = Buffer.alloc(buf.length * 4);
283
+ for (let i = 0; i < buf.length; i++) {
284
+ correct.writeUInt32BE(buf[i], i * 4);
285
+ }
286
+ return correct;
287
+ }
288
+ /**
289
+ * Calculates the SHA1 digest for the given data
290
+ * @param data
291
+ * @returns {Promise}
292
+ */
293
+ function sha1(data) {
294
+ const shaSum = CryptoFile_1.default.createHash("sha1");
295
+ shaSum.update(data);
296
+ // @ts-ignore
297
+ return shaSum.digest();
298
+ }
299
+ /**
300
+ * Calculates the SHA256 digest for the given data
301
+ * @param data
302
+ * @returns {Promise}
303
+ */
304
+ function sha256(data) {
305
+ const shaSum = CryptoFile_1.default.createHash("sha256");
306
+ shaSum.update(data);
307
+ // @ts-ignore
308
+ return shaSum.digest();
309
+ }
310
+ /**
311
+ * Fast mod pow for RSA calculation. a^b % n
312
+ * @param a
313
+ * @param b
314
+ * @param n
315
+ * @returns {bigInt.BigInteger}
316
+ */
317
+ function modExp(a, b, n) {
318
+ a = a.remainder(n);
319
+ let result = big_integer_1.default.one;
320
+ let x = a;
321
+ while (b.greater(big_integer_1.default.zero)) {
322
+ const leastSignificantBit = b.remainder((0, big_integer_1.default)(2));
323
+ b = b.divide((0, big_integer_1.default)(2));
324
+ if (leastSignificantBit.eq(big_integer_1.default.one)) {
325
+ result = result.multiply(x);
326
+ result = result.remainder(n);
327
+ }
328
+ x = x.multiply(x);
329
+ x = x.remainder(n);
330
+ }
331
+ return result;
332
+ }
333
+ /**
334
+ * Gets the arbitrary-length byte array corresponding to the given integer
335
+ * @param integer {number,BigInteger}
336
+ * @param signed {boolean}
337
+ * @returns {Buffer}
338
+ */
339
+ function getByteArray(integer, signed = false) {
340
+ const bits = integer.toString(2).length;
341
+ const byteLength = Math.floor((bits + 8 - 1) / 8);
342
+ return readBufferFromBigInt(typeof integer == "number" ? (0, big_integer_1.default)(integer) : integer, byteLength, false, signed);
343
+ }
344
+ function returnBigInt(num) {
345
+ if (big_integer_1.default.isInstance(num)) {
346
+ return num;
347
+ }
348
+ if (typeof num == "number") {
349
+ return (0, big_integer_1.default)(num);
350
+ }
351
+ if (typeof num == "bigint") {
352
+ return (0, big_integer_1.default)(num);
353
+ }
354
+ return (0, big_integer_1.default)(num);
355
+ }
356
+ /**
357
+ * Helper function to return the smaller big int in an array
358
+ * @param arrayOfBigInts
359
+ */
360
+ function getMinBigInt(arrayOfBigInts) {
361
+ if (arrayOfBigInts.length == 0) {
362
+ return big_integer_1.default.zero;
363
+ }
364
+ if (arrayOfBigInts.length == 1) {
365
+ return returnBigInt(arrayOfBigInts[0]);
366
+ }
367
+ let smallest = returnBigInt(arrayOfBigInts[0]);
368
+ for (let i = 1; i < arrayOfBigInts.length; i++) {
369
+ if (returnBigInt(arrayOfBigInts[i]).lesser(smallest)) {
370
+ smallest = returnBigInt(arrayOfBigInts[i]);
371
+ }
372
+ }
373
+ return smallest;
374
+ }
375
+ /**
376
+ * returns a random int from min (inclusive) and max (inclusive)
377
+ * @param min
378
+ * @param max
379
+ * @returns {number}
380
+ */
381
+ function getRandomInt(min, max) {
382
+ min = Math.ceil(min);
383
+ max = Math.floor(max);
384
+ return Math.floor(Math.random() * (max - min + 1)) + min;
385
+ }
386
+ /**
387
+ * Sleeps a specified amount of time
388
+ * @param ms time in milliseconds
389
+ * @param isUnref make a timer unref'ed
390
+ * @returns {Promise}
391
+ */
392
+ const sleep = (ms, isUnref = false) => new Promise((resolve) => isUnref ? setTimeout(resolve, ms).unref() : setTimeout(resolve, ms));
393
+ exports.sleep = sleep;
394
+ /**
395
+ * Helper to export two buffers of same length
396
+ * @returns {Buffer}
397
+ */
398
+ function bufferXor(a, b) {
399
+ const res = [];
400
+ for (let i = 0; i < a.length; i++) {
401
+ res.push(a[i] ^ b[i]);
402
+ }
403
+ return Buffer.from(res);
404
+ }
405
+ // Taken from https://stackoverflow.com/questions/18638900/javascript-crc32/18639999#18639999
406
+ function makeCRCTable() {
407
+ let c;
408
+ const crcTable = [];
409
+ for (let n = 0; n < 256; n++) {
410
+ c = n;
411
+ for (let k = 0; k < 8; k++) {
412
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
413
+ }
414
+ crcTable[n] = c;
415
+ }
416
+ return crcTable;
417
+ }
418
+ let crcTable = undefined;
419
+ function crc32(buf) {
420
+ if (!crcTable) {
421
+ crcTable = makeCRCTable();
422
+ }
423
+ if (!Buffer.isBuffer(buf)) {
424
+ buf = Buffer.from(buf);
425
+ }
426
+ let crc = -1;
427
+ for (let index = 0; index < buf.length; index++) {
428
+ const byte = buf[index];
429
+ crc = crcTable[(crc ^ byte) & 0xff] ^ (crc >>> 8);
430
+ }
431
+ return (crc ^ -1) >>> 0;
432
+ }
433
+ class TotalList extends Array {
434
+ constructor() {
435
+ super();
436
+ this.total = 0;
437
+ }
438
+ }
439
+ exports.TotalList = TotalList;
440
+ exports._EntityType = {
441
+ USER: 0,
442
+ CHAT: 1,
443
+ CHANNEL: 2,
444
+ };
445
+ Object.freeze(exports._EntityType);
446
+ function _entityType(entity) {
447
+ if (typeof entity !== "object" || !("SUBCLASS_OF_ID" in entity)) {
448
+ throw new Error(`${entity} is not a TLObject, cannot determine entity type`);
449
+ }
450
+ if (![
451
+ 0x2d45687, // crc32('Peer')
452
+ 0xc91c90b6, // crc32('InputPeer')
453
+ 0xe669bf46, // crc32('InputUser')
454
+ 0x40f202fd, // crc32('InputChannel')
455
+ 0x2da17977, // crc32('User')
456
+ 0xc5af5d94, // crc32('Chat')
457
+ 0x1f4661b9, // crc32('UserFull')
458
+ 0xd49a2697, // crc32('ChatFull')
459
+ ].includes(entity.SUBCLASS_OF_ID)) {
460
+ throw new Error(`${entity} does not have any entity type`);
461
+ }
462
+ const name = entity.className;
463
+ if (name.includes("User")) {
464
+ return exports._EntityType.USER;
465
+ }
466
+ else if (name.includes("Chat")) {
467
+ return exports._EntityType.CHAT;
468
+ }
469
+ else if (name.includes("Channel")) {
470
+ return exports._EntityType.CHANNEL;
471
+ }
472
+ else if (name.includes("Self")) {
473
+ return exports._EntityType.USER;
474
+ }
475
+ // 'Empty' in name or not found, we don't care, not a valid entity.
476
+ throw new Error(`${entity} does not have any entity type`);
477
+ }
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alexander Grigoryev
4
+ Based on work originally licensed under MIT by GramJS (c) 2019
5
+ https://github.com/gram-js/gramjs
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/Password.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Api } from "./tl";
2
+ /**
3
+ *
4
+ * @param algo {constructors.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow}
5
+ * @param password
6
+ */
7
+ declare function computeDigest(algo: Api.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow, password: string): Promise<Buffer<ArrayBufferLike>>;
8
+ /**
9
+ *
10
+ * @param request {constructors.account.Password}
11
+ * @param password {string}
12
+ */
13
+ declare function computeCheck(request: Api.account.Password, password: string): Promise<Api.InputCheckPasswordSRP>;
14
+ export { computeCheck, computeDigest };