teleproto 203.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CryptoFile.d.ts +2 -0
  2. package/CryptoFile.js +23 -0
  3. package/Helpers.d.ts +151 -0
  4. package/Helpers.js +477 -0
  5. package/LICENSE +23 -0
  6. package/Password.d.ts +15 -0
  7. package/Password.js +271 -0
  8. package/README.md +111 -0
  9. package/Utils.d.ts +228 -0
  10. package/Utils.js +1248 -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 +109 -0
  15. package/client/TelegramClient.d.ts +1042 -0
  16. package/client/TelegramClient.js +1167 -0
  17. package/client/account.d.ts +0 -0
  18. package/client/account.js +1 -0
  19. package/client/auth.d.ts +93 -0
  20. package/client/auth.js +375 -0
  21. package/client/bots.d.ts +6 -0
  22. package/client/bots.js +24 -0
  23. package/client/buttons.d.ts +4 -0
  24. package/client/buttons.js +87 -0
  25. package/client/chats.d.ts +46 -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 +157 -0
  30. package/client/downloads.js +598 -0
  31. package/client/fs.d.ts +1 -0
  32. package/client/fs.js +13 -0
  33. package/client/index.d.ts +15 -0
  34. package/client/index.js +50 -0
  35. package/client/messageParse.d.ts +17 -0
  36. package/client/messageParse.js +191 -0
  37. package/client/messages.d.ts +259 -0
  38. package/client/messages.js +804 -0
  39. package/client/os.d.ts +2 -0
  40. package/client/os.js +23 -0
  41. package/client/path.d.ts +2 -0
  42. package/client/path.js +7 -0
  43. package/client/telegramBaseClient.d.ts +238 -0
  44. package/client/telegramBaseClient.js +368 -0
  45. package/client/updates.d.ts +31 -0
  46. package/client/updates.js +254 -0
  47. package/client/uploads.d.ts +137 -0
  48. package/client/uploads.js +514 -0
  49. package/client/users.d.ts +29 -0
  50. package/client/users.js +491 -0
  51. package/crypto/AuthKey.d.ts +20 -0
  52. package/crypto/AuthKey.js +76 -0
  53. package/crypto/CTR.d.ts +6 -0
  54. package/crypto/CTR.js +35 -0
  55. package/crypto/Factorizator.d.ts +19 -0
  56. package/crypto/Factorizator.js +74 -0
  57. package/crypto/IGE.d.ts +18 -0
  58. package/crypto/IGE.js +34 -0
  59. package/crypto/RSA.d.ts +15 -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 +27 -0
  64. package/crypto/crypto.js +117 -0
  65. package/crypto/words.d.ts +6 -0
  66. package/crypto/words.js +48 -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 +72 -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 +29 -0
  78. package/events/Album.d.ts +36 -0
  79. package/events/Album.js +104 -0
  80. package/events/CallbackQuery.d.ts +74 -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 +100 -0
  97. package/extensions/BinaryReader.js +242 -0
  98. package/extensions/BinaryWriter.d.ts +7 -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 +56 -0
  103. package/extensions/Logger.js +107 -0
  104. package/extensions/MessagePacker.d.ts +22 -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 +25 -0
  109. package/extensions/PromisedNetSockets.js +178 -0
  110. package/extensions/PromisedWebSockets.d.ts +19 -0
  111. package/extensions/PromisedWebSockets.js +124 -0
  112. package/extensions/html.d.ts +5 -0
  113. package/extensions/html.js +213 -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 +13 -0
  122. package/extensions/socks.d.ts +1 -0
  123. package/extensions/socks.js +13 -0
  124. package/index.d.ts +14 -0
  125. package/index.js +48 -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 +193 -0
  130. package/network/MTProtoPlainSender.d.ts +19 -0
  131. package/network/MTProtoPlainSender.js +74 -0
  132. package/network/MTProtoSender.d.ts +291 -0
  133. package/network/MTProtoSender.js +854 -0
  134. package/network/MTProtoState.d.ts +103 -0
  135. package/network/MTProtoState.js +267 -0
  136. package/network/RequestState.d.ts +19 -0
  137. package/network/RequestState.js +35 -0
  138. package/network/connection/Connection.d.ts +71 -0
  139. package/network/connection/Connection.js +157 -0
  140. package/network/connection/TCPAbridged.d.ts +20 -0
  141. package/network/connection/TCPAbridged.js +58 -0
  142. package/network/connection/TCPFull.d.ts +17 -0
  143. package/network/connection/TCPFull.js +61 -0
  144. package/network/connection/TCPMTProxy.d.ts +50 -0
  145. package/network/connection/TCPMTProxy.js +121 -0
  146. package/network/connection/TCPObfuscated.d.ts +19 -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 +69 -0
  153. package/requestIter.d.ts +24 -0
  154. package/requestIter.js +107 -0
  155. package/sessions/Abstract.d.ts +103 -0
  156. package/sessions/Abstract.js +6 -0
  157. package/sessions/CacheApiSession.d.ts +18 -0
  158. package/sessions/CacheApiSession.js +99 -0
  159. package/sessions/Memory.d.ts +38 -0
  160. package/sessions/Memory.js +272 -0
  161. package/sessions/StoreSession.d.ts +14 -0
  162. package/sessions/StoreSession.js +77 -0
  163. package/sessions/StringSession.d.ts +33 -0
  164. package/sessions/StringSession.js +116 -0
  165. package/sessions/index.d.ts +4 -0
  166. package/sessions/index.js +13 -0
  167. package/sessions/localStorage.d.ts +1 -0
  168. package/sessions/localStorage.js +4 -0
  169. package/tl/AllTLObjects.d.ts +3 -0
  170. package/tl/AllTLObjects.js +17 -0
  171. package/tl/MTProtoRequest.d.ts +19 -0
  172. package/tl/MTProtoRequest.js +38 -0
  173. package/tl/api.d.ts +31425 -0
  174. package/tl/api.js +507 -0
  175. package/tl/apiTl.d.ts +2 -0
  176. package/tl/apiTl.js +2142 -0
  177. package/tl/core/GZIPPacked.d.ts +16 -0
  178. package/tl/core/GZIPPacked.js +51 -0
  179. package/tl/core/MessageContainer.d.ts +12 -0
  180. package/tl/core/MessageContainer.js +42 -0
  181. package/tl/core/RPCResult.d.ts +15 -0
  182. package/tl/core/RPCResult.js +32 -0
  183. package/tl/core/TLMessage.d.ts +10 -0
  184. package/tl/core/TLMessage.js +14 -0
  185. package/tl/core/index.d.ts +6 -0
  186. package/tl/core/index.js +16 -0
  187. package/tl/custom/button.d.ts +25 -0
  188. package/tl/custom/button.js +78 -0
  189. package/tl/custom/chatGetter.d.ts +30 -0
  190. package/tl/custom/chatGetter.js +114 -0
  191. package/tl/custom/dialog.d.ts +31 -0
  192. package/tl/custom/dialog.js +40 -0
  193. package/tl/custom/draft.d.ts +22 -0
  194. package/tl/custom/draft.js +48 -0
  195. package/tl/custom/file.d.ts +22 -0
  196. package/tl/custom/file.js +68 -0
  197. package/tl/custom/forward.d.ts +16 -0
  198. package/tl/custom/forward.js +47 -0
  199. package/tl/custom/index.d.ts +1 -0
  200. package/tl/custom/index.js +5 -0
  201. package/tl/custom/inlineResult.d.ts +33 -0
  202. package/tl/custom/inlineResult.js +87 -0
  203. package/tl/custom/inlineResults.d.ts +21 -0
  204. package/tl/custom/inlineResults.js +26 -0
  205. package/tl/custom/message.d.ts +428 -0
  206. package/tl/custom/message.js +702 -0
  207. package/tl/custom/messageButton.d.ts +55 -0
  208. package/tl/custom/messageButton.js +152 -0
  209. package/tl/custom/senderGetter.d.ts +29 -0
  210. package/tl/custom/senderGetter.js +55 -0
  211. package/tl/generateModule.d.ts +1 -0
  212. package/tl/generateModule.js +17 -0
  213. package/tl/generationHelpers.d.ts +12 -0
  214. package/tl/generationHelpers.js +289 -0
  215. package/tl/index.d.ts +3 -0
  216. package/tl/index.js +10 -0
  217. package/tl/patched/index.d.ts +2 -0
  218. package/tl/patched/index.js +77 -0
  219. package/tl/schemaTl.d.ts +2 -0
  220. package/tl/schemaTl.js +64 -0
  221. package/tl/types-generator/generate.d.ts +1 -0
  222. package/tl/types-generator/generate.js +84 -0
  223. package/tl/types-generator/template.d.ts +6 -0
  224. package/tl/types-generator/template.js +257 -0
