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,290 @@
1
+ /**
2
+ * MTProto Mobile Protocol sender
3
+ * (https://core.telegram.org/mtproto/description)
4
+ * This class is responsible for wrapping requests into `TLMessage`'s,
5
+ * sending them over the network and receiving them in a safe manner.
6
+ *
7
+ * Automatic reconnection due to temporary network issues is a concern
8
+ * for this class as well, including retry of messages that could not
9
+ * be sent successfully.
10
+ *
11
+ * A new authorization key will be generated on connection if no other
12
+ * key exists yet.
13
+ */
14
+ import { AuthKey } from "../crypto/AuthKey";
15
+ import { TLMessage } from "../tl/core";
16
+ import { Api } from "../tl";
17
+ import bigInt from "big-integer";
18
+ import { RequestState } from "./RequestState";
19
+ import { Connection, UpdateConnectionState } from ".";
20
+ import type { TelegramClient } from "..";
21
+ import { PendingState } from "../extensions/PendingState";
22
+ interface DEFAULT_OPTIONS {
23
+ logger: any;
24
+ retries: number;
25
+ reconnectRetries: number;
26
+ delay: number;
27
+ autoReconnect: boolean;
28
+ connectTimeout: any;
29
+ authKeyCallback: any;
30
+ updateCallback?: any;
31
+ autoReconnectCallback?: any;
32
+ isMainSender: boolean;
33
+ dcId: number;
34
+ senderCallback?: any;
35
+ client: TelegramClient;
36
+ onConnectionBreak?: CallableFunction;
37
+ securityChecks: boolean;
38
+ _exportedSenderPromises: Map<number, Promise<MTProtoSender>>;
39
+ }
40
+ export declare class MTProtoSender {
41
+ static DEFAULT_OPTIONS: {
42
+ logger: null;
43
+ reconnectRetries: number;
44
+ retries: number;
45
+ delay: number;
46
+ autoReconnect: boolean;
47
+ connectTimeout: null;
48
+ authKeyCallback: null;
49
+ updateCallback: null;
50
+ autoReconnectCallback: null;
51
+ isMainSender: null;
52
+ senderCallback: null;
53
+ onConnectionBreak: undefined;
54
+ securityChecks: boolean;
55
+ };
56
+ _connection?: Connection;
57
+ private readonly _log;
58
+ private _dcId;
59
+ private readonly _retries;
60
+ private _reconnectRetries;
61
+ private _currentRetries;
62
+ private readonly _delay;
63
+ private _connectTimeout;
64
+ private _autoReconnect;
65
+ private readonly _authKeyCallback;
66
+ _updateCallback: (client: TelegramClient, update: UpdateConnectionState) => void;
67
+ private readonly _autoReconnectCallback?;
68
+ private readonly _senderCallback;
69
+ private readonly _isMainSender;
70
+ _userConnected: boolean;
71
+ isReconnecting: boolean;
72
+ _reconnecting: boolean;
73
+ _disconnected: boolean;
74
+ private _sendLoopHandle;
75
+ private _recvLoopHandle;
76
+ readonly authKey: AuthKey;
77
+ private readonly _state;
78
+ private _sendQueue;
79
+ _pendingState: PendingState;
80
+ private readonly _pendingAck;
81
+ private readonly _lastAcks;
82
+ private readonly _handlers;
83
+ private readonly _client;
84
+ private readonly _onConnectionBreak?;
85
+ userDisconnected: boolean;
86
+ isConnecting: boolean;
87
+ _authenticated: boolean;
88
+ private _securityChecks;
89
+ private _connectMutex;
90
+ private _cancelSend;
91
+ private _abortController;
92
+ private _finishedConnecting;
93
+ private _exportedSenderPromises;
94
+ /**
95
+ * @param authKey
96
+ * @param opts
97
+ */
98
+ constructor(authKey: undefined | AuthKey, opts: DEFAULT_OPTIONS);
99
+ set dcId(dcId: number);
100
+ get dcId(): number;
101
+ /**
102
+ * Connects to the specified given connection using the given auth key.
103
+ */
104
+ connect(connection: Connection, force: boolean): Promise<boolean>;
105
+ isConnected(): boolean;
106
+ _transportConnected(): boolean | undefined;
107
+ /**
108
+ * Cleanly disconnects the instance from the network, cancels
109
+ * all pending requests, and closes the send and receive loops.
110
+ */
111
+ disconnect(): Promise<void>;
112
+ /**
113
+ *
114
+ This method enqueues the given request to be sent. Its send
115
+ state will be saved until a response arrives, and a ``Future``
116
+ that will be resolved when the response arrives will be returned:
117
+
118
+ .. code-block:: javascript
119
+
120
+ async def method():
121
+ # Sending (enqueued for the send loop)
122
+ future = sender.send(request)
123
+ # Receiving (waits for the receive loop to read the result)
124
+ result = await future
125
+
126
+ Designed like this because Telegram may send the response at
127
+ any point, and it can send other items while one waits for it.
128
+ Once the response for this future arrives, it is set with the
129
+ received result, quite similar to how a ``receive()`` call
130
+ would otherwise work.
131
+
132
+ Since the receiving part is "built in" the future, it's
133
+ impossible to await receive a result that was never sent.
134
+ * @param request
135
+ * @returns {RequestState}
136
+ */
137
+ send(request: Api.AnyRequest): Promise<unknown> | undefined;
138
+ addStateToQueue(state: RequestState): void;
139
+ /**
140
+ * Performs the actual connection, retrying, generating the
141
+ * authorization key if necessary, and starting the send and
142
+ * receive loops.
143
+ * @returns {Promise<void>}
144
+ * @private
145
+ */
146
+ _connect(): Promise<void>;
147
+ _disconnect(): Promise<void>;
148
+ _cancelLoops(): void;
149
+ /**
150
+ * This loop is responsible for popping items off the send
151
+ * queue, encrypting them, and sending them over the network.
152
+ * Besides `connect`, only this method ever sends data.
153
+ * @returns {Promise<void>}
154
+ * @private
155
+ */
156
+ _sendLoop(): Promise<void>;
157
+ _recvLoop(): Promise<void>;
158
+ _handleBadAuthKey(shouldSkipForMain?: boolean): void;
159
+ /**
160
+ * Adds the given message to the list of messages that must be
161
+ * acknowledged and dispatches control to different ``_handle_*``
162
+ * method based on its type.
163
+ * @param message
164
+ * @returns {Promise<void>}
165
+ * @private
166
+ */
167
+ _processMessage(message: TLMessage): Promise<void>;
168
+ /**
169
+ * Pops the states known to match the given ID from pending messages.
170
+ * This method should be used when the response isn't specific.
171
+ * @param msgId
172
+ * @returns {*[]}
173
+ * @private
174
+ */
175
+ _popStates(msgId: bigInt.BigInteger): any[];
176
+ /**
177
+ * Handles the result for Remote Procedure Calls:
178
+ * rpc_result#f35c6d01 req_msg_id:long result:bytes = RpcResult;
179
+ * This is where the future results for sent requests are set.
180
+ * @param message
181
+ * @returns {Promise<void>}
182
+ * @private
183
+ */
184
+ _handleRPCResult(message: TLMessage): void;
185
+ /**
186
+ * Processes the inner messages of a container with many of them:
187
+ * msg_container#73f1f8dc messages:vector<%Message> = MessageContainer;
188
+ * @param message
189
+ * @returns {Promise<void>}
190
+ * @private
191
+ */
192
+ _handleContainer(message: TLMessage): Promise<void>;
193
+ /**
194
+ * Unpacks the data from a gzipped object and processes it:
195
+ * gzip_packed#3072cfa1 packed_data:bytes = Object;
196
+ * @param message
197
+ * @returns {Promise<void>}
198
+ * @private
199
+ */
200
+ _handleGzipPacked(message: TLMessage): Promise<void>;
201
+ _handleUpdate(message: TLMessage): Promise<void>;
202
+ /**
203
+ * Handles pong results, which don't come inside a ``RPCResult``
204
+ * but are still sent through a request:
205
+ * pong#347773c5 msg_id:long ping_id:long = Pong;
206
+ * @param message
207
+ * @returns {Promise<void>}
208
+ * @private
209
+ */
210
+ _handlePong(message: TLMessage): Promise<void>;
211
+ /**
212
+ * Corrects the currently used server salt to use the right value
213
+ * before enqueuing the rejected message to be re-sent:
214
+ * bad_server_salt#edab447b bad_msg_id:long bad_msg_seqno:int
215
+ * error_code:int new_server_salt:long = BadMsgNotification;
216
+ * @param message
217
+ * @returns {Promise<void>}
218
+ * @private
219
+ */
220
+ _handleBadServerSalt(message: TLMessage): Promise<void>;
221
+ /**
222
+ * Adjusts the current state to be correct based on the
223
+ * received bad message notification whenever possible:
224
+ * bad_msg_notification#a7eff811 bad_msg_id:long bad_msg_seqno:int
225
+ * error_code:int = BadMsgNotification;
226
+ * @param message
227
+ * @returns {Promise<void>}
228
+ * @private
229
+ */
230
+ _handleBadNotification(message: TLMessage): Promise<void>;
231
+ /**
232
+ * Updates the current status with the received detailed information:
233
+ * msg_detailed_info#276d3ec6 msg_id:long answer_msg_id:long
234
+ * bytes:int status:int = MsgDetailedInfo;
235
+ * @param message
236
+ * @returns {Promise<void>}
237
+ * @private
238
+ */
239
+ _handleDetailedInfo(message: TLMessage): Promise<void>;
240
+ /**
241
+ * Updates the current status with the received detailed information:
242
+ * msg_new_detailed_info#809db6df answer_msg_id:long
243
+ * bytes:int status:int = MsgDetailedInfo;
244
+ * @param message
245
+ * @returns {Promise<void>}
246
+ * @private
247
+ */
248
+ _handleNewDetailedInfo(message: TLMessage): Promise<void>;
249
+ /**
250
+ * Updates the current status with the received session information:
251
+ * new_session_created#9ec20908 first_msg_id:long unique_id:long
252
+ * server_salt:long = NewSession;
253
+ * @param message
254
+ * @returns {Promise<void>}
255
+ * @private
256
+ */
257
+ _handleNewSessionCreated(message: TLMessage): Promise<void>;
258
+ /**
259
+ * Handles a server acknowledge about our messages. Normally these can be ignored
260
+ */
261
+ _handleAck(): void;
262
+ /**
263
+ * Handles future salt results, which don't come inside a
264
+ * ``rpc_result`` but are still sent through a request:
265
+ * future_salts#ae500895 req_msg_id:long now:int
266
+ * salts:vector<future_salt> = FutureSalts;
267
+ * @param message
268
+ * @returns {Promise<void>}
269
+ * @private
270
+ */
271
+ _handleFutureSalts(message: TLMessage): Promise<void>;
272
+ /**
273
+ * Handles both :tl:`MsgsStateReq` and :tl:`MsgResendReq` by
274
+ * enqueuing a :tl:`MsgsStateInfo` to be sent at a later point.
275
+ * @param message
276
+ * @returns {Promise<void>}
277
+ * @private
278
+ */
279
+ _handleStateForgotten(message: TLMessage): Promise<void>;
280
+ /**
281
+ * Handles :tl:`MsgsAllInfo` by doing nothing (yet).
282
+ * @param message
283
+ * @returns {Promise<void>}
284
+ * @private
285
+ */
286
+ _handleMsgAll(message: TLMessage): Promise<void>;
287
+ reconnect(): void;
288
+ _reconnect(): Promise<void>;
289
+ }
290
+ export {};