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