package/Version.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const version = "203.0.0";
package/Version.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ exports.version = "203.0.0";
@@ -0,0 +1,48 @@
1
+ import type { TelegramClient } from "./TelegramClient";
2
+ export interface TwoFaParams {
3
+ isCheckPassword?: boolean;
4
+ currentPassword?: string;
5
+ newPassword?: string;
6
+ hint?: string;
7
+ email?: string;
8
+ emailCodeCallback?: (length: number) => Promise<string>;
9
+ onEmailCodeError?: (err: Error) => void;
10
+ }
11
+ /**
12
+ * Changes the 2FA settings of the logged in user.
13
+ Note that this method may be *incredibly* slow depending on the
14
+ prime numbers that must be used during the process to make sure
15
+ that everything is safe.
16
+
17
+ Has no effect if both current and new password are omitted.
18
+
19
+ * @param client: The telegram client instance
20
+ * @param isCheckPassword: Must be ``true`` if you want to check the current password
21
+ * @param currentPassword: The current password, to authorize changing to ``new_password``.
22
+ Must be set if changing existing 2FA settings.
23
+ Must **not** be set if 2FA is currently disabled.
24
+ Passing this by itself will remove 2FA (if correct).
25
+ * @param newPassword: The password to set as 2FA.
26
+ If 2FA was already enabled, ``currentPassword`` **must** be set.
27
+ Leaving this blank or `undefined` will remove the password.
28
+ * @param hint: Hint to be displayed by Telegram when it asks for 2FA.
29
+ Must be set when changing or creating a new password.
30
+ Has no effect if ``newPassword`` is not set.
31
+ * @param email: Recovery and verification email. If present, you must also
32
+ set `emailCodeCallback`, else it raises an Error.
33
+ * @param emailCodeCallback: If an email is provided, a callback that returns the code sent
34
+ to it must also be set. This callback may be asynchronous.
35
+ It should return a string with the code. The length of the
36
+ code will be passed to the callback as an input parameter.
37
+ * @param onEmailCodeError: Called when an error happens while sending an email.
38
+
39
+ If the callback returns an invalid code, it will raise an rpc error with the message
40
+ ``CODE_INVALID``
41
+
42
+ * @returns Promise<void>
43
+ * @throws this method can throw:
44
+ "PASSWORD_HASH_INVALID" if you entered a wrong password (or set it to undefined).
45
+ "EMAIL_INVALID" if the entered email is wrong
46
+ "EMAIL_HASH_EXPIRED" if the user took too long to verify their email
47
+ */
48
+ export declare function updateTwoFaSettings(client: TelegramClient, { isCheckPassword, currentPassword, newPassword, hint, email, emailCodeCallback, onEmailCodeError, }: TwoFaParams): Promise<void>;
package/client/2fa.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTwoFaSettings = void 0;
4
+ const Helpers_1 = require("../Helpers");
5
+ const Password_1 = require("../Password");
6
+ const tl_1 = require("../tl");
7
+ const index_1 = require("../index");
8
+ /**
9
+ * Changes the 2FA settings of the logged in user.
10
+ Note that this method may be *incredibly* slow depending on the
11
+ prime numbers that must be used during the process to make sure
12
+ that everything is safe.
13
+
14
+ Has no effect if both current and new password are omitted.
15
+
16
+ * @param client: The telegram client instance
17
+ * @param isCheckPassword: Must be ``true`` if you want to check the current password
18
+ * @param currentPassword: The current password, to authorize changing to ``new_password``.
19
+ Must be set if changing existing 2FA settings.
20
+ Must **not** be set if 2FA is currently disabled.
21
+ Passing this by itself will remove 2FA (if correct).
22
+ * @param newPassword: The password to set as 2FA.
23
+ If 2FA was already enabled, ``currentPassword`` **must** be set.
24
+ Leaving this blank or `undefined` will remove the password.
25
+ * @param hint: Hint to be displayed by Telegram when it asks for 2FA.
26
+ Must be set when changing or creating a new password.
27
+ Has no effect if ``newPassword`` is not set.
28
+ * @param email: Recovery and verification email. If present, you must also
29
+ set `emailCodeCallback`, else it raises an Error.
30
+ * @param emailCodeCallback: If an email is provided, a callback that returns the code sent
31
+ to it must also be set. This callback may be asynchronous.
32
+ It should return a string with the code. The length of the
33
+ code will be passed to the callback as an input parameter.
34
+ * @param onEmailCodeError: Called when an error happens while sending an email.
35
+
36
+ If the callback returns an invalid code, it will raise an rpc error with the message
37
+ ``CODE_INVALID``
38
+
39
+ * @returns Promise<void>
40
+ * @throws this method can throw:
41
+ "PASSWORD_HASH_INVALID" if you entered a wrong password (or set it to undefined).
42
+ "EMAIL_INVALID" if the entered email is wrong
43
+ "EMAIL_HASH_EXPIRED" if the user took too long to verify their email
44
+ */
45
+ async function updateTwoFaSettings(client, { isCheckPassword, currentPassword, newPassword, hint = "", email, emailCodeCallback, onEmailCodeError, }) {
46
+ if (!newPassword && !currentPassword) {
47
+ throw new Error("Neither `currentPassword` nor `newPassword` is present");
48
+ }
49
+ if (email && !(emailCodeCallback && onEmailCodeError)) {
50
+ throw new Error("`email` present without `emailCodeCallback` and `onEmailCodeError`");
51
+ }
52
+ const pwd = await client.invoke(new tl_1.Api.account.GetPassword());
53
+ if (!(pwd.newAlgo instanceof tl_1.Api.PasswordKdfAlgoUnknown)) {
54
+ pwd.newAlgo.salt1 = Buffer.concat([
55
+ pwd.newAlgo.salt1,
56
+ (0, Helpers_1.generateRandomBytes)(32),
57
+ ]);
58
+ }
59
+ if (!pwd.hasPassword && currentPassword) {
60
+ currentPassword = undefined;
61
+ }
62
+ const password = currentPassword
63
+ ? await (0, Password_1.computeCheck)(pwd, currentPassword)
64
+ : new tl_1.Api.InputCheckPasswordEmpty();
65
+ if (isCheckPassword) {
66
+ await client.invoke(new tl_1.Api.auth.CheckPassword({ password }));
67
+ return;
68
+ }
69
+ if (pwd.newAlgo instanceof tl_1.Api.PasswordKdfAlgoUnknown) {
70
+ throw new Error("Unknown password encryption method");
71
+ }
72
+ try {
73
+ await client.invoke(new tl_1.Api.account.UpdatePasswordSettings({
74
+ password,
75
+ newSettings: new tl_1.Api.account.PasswordInputSettings({
76
+ newAlgo: pwd.newAlgo,
77
+ newPasswordHash: newPassword
78
+ ? await (0, Password_1.computeDigest)(pwd.newAlgo, newPassword)
79
+ : Buffer.alloc(0),
80
+ hint,
81
+ email,
82
+ // not explained what it does and it seems to always be set to empty in tdesktop
83
+ newSecureSettings: undefined,
84
+ }),
85
+ }));
86
+ }
87
+ catch (e) {
88
+ if (e instanceof index_1.errors.EmailUnconfirmedError) {
89
+ // eslint-disable-next-line no-constant-condition
90
+ while (true) {
91
+ try {
92
+ const code = await emailCodeCallback(e.codeLength);
93
+ if (!code) {
94
+ throw new Error("Code is empty");
95
+ }
96
+ await client.invoke(new tl_1.Api.account.ConfirmPasswordEmail({ code }));
97
+ break;
98
+ }
99
+ catch (err) {
100
+ onEmailCodeError(err);
101
+ }
102
+ }
103
+ }
104
+ else {
105
+ throw e;
106
+ }
107
+ }
108
+ }
109
+ exports.updateTwoFaSettings = updateTwoFaSettings;