@mtkruto/node 0.62.0 → 0.63.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 (513) hide show
  1. package/esm/2_tl.d.ts +6 -6
  2. package/esm/2_tl.d.ts.map +1 -1
  3. package/esm/2_tl.js +6 -6
  4. package/esm/3_errors.d.ts +1 -2
  5. package/esm/3_errors.d.ts.map +1 -1
  6. package/esm/3_errors.js +2 -1
  7. package/esm/4_constants.d.ts +0 -1
  8. package/esm/4_constants.d.ts.map +1 -1
  9. package/esm/4_constants.js +0 -1
  10. package/esm/4_errors.d.ts +2 -2
  11. package/esm/4_errors.d.ts.map +1 -1
  12. package/esm/4_session.d.ts +24 -0
  13. package/esm/4_session.d.ts.map +1 -0
  14. package/esm/4_session.js +23 -0
  15. package/esm/5_client.d.ts +1 -1
  16. package/esm/5_client.js +1 -1
  17. package/esm/client/0_client_abstract.d.ts +28 -26
  18. package/esm/client/0_client_abstract.d.ts.map +1 -1
  19. package/esm/client/0_client_abstract.js +16 -88
  20. package/esm/client/0_params.d.ts +5 -0
  21. package/esm/client/0_params.d.ts.map +1 -1
  22. package/esm/client/0_password.d.ts.map +1 -1
  23. package/esm/client/0_password.js +2 -2
  24. package/esm/client/0_storage_operations.d.ts +4 -4
  25. package/esm/client/0_storage_operations.d.ts.map +1 -1
  26. package/esm/client/0_storage_operations.js +14 -14
  27. package/esm/client/0_update_processor.d.ts +19 -0
  28. package/esm/client/0_update_processor.d.ts.map +1 -1
  29. package/esm/client/0_update_processor.js +19 -0
  30. package/esm/client/0_utilities.d.ts +6 -2
  31. package/esm/client/0_utilities.d.ts.map +1 -1
  32. package/esm/client/0_utilities.js +21 -23
  33. package/esm/client/1_client_plain.d.ts +9 -6
  34. package/esm/client/1_client_plain.d.ts.map +1 -1
  35. package/esm/client/1_client_plain.js +26 -41
  36. package/esm/client/1_types.d.ts +4 -23
  37. package/esm/client/1_types.d.ts.map +1 -1
  38. package/esm/client/2_account_manager.js +10 -10
  39. package/esm/client/2_business_connection_manager.d.ts.map +1 -1
  40. package/esm/client/2_business_connection_manager.js +4 -4
  41. package/esm/client/2_client_encrypted.d.ts +58 -0
  42. package/esm/client/2_client_encrypted.d.ts.map +1 -0
  43. package/esm/client/2_client_encrypted.js +265 -0
  44. package/esm/client/2_file_manager.d.ts.map +1 -1
  45. package/esm/client/2_file_manager.js +54 -74
  46. package/esm/client/2_network_statistics_manager.d.ts +1 -1
  47. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  48. package/esm/client/2_network_statistics_manager.js +3 -3
  49. package/esm/client/2_payment_manager.d.ts.map +1 -1
  50. package/esm/client/2_payment_manager.js +3 -3
  51. package/esm/client/2_reaction_manager.d.ts.map +1 -1
  52. package/esm/client/2_reaction_manager.js +10 -10
  53. package/esm/client/2_translations_manager.d.ts +19 -0
  54. package/esm/client/2_translations_manager.d.ts.map +1 -1
  55. package/esm/client/2_translations_manager.js +24 -5
  56. package/esm/client/2_update_manager.d.ts +4 -4
  57. package/esm/client/2_update_manager.d.ts.map +1 -1
  58. package/esm/client/2_update_manager.js +69 -79
  59. package/esm/client/3_client_encrypted_pool.d.ts +30 -0
  60. package/esm/client/3_client_encrypted_pool.d.ts.map +1 -0
  61. package/esm/client/3_client_encrypted_pool.js +70 -0
  62. package/esm/client/3_message_manager.d.ts.map +1 -1
  63. package/esm/client/3_message_manager.js +100 -74
  64. package/esm/client/3_video_chat_manager.d.ts.map +1 -1
  65. package/esm/client/3_video_chat_manager.js +15 -20
  66. package/esm/client/4_callback_query_manager.d.ts.map +1 -1
  67. package/esm/client/4_callback_query_manager.js +2 -2
  68. package/esm/client/4_chat_list_manager.d.ts.map +1 -1
  69. package/esm/client/4_chat_list_manager.js +33 -33
  70. package/esm/client/4_chat_manager.d.ts.map +1 -1
  71. package/esm/client/4_chat_manager.js +25 -25
  72. package/esm/client/4_gift_manager.js +2 -2
  73. package/esm/client/4_inline_query_manager.d.ts.map +1 -1
  74. package/esm/client/4_inline_query_manager.js +4 -4
  75. package/esm/client/4_poll_manager.d.ts.map +1 -1
  76. package/esm/client/4_poll_manager.js +5 -5
  77. package/esm/client/4_story_manager.d.ts.map +1 -1
  78. package/esm/client/4_story_manager.js +10 -10
  79. package/esm/client/5_client.d.ts +3 -9
  80. package/esm/client/5_client.d.ts.map +1 -1
  81. package/esm/client/5_client.js +290 -306
  82. package/esm/connection/0_connection.d.ts +5 -4
  83. package/esm/connection/0_connection.d.ts.map +1 -1
  84. package/esm/connection/1_connection_web_socket.js +2 -2
  85. package/esm/mod.d.ts +1 -1
  86. package/esm/mod.d.ts.map +1 -1
  87. package/esm/mod.js +1 -1
  88. package/{script/tl/2_tl_reader.d.ts → esm/session/0_session_error.d.ts} +4 -7
  89. package/esm/session/0_session_error.d.ts.map +1 -0
  90. package/esm/{tl/2_tl_reader.d.ts → session/0_session_error.js} +5 -7
  91. package/esm/{tl/2_tl_writer.d.ts → session/0_session_state.d.ts} +7 -5
  92. package/esm/session/0_session_state.d.ts.map +1 -0
  93. package/esm/session/0_session_state.js +77 -0
  94. package/esm/session/1_session.d.ts +31 -0
  95. package/esm/session/1_session.d.ts.map +1 -0
  96. package/esm/session/1_session.js +149 -0
  97. package/esm/session/2_session_encrypted.d.ts +40 -0
  98. package/esm/session/2_session_encrypted.d.ts.map +1 -0
  99. package/esm/session/2_session_encrypted.js +416 -0
  100. package/esm/session/2_session_plain.d.ts +25 -0
  101. package/esm/session/2_session_plain.d.ts.map +1 -0
  102. package/esm/session/2_session_plain.js +56 -0
  103. package/esm/tl/0_tl_error.d.ts +22 -0
  104. package/esm/tl/0_tl_error.d.ts.map +1 -0
  105. package/esm/tl/0_tl_error.js +21 -0
  106. package/esm/tl/0_types.d.ts +25 -0
  107. package/esm/tl/0_types.d.ts.map +1 -0
  108. package/esm/tl/0_types.js +20 -0
  109. package/esm/tl/0_utilities.d.ts +32 -0
  110. package/esm/tl/0_utilities.d.ts.map +1 -0
  111. package/esm/tl/0_utilities.js +51 -0
  112. package/esm/tl/0_utilities_test.d.ts.map +1 -0
  113. package/esm/tl/1_mtproto_api.d.ts +371 -0
  114. package/esm/tl/1_mtproto_api.d.ts.map +1 -0
  115. package/esm/tl/1_mtproto_api.js +416 -0
  116. package/esm/tl/{0_api.d.ts → 1_telegram_api.d.ts} +23 -340
  117. package/esm/tl/1_telegram_api.d.ts.map +1 -0
  118. package/esm/tl/{0_api.js → 1_telegram_api.js} +4945 -11109
  119. package/{script/tl/0_tl_raw_reader.d.ts → esm/tl/1_tl_reader.d.ts} +5 -2
  120. package/esm/tl/1_tl_reader.d.ts.map +1 -0
  121. package/esm/tl/{2_tl_reader.js → 1_tl_reader.js} +107 -40
  122. package/esm/tl/1_tl_reader_test.d.ts.map +1 -0
  123. package/esm/tl/{0_tl_raw_writer.d.ts → 1_tl_writer.d.ts} +5 -2
  124. package/esm/tl/1_tl_writer.d.ts.map +1 -0
  125. package/esm/tl/{2_tl_writer.js → 1_tl_writer.js} +80 -23
  126. package/esm/tl/1_tl_writer_test.d.ts.map +1 -0
  127. package/esm/tl/1_utilities.d.ts +9 -24
  128. package/esm/tl/1_utilities.d.ts.map +1 -1
  129. package/esm/tl/1_utilities.js +18 -64
  130. package/esm/tl/2_message.d.ts +2 -2
  131. package/esm/tl/2_message.d.ts.map +1 -1
  132. package/esm/tl/2_message.js +7 -7
  133. package/esm/tl/2_mtproto.d.ts +33 -0
  134. package/esm/tl/2_mtproto.d.ts.map +1 -0
  135. package/esm/tl/2_mtproto.js +53 -0
  136. package/{script/tl/2_utilities.d.ts → esm/tl/2_telegram.d.ts} +16 -2
  137. package/esm/tl/2_telegram.d.ts.map +1 -0
  138. package/esm/tl/{2_utilities.js → 2_telegram.js} +46 -1
  139. package/esm/transport/0_transport.d.ts +1 -1
  140. package/esm/transport/0_transport.d.ts.map +1 -1
  141. package/esm/types/0_chat_photo.d.ts.map +1 -1
  142. package/esm/types/0_chat_photo.js +2 -2
  143. package/esm/types/0_giveaway_parameters.d.ts.map +1 -1
  144. package/esm/types/0_giveaway_parameters.js +3 -3
  145. package/esm/types/0_location.d.ts.map +1 -1
  146. package/esm/types/0_location.js +5 -5
  147. package/esm/types/0_message_entity.d.ts.map +1 -1
  148. package/esm/types/0_message_entity.js +20 -20
  149. package/esm/types/0_reaction.d.ts.map +1 -1
  150. package/esm/types/0_reaction.js +4 -4
  151. package/esm/types/0_slow_mode_duration.d.ts +19 -0
  152. package/esm/types/0_slow_mode_duration.d.ts.map +1 -1
  153. package/esm/types/0_slow_mode_duration.js +19 -0
  154. package/esm/types/0_thumbnail.d.ts.map +1 -1
  155. package/esm/types/0_thumbnail.js +3 -3
  156. package/esm/types/0_translation.d.ts +19 -0
  157. package/esm/types/0_translation.d.ts.map +1 -1
  158. package/esm/types/0_translation.js +22 -3
  159. package/esm/types/0_video_chat.d.ts.map +1 -1
  160. package/esm/types/0_video_chat.js +2 -2
  161. package/esm/types/1_animation.d.ts.map +1 -1
  162. package/esm/types/1_animation.js +2 -2
  163. package/esm/types/1_audio.d.ts.map +1 -1
  164. package/esm/types/1_audio.js +2 -2
  165. package/esm/types/1_bot_command_scope.d.ts.map +1 -1
  166. package/esm/types/1_bot_command_scope.js +2 -2
  167. package/esm/types/1_chat_p.d.ts.map +1 -1
  168. package/esm/types/1_chat_p.js +6 -6
  169. package/esm/types/1_document.d.ts.map +1 -1
  170. package/esm/types/1_document.js +2 -2
  171. package/esm/types/1_keyboard_button.d.ts.map +1 -1
  172. package/esm/types/1_keyboard_button.js +10 -10
  173. package/esm/types/1_message_reaction.d.ts.map +1 -1
  174. package/esm/types/1_message_reaction.js +6 -6
  175. package/esm/types/1_photo.d.ts.map +1 -1
  176. package/esm/types/1_photo.js +3 -3
  177. package/esm/types/1_sticker.d.ts.map +1 -1
  178. package/esm/types/1_sticker.js +8 -8
  179. package/esm/types/1_story_privacy.d.ts.map +1 -1
  180. package/esm/types/1_story_privacy.js +7 -7
  181. package/esm/types/1_user.d.ts.map +1 -1
  182. package/esm/types/1_user.js +2 -2
  183. package/esm/types/1_venue.d.ts.map +1 -1
  184. package/esm/types/1_venue.js +2 -2
  185. package/esm/types/1_video.d.ts.map +1 -1
  186. package/esm/types/1_video.js +2 -2
  187. package/esm/types/1_video_note.d.ts.map +1 -1
  188. package/esm/types/1_video_note.js +2 -2
  189. package/esm/types/2_chat.d.ts.map +1 -1
  190. package/esm/types/2_chat.js +8 -8
  191. package/esm/types/2_chat_member.d.ts.map +1 -1
  192. package/esm/types/2_chat_member.js +10 -10
  193. package/esm/types/2_chat_settings.d.ts +19 -0
  194. package/esm/types/2_chat_settings.d.ts.map +1 -1
  195. package/esm/types/2_chat_settings.js +21 -2
  196. package/esm/types/2_chosen_inline_result.d.ts.map +1 -1
  197. package/esm/types/2_chosen_inline_result.js +4 -4
  198. package/esm/types/2_game.d.ts.map +1 -1
  199. package/esm/types/2_game.js +4 -4
  200. package/esm/types/2_gift_upgraded_component.d.ts.map +1 -1
  201. package/esm/types/2_gift_upgraded_component.js +3 -3
  202. package/esm/types/2_inactive_chat.d.ts.map +1 -1
  203. package/esm/types/2_inactive_chat.js +2 -2
  204. package/esm/types/2_inline_keyboard_button.d.ts.map +1 -1
  205. package/esm/types/2_inline_keyboard_button.js +10 -10
  206. package/esm/types/2_inline_query.d.ts.map +1 -1
  207. package/esm/types/2_inline_query.js +7 -7
  208. package/esm/types/2_message_reactions.d.ts.map +1 -1
  209. package/esm/types/2_message_reactions.js +2 -2
  210. package/esm/types/2_story_content.d.ts.map +1 -1
  211. package/esm/types/2_story_content.js +6 -6
  212. package/esm/types/2_story_interactive_area.d.ts.map +1 -1
  213. package/esm/types/2_story_interactive_area.js +9 -9
  214. package/esm/types/3_chat_member_updated.d.ts.map +1 -1
  215. package/esm/types/3_chat_member_updated.js +2 -2
  216. package/esm/types/3_gift.d.ts.map +1 -1
  217. package/esm/types/3_gift.js +3 -3
  218. package/esm/types/3_join_request.d.ts.map +1 -1
  219. package/esm/types/3_join_request.js +2 -2
  220. package/esm/types/3_reply_markup.d.ts.map +1 -1
  221. package/esm/types/3_reply_markup.js +5 -5
  222. package/esm/types/4_claimed_gift.d.ts.map +1 -1
  223. package/esm/types/4_claimed_gift.js +2 -2
  224. package/esm/types/4_inline_query_result.d.ts.map +1 -1
  225. package/esm/types/4_inline_query_result.js +14 -14
  226. package/esm/types/4_message.d.ts.map +1 -1
  227. package/esm/types/4_message.js +57 -57
  228. package/esm/types/5_callback_query.d.ts +1 -1
  229. package/esm/types/5_callback_query.d.ts.map +1 -1
  230. package/esm/types/5_callback_query.js +7 -8
  231. package/esm/types/5_chat_list_item.d.ts.map +1 -1
  232. package/esm/types/5_chat_list_item.js +5 -5
  233. package/esm/types/5_claimed_gifts.d.ts.map +1 -1
  234. package/esm/types/5_claimed_gifts.js +6 -6
  235. package/esm/types/_file_id.d.ts.map +1 -1
  236. package/esm/types/_file_id.js +3 -3
  237. package/package.json +1 -1
  238. package/script/2_tl.d.ts +6 -6
  239. package/script/2_tl.d.ts.map +1 -1
  240. package/script/2_tl.js +11 -11
  241. package/script/3_errors.d.ts +1 -2
  242. package/script/3_errors.d.ts.map +1 -1
  243. package/script/3_errors.js +2 -1
  244. package/script/4_constants.d.ts +0 -1
  245. package/script/4_constants.d.ts.map +1 -1
  246. package/script/4_constants.js +1 -2
  247. package/script/4_errors.d.ts +2 -2
  248. package/script/4_errors.d.ts.map +1 -1
  249. package/script/4_session.d.ts +24 -0
  250. package/script/4_session.d.ts.map +1 -0
  251. package/script/4_session.js +39 -0
  252. package/script/5_client.d.ts +1 -1
  253. package/script/5_client.js +1 -1
  254. package/script/client/0_client_abstract.d.ts +28 -26
  255. package/script/client/0_client_abstract.d.ts.map +1 -1
  256. package/script/client/0_client_abstract.js +18 -113
  257. package/script/client/0_params.d.ts +5 -0
  258. package/script/client/0_params.d.ts.map +1 -1
  259. package/script/client/0_password.d.ts.map +1 -1
  260. package/script/client/0_password.js +1 -1
  261. package/script/client/0_storage_operations.d.ts +4 -4
  262. package/script/client/0_storage_operations.d.ts.map +1 -1
  263. package/script/client/0_storage_operations.js +13 -13
  264. package/script/client/0_update_processor.d.ts +19 -0
  265. package/script/client/0_update_processor.d.ts.map +1 -1
  266. package/script/client/0_update_processor.js +19 -0
  267. package/script/client/0_utilities.d.ts +6 -2
  268. package/script/client/0_utilities.d.ts.map +1 -1
  269. package/script/client/0_utilities.js +22 -24
  270. package/script/client/1_client_plain.d.ts +9 -6
  271. package/script/client/1_client_plain.d.ts.map +1 -1
  272. package/script/client/1_client_plain.js +25 -40
  273. package/script/client/1_types.d.ts +4 -23
  274. package/script/client/1_types.d.ts.map +1 -1
  275. package/script/client/2_account_manager.js +9 -9
  276. package/script/client/2_business_connection_manager.d.ts.map +1 -1
  277. package/script/client/2_business_connection_manager.js +3 -3
  278. package/script/client/2_client_encrypted.d.ts +58 -0
  279. package/script/client/2_client_encrypted.d.ts.map +1 -0
  280. package/script/client/2_client_encrypted.js +269 -0
  281. package/script/client/2_file_manager.d.ts.map +1 -1
  282. package/script/client/2_file_manager.js +52 -72
  283. package/script/client/2_network_statistics_manager.d.ts +1 -1
  284. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  285. package/script/client/2_network_statistics_manager.js +3 -3
  286. package/script/client/2_payment_manager.d.ts.map +1 -1
  287. package/script/client/2_payment_manager.js +2 -2
  288. package/script/client/2_reaction_manager.d.ts.map +1 -1
  289. package/script/client/2_reaction_manager.js +9 -9
  290. package/script/client/2_translations_manager.d.ts +19 -0
  291. package/script/client/2_translations_manager.d.ts.map +1 -1
  292. package/script/client/2_translations_manager.js +23 -4
  293. package/script/client/2_update_manager.d.ts +4 -4
  294. package/script/client/2_update_manager.d.ts.map +1 -1
  295. package/script/client/2_update_manager.js +68 -78
  296. package/script/client/3_client_encrypted_pool.d.ts +30 -0
  297. package/script/client/3_client_encrypted_pool.d.ts.map +1 -0
  298. package/script/client/3_client_encrypted_pool.js +74 -0
  299. package/script/client/3_message_manager.d.ts.map +1 -1
  300. package/script/client/3_message_manager.js +99 -73
  301. package/script/client/3_video_chat_manager.d.ts.map +1 -1
  302. package/script/client/3_video_chat_manager.js +14 -19
  303. package/script/client/4_callback_query_manager.d.ts.map +1 -1
  304. package/script/client/4_callback_query_manager.js +1 -1
  305. package/script/client/4_chat_list_manager.d.ts.map +1 -1
  306. package/script/client/4_chat_list_manager.js +32 -32
  307. package/script/client/4_chat_manager.d.ts.map +1 -1
  308. package/script/client/4_chat_manager.js +24 -24
  309. package/script/client/4_gift_manager.js +1 -1
  310. package/script/client/4_inline_query_manager.d.ts.map +1 -1
  311. package/script/client/4_inline_query_manager.js +3 -3
  312. package/script/client/4_poll_manager.d.ts.map +1 -1
  313. package/script/client/4_poll_manager.js +4 -4
  314. package/script/client/4_story_manager.d.ts.map +1 -1
  315. package/script/client/4_story_manager.js +9 -9
  316. package/script/client/5_client.d.ts +3 -9
  317. package/script/client/5_client.d.ts.map +1 -1
  318. package/script/client/5_client.js +284 -300
  319. package/script/connection/0_connection.d.ts +5 -4
  320. package/script/connection/0_connection.d.ts.map +1 -1
  321. package/script/connection/1_connection_web_socket.js +2 -2
  322. package/script/mod.d.ts +1 -1
  323. package/script/mod.d.ts.map +1 -1
  324. package/script/mod.js +1 -2
  325. package/script/session/0_session_error.d.ts +24 -0
  326. package/script/session/0_session_error.d.ts.map +1 -0
  327. package/script/session/0_session_error.js +29 -0
  328. package/script/{tl/2_tl_writer.d.ts → session/0_session_state.d.ts} +7 -5
  329. package/script/session/0_session_state.d.ts.map +1 -0
  330. package/script/session/0_session_state.js +81 -0
  331. package/script/session/1_session.d.ts +31 -0
  332. package/script/session/1_session.d.ts.map +1 -0
  333. package/script/session/1_session.js +176 -0
  334. package/script/session/2_session_encrypted.d.ts +40 -0
  335. package/script/session/2_session_encrypted.d.ts.map +1 -0
  336. package/script/session/2_session_encrypted.js +420 -0
  337. package/script/session/2_session_plain.d.ts +25 -0
  338. package/script/session/2_session_plain.d.ts.map +1 -0
  339. package/script/session/2_session_plain.js +60 -0
  340. package/script/tl/0_tl_error.d.ts +22 -0
  341. package/script/tl/0_tl_error.d.ts.map +1 -0
  342. package/script/tl/0_tl_error.js +25 -0
  343. package/script/tl/0_types.d.ts +25 -0
  344. package/script/tl/0_types.d.ts.map +1 -0
  345. package/script/tl/0_types.js +21 -0
  346. package/script/tl/0_utilities.d.ts +32 -0
  347. package/script/tl/0_utilities.d.ts.map +1 -0
  348. package/script/tl/0_utilities.js +59 -0
  349. package/script/tl/0_utilities_test.d.ts.map +1 -0
  350. package/script/tl/1_mtproto_api.d.ts +371 -0
  351. package/script/tl/1_mtproto_api.d.ts.map +1 -0
  352. package/script/tl/1_mtproto_api.js +419 -0
  353. package/script/tl/{0_api.d.ts → 1_telegram_api.d.ts} +23 -340
  354. package/script/tl/1_telegram_api.d.ts.map +1 -0
  355. package/script/tl/{0_api.js → 1_telegram_api.js} +4947 -11134
  356. package/{esm/tl/0_tl_raw_reader.d.ts → script/tl/1_tl_reader.d.ts} +5 -2
  357. package/script/tl/1_tl_reader.d.ts.map +1 -0
  358. package/script/tl/1_tl_reader.js +218 -0
  359. package/script/tl/1_tl_reader_test.d.ts.map +1 -0
  360. package/script/tl/{0_tl_raw_writer.d.ts → 1_tl_writer.d.ts} +5 -2
  361. package/script/tl/1_tl_writer.d.ts.map +1 -0
  362. package/script/tl/{2_tl_writer.js → 1_tl_writer.js} +102 -45
  363. package/script/tl/1_tl_writer_test.d.ts.map +1 -0
  364. package/script/tl/1_utilities.d.ts +9 -24
  365. package/script/tl/1_utilities.d.ts.map +1 -1
  366. package/script/tl/1_utilities.js +19 -72
  367. package/script/tl/2_message.d.ts +2 -2
  368. package/script/tl/2_message.d.ts.map +1 -1
  369. package/script/tl/2_message.js +7 -7
  370. package/script/tl/2_mtproto.d.ts +33 -0
  371. package/script/tl/2_mtproto.d.ts.map +1 -0
  372. package/script/tl/2_mtproto.js +78 -0
  373. package/{esm/tl/2_utilities.d.ts → script/tl/2_telegram.d.ts} +16 -2
  374. package/script/tl/2_telegram.d.ts.map +1 -0
  375. package/script/tl/2_telegram.js +167 -0
  376. package/script/transport/0_transport.d.ts +1 -1
  377. package/script/transport/0_transport.d.ts.map +1 -1
  378. package/script/types/0_chat_photo.d.ts.map +1 -1
  379. package/script/types/0_chat_photo.js +1 -1
  380. package/script/types/0_giveaway_parameters.d.ts.map +1 -1
  381. package/script/types/0_giveaway_parameters.js +2 -2
  382. package/script/types/0_location.d.ts.map +1 -1
  383. package/script/types/0_location.js +4 -4
  384. package/script/types/0_message_entity.d.ts.map +1 -1
  385. package/script/types/0_message_entity.js +19 -19
  386. package/script/types/0_reaction.d.ts.map +1 -1
  387. package/script/types/0_reaction.js +3 -3
  388. package/script/types/0_slow_mode_duration.d.ts +19 -0
  389. package/script/types/0_slow_mode_duration.d.ts.map +1 -1
  390. package/script/types/0_slow_mode_duration.js +19 -0
  391. package/script/types/0_thumbnail.d.ts.map +1 -1
  392. package/script/types/0_thumbnail.js +2 -2
  393. package/script/types/0_translation.d.ts +19 -0
  394. package/script/types/0_translation.d.ts.map +1 -1
  395. package/script/types/0_translation.js +21 -2
  396. package/script/types/0_video_chat.d.ts.map +1 -1
  397. package/script/types/0_video_chat.js +1 -1
  398. package/script/types/1_animation.d.ts.map +1 -1
  399. package/script/types/1_animation.js +1 -1
  400. package/script/types/1_audio.d.ts.map +1 -1
  401. package/script/types/1_audio.js +1 -1
  402. package/script/types/1_bot_command_scope.d.ts.map +1 -1
  403. package/script/types/1_bot_command_scope.js +1 -1
  404. package/script/types/1_chat_p.d.ts.map +1 -1
  405. package/script/types/1_chat_p.js +5 -5
  406. package/script/types/1_document.d.ts.map +1 -1
  407. package/script/types/1_document.js +1 -1
  408. package/script/types/1_keyboard_button.d.ts.map +1 -1
  409. package/script/types/1_keyboard_button.js +9 -9
  410. package/script/types/1_message_reaction.d.ts.map +1 -1
  411. package/script/types/1_message_reaction.js +5 -5
  412. package/script/types/1_photo.d.ts.map +1 -1
  413. package/script/types/1_photo.js +2 -2
  414. package/script/types/1_sticker.d.ts.map +1 -1
  415. package/script/types/1_sticker.js +7 -7
  416. package/script/types/1_story_privacy.d.ts.map +1 -1
  417. package/script/types/1_story_privacy.js +6 -6
  418. package/script/types/1_user.d.ts.map +1 -1
  419. package/script/types/1_user.js +1 -1
  420. package/script/types/1_venue.d.ts.map +1 -1
  421. package/script/types/1_venue.js +1 -1
  422. package/script/types/1_video.d.ts.map +1 -1
  423. package/script/types/1_video.js +1 -1
  424. package/script/types/1_video_note.d.ts.map +1 -1
  425. package/script/types/1_video_note.js +1 -1
  426. package/script/types/2_chat.d.ts.map +1 -1
  427. package/script/types/2_chat.js +7 -7
  428. package/script/types/2_chat_member.d.ts.map +1 -1
  429. package/script/types/2_chat_member.js +9 -9
  430. package/script/types/2_chat_settings.d.ts +19 -0
  431. package/script/types/2_chat_settings.d.ts.map +1 -1
  432. package/script/types/2_chat_settings.js +20 -1
  433. package/script/types/2_chosen_inline_result.d.ts.map +1 -1
  434. package/script/types/2_chosen_inline_result.js +3 -3
  435. package/script/types/2_game.d.ts.map +1 -1
  436. package/script/types/2_game.js +3 -3
  437. package/script/types/2_gift_upgraded_component.d.ts.map +1 -1
  438. package/script/types/2_gift_upgraded_component.js +2 -2
  439. package/script/types/2_inactive_chat.d.ts.map +1 -1
  440. package/script/types/2_inactive_chat.js +1 -1
  441. package/script/types/2_inline_keyboard_button.d.ts.map +1 -1
  442. package/script/types/2_inline_keyboard_button.js +9 -9
  443. package/script/types/2_inline_query.d.ts.map +1 -1
  444. package/script/types/2_inline_query.js +6 -6
  445. package/script/types/2_message_reactions.d.ts.map +1 -1
  446. package/script/types/2_message_reactions.js +1 -1
  447. package/script/types/2_story_content.d.ts.map +1 -1
  448. package/script/types/2_story_content.js +5 -5
  449. package/script/types/2_story_interactive_area.d.ts.map +1 -1
  450. package/script/types/2_story_interactive_area.js +8 -8
  451. package/script/types/3_chat_member_updated.d.ts.map +1 -1
  452. package/script/types/3_chat_member_updated.js +1 -1
  453. package/script/types/3_gift.d.ts.map +1 -1
  454. package/script/types/3_gift.js +2 -2
  455. package/script/types/3_join_request.d.ts.map +1 -1
  456. package/script/types/3_join_request.js +1 -1
  457. package/script/types/3_reply_markup.d.ts.map +1 -1
  458. package/script/types/3_reply_markup.js +4 -4
  459. package/script/types/4_claimed_gift.d.ts.map +1 -1
  460. package/script/types/4_claimed_gift.js +1 -1
  461. package/script/types/4_inline_query_result.d.ts.map +1 -1
  462. package/script/types/4_inline_query_result.js +13 -13
  463. package/script/types/4_message.d.ts.map +1 -1
  464. package/script/types/4_message.js +56 -56
  465. package/script/types/5_callback_query.d.ts +1 -1
  466. package/script/types/5_callback_query.d.ts.map +1 -1
  467. package/script/types/5_callback_query.js +6 -7
  468. package/script/types/5_chat_list_item.d.ts.map +1 -1
  469. package/script/types/5_chat_list_item.js +4 -4
  470. package/script/types/5_claimed_gifts.d.ts.map +1 -1
  471. package/script/types/5_claimed_gifts.js +5 -5
  472. package/script/types/_file_id.d.ts.map +1 -1
  473. package/script/types/_file_id.js +2 -2
  474. package/esm/client/0_message.d.ts +0 -29
  475. package/esm/client/0_message.d.ts.map +0 -1
  476. package/esm/client/0_message.js +0 -83
  477. package/esm/client/1_client_encrypted.d.ts +0 -52
  478. package/esm/client/1_client_encrypted.d.ts.map +0 -1
  479. package/esm/client/1_client_encrypted.js +0 -381
  480. package/esm/tl/0_api.d.ts.map +0 -1
  481. package/esm/tl/0_tl_raw_reader.d.ts.map +0 -1
  482. package/esm/tl/0_tl_raw_reader.js +0 -97
  483. package/esm/tl/0_tl_raw_reader_test.d.ts.map +0 -1
  484. package/esm/tl/0_tl_raw_writer.d.ts.map +0 -1
  485. package/esm/tl/0_tl_raw_writer.js +0 -86
  486. package/esm/tl/0_tl_raw_writer_test.d.ts.map +0 -1
  487. package/esm/tl/1_utilities_test.d.ts.map +0 -1
  488. package/esm/tl/2_tl_reader.d.ts.map +0 -1
  489. package/esm/tl/2_tl_reader_test.d.ts.map +0 -1
  490. package/esm/tl/2_tl_writer.d.ts.map +0 -1
  491. package/esm/tl/2_tl_writer_test.d.ts.map +0 -1
  492. package/esm/tl/2_utilities.d.ts.map +0 -1
  493. package/script/client/0_message.d.ts +0 -29
  494. package/script/client/0_message.d.ts.map +0 -1
  495. package/script/client/0_message.js +0 -90
  496. package/script/client/1_client_encrypted.d.ts +0 -52
  497. package/script/client/1_client_encrypted.d.ts.map +0 -1
  498. package/script/client/1_client_encrypted.js +0 -385
  499. package/script/tl/0_api.d.ts.map +0 -1
  500. package/script/tl/0_tl_raw_reader.d.ts.map +0 -1
  501. package/script/tl/0_tl_raw_reader.js +0 -102
  502. package/script/tl/0_tl_raw_reader_test.d.ts.map +0 -1
  503. package/script/tl/0_tl_raw_writer.d.ts.map +0 -1
  504. package/script/tl/0_tl_raw_writer.js +0 -90
  505. package/script/tl/0_tl_raw_writer_test.d.ts.map +0 -1
  506. package/script/tl/1_utilities_test.d.ts.map +0 -1
  507. package/script/tl/2_tl_reader.d.ts.map +0 -1
  508. package/script/tl/2_tl_reader.js +0 -150
  509. package/script/tl/2_tl_reader_test.d.ts.map +0 -1
  510. package/script/tl/2_tl_writer.d.ts.map +0 -1
  511. package/script/tl/2_tl_writer_test.d.ts.map +0 -1
  512. package/script/tl/2_utilities.d.ts.map +0 -1
  513. package/script/tl/2_utilities.js +0 -98
@@ -28,46 +28,36 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
28
28
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
29
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
30
  };
31
- var _ClientPlain_publicKeys, _ClientPlain_lastMessageId;
31
+ var _ClientPlain_publicKeys;
32
32
  import { assert, assertEquals, concat, ige256Decrypt, ige256Encrypt, unreachable } from "../0_deps.js";
33
- import { ConnectionError, TransportError } from "../0_errors.js";
34
33
  import { bigIntFromBuffer, bufferFromBigInt, factorize, getLogger, getRandomBigInt, modExp, rsaPad, sha1 } from "../1_utilities.js";
35
- import { is, mustGetReturnType, TLReader, TLWriter } from "../2_tl.js";
34
+ import { Mtproto } from "../2_tl.js";
35
+ import { getDcId } from "../3_transport.js";
36
36
  import { PUBLIC_KEYS } from "../4_constants.js";
37
+ import { SessionPlain } from "../4_session.js";
37
38
  import { ClientAbstract } from "./0_client_abstract.js";
38
- import { getMessageId, packUnencryptedMessage, unpackUnencryptedMessage } from "./0_message.js";
39
39
  const L = getLogger("ClientPlain");
40
40
  const LcreateAuthKey = L.branch("createAuthKey");
41
41
  /**
42
42
  * An MTProto client for making plain connections. Most users won't need to interact with this. Used internally for creating authorization keys.
43
43
  */
44
44
  export class ClientPlain extends ClientAbstract {
45
- constructor(params) {
46
- super(params);
45
+ constructor(dc, params) {
46
+ super();
47
47
  _ClientPlain_publicKeys.set(this, void 0);
48
- _ClientPlain_lastMessageId.set(this, 0n);
48
+ Object.defineProperty(this, "session", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
49
54
  __classPrivateFieldSet(this, _ClientPlain_publicKeys, params?.publicKeys ?? PUBLIC_KEYS, "f");
55
+ this.session = new SessionPlain(dc, params);
50
56
  }
51
57
  async invoke(function_) {
52
- if (!this.transport) {
53
- throw new ConnectionError("Not connected.");
54
- }
55
- const messageId = __classPrivateFieldSet(this, _ClientPlain_lastMessageId, getMessageId(__classPrivateFieldGet(this, _ClientPlain_lastMessageId, "f"), 0), "f");
56
- const payload = packUnencryptedMessage(new TLWriter().serialize(function_).buffer, messageId);
57
- await this.transport.transport.send(payload);
58
- L.out(function_);
59
- L.outBin(payload);
60
- const buffer = await this.transport.transport.receive();
61
- L.inBin(payload);
62
- if (buffer.length == 4) {
63
- const int = bigIntFromBuffer(buffer, true, true);
64
- throw new TransportError(Number(int));
65
- }
66
- const { message } = unpackUnencryptedMessage(buffer);
67
- const reader = new TLReader(message);
68
- const result = await reader.deserialize(mustGetReturnType(function_._));
69
- L.in(result);
70
- return result;
58
+ await this.session.send(Mtproto.serializeObject(function_));
59
+ const body = await this.session.receive();
60
+ return await Mtproto.deserializeType(Mtproto.mustGetReturnType(function_._), body);
71
61
  }
72
62
  async createAuthKey() {
73
63
  const nonce = getRandomBigInt(16, false, true);
@@ -77,7 +67,7 @@ export class ClientPlain extends ClientAbstract {
77
67
  try {
78
68
  LcreateAuthKey.debug(`req_pq_multi [${i + 1}]`);
79
69
  resPq = await this.invoke({ _: "req_pq_multi", nonce });
80
- assert(is("resPQ", resPq));
70
+ assert(Mtproto.is("resPQ", resPq));
81
71
  assertEquals(resPq.nonce, nonce);
82
72
  LcreateAuthKey.debug("got res_pq");
83
73
  break;
@@ -109,12 +99,11 @@ export class ClientPlain extends ClientAbstract {
109
99
  if (!publicKeyFingerprint || !publicKey) {
110
100
  throw new Error("No corresponding public key found");
111
101
  }
112
- const dc = this.dcId;
102
+ const dc = getDcId(this.dc, this.cdn);
113
103
  const pq = resPq.pq;
114
104
  const serverNonce = resPq.server_nonce;
115
105
  const newNonce = getRandomBigInt(32, false, true);
116
- let encryptedData = await rsaPad(new TLWriter()
117
- .serialize({
106
+ let encryptedData = await rsaPad(Mtproto.serializeObject({
118
107
  _: "p_q_inner_data_dc",
119
108
  pq,
120
109
  p,
@@ -123,8 +112,7 @@ export class ClientPlain extends ClientAbstract {
123
112
  new_nonce: newNonce,
124
113
  nonce,
125
114
  server_nonce: serverNonce,
126
- })
127
- .buffer, publicKey);
115
+ }), publicKey);
128
116
  const dhParams = await this.invoke({
129
117
  _: "req_DH_params",
130
118
  nonce,
@@ -134,29 +122,26 @@ export class ClientPlain extends ClientAbstract {
134
122
  public_key_fingerprint: publicKeyFingerprint,
135
123
  encrypted_data: encryptedData,
136
124
  });
137
- assert(is("server_DH_params_ok", dhParams));
125
+ assert(Mtproto.is("server_DH_params_ok", dhParams));
138
126
  LcreateAuthKey.debug("got server_DH_params_ok");
139
127
  const newNonce_ = bufferFromBigInt(newNonce, 32, true, true);
140
128
  const serverNonce_ = bufferFromBigInt(serverNonce, 16, true, true);
141
129
  const tmpAesKey = concat([await sha1(concat([newNonce_, serverNonce_])), (await sha1(concat([serverNonce_, newNonce_]))).subarray(0, 0 + 12)]);
142
130
  const tmpAesIv = concat([(await sha1(concat([serverNonce_, newNonce_]))).subarray(12, 12 + 8), await sha1(concat([newNonce_, newNonce_])), newNonce_.subarray(0, 0 + 4)]);
143
131
  const answerWithHash = ige256Decrypt(dhParams.encrypted_answer, tmpAesKey, tmpAesIv);
144
- const dhInnerData = await new TLReader(answerWithHash.slice(20)).deserialize("server_DH_inner_data");
145
- assert(is("server_DH_inner_data", dhInnerData));
132
+ const dhInnerData = await Mtproto.deserializeType("server_DH_inner_data", answerWithHash.slice(20));
146
133
  const { g, g_a: gA_, dh_prime: dhPrime_ } = dhInnerData;
147
134
  const gA = bigIntFromBuffer(gA_, false, false);
148
135
  const dhPrime = bigIntFromBuffer(dhPrime_, false, false);
149
136
  const b = getRandomBigInt(256, false, false);
150
137
  const gB = modExp(BigInt(g), b, dhPrime);
151
- const data = new TLWriter()
152
- .serialize({
138
+ const data = Mtproto.serializeObject({
153
139
  _: "client_DH_inner_data",
154
140
  nonce,
155
141
  server_nonce: serverNonce,
156
142
  retry_id: 0n,
157
143
  g_b: bufferFromBigInt(gB, 256, false, false),
158
- })
159
- .buffer;
144
+ });
160
145
  let dataWithHash = concat([await sha1(data), data]);
161
146
  while (dataWithHash.length % 16 != 0) {
162
147
  dataWithHash = concat([dataWithHash, new Uint8Array(1)]);
@@ -168,7 +153,7 @@ export class ClientPlain extends ClientAbstract {
168
153
  server_nonce: serverNonce,
169
154
  encrypted_data: encryptedData,
170
155
  });
171
- assert(is("dh_gen_ok", dhGenOk));
156
+ assert(Mtproto.is("dh_gen_ok", dhGenOk));
172
157
  LcreateAuthKey.debug("got dh_gen_ok");
173
158
  const serverNonceSlice = serverNonce_.subarray(0, 8);
174
159
  const salt = newNonce_.subarray(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
@@ -178,4 +163,4 @@ export class ClientPlain extends ClientAbstract {
178
163
  return [authKey, bigIntFromBuffer(salt, true, false)];
179
164
  }
180
165
  }
181
- _ClientPlain_publicKeys = new WeakMap(), _ClientPlain_lastMessageId = new WeakMap();
166
+ _ClientPlain_publicKeys = new WeakMap();
@@ -19,25 +19,8 @@
19
19
  */
20
20
  import { Api } from "../2_tl.js";
21
21
  import { ConnectionState, EntityGetter, ID, ParseMode, Update } from "../3_types.js";
22
+ import { InvokeParams } from "./0_params.js";
22
23
  import { StorageOperations } from "./0_storage_operations.js";
23
- export type Invoke = <T extends Api.AnyFunction<P>, P extends Api.Function, R extends unknown = Api.ReturnType<Api.Functions[T["_"]]>>(function_: T, businessConnectionId?: string) => Promise<R>;
24
- interface Connection {
25
- invoke: Invoke;
26
- connect: () => Promise<void>;
27
- disconnect: () => Promise<void>;
28
- }
29
- export interface ConnectionPool extends Omit<Connection, "invoke"> {
30
- size: number;
31
- invoke: () => Invoke;
32
- connect: () => Promise<void>;
33
- disconnect: () => Promise<void>;
34
- }
35
- interface GetCdnConnection {
36
- (dcId?: number): Connection;
37
- }
38
- interface GetCdnConnectionPool {
39
- (size: number, dcId?: number): ConnectionPool;
40
- }
41
24
  export interface C {
42
25
  id: number;
43
26
  storage: StorageOperations;
@@ -53,15 +36,13 @@ export interface C {
53
36
  getEntity: EntityGetter;
54
37
  handleUpdate: (update: Update) => void;
55
38
  parseMode: ParseMode;
56
- getCdnConnection: GetCdnConnection;
57
- getCdnConnectionPool: GetCdnConnectionPool;
58
39
  outgoingMessages: "none" | "business" | "all" | null;
59
- cdn: boolean;
60
40
  dropPendingUpdates?: boolean;
61
- invoke: Invoke;
62
41
  disconnected: () => boolean;
63
42
  langPack?: string;
64
43
  langCode?: string;
44
+ invoke<T extends Api.AnyFunction<P>, P extends Api.Function, R extends unknown = Api.ReturnType<Api.Functions[T["_"]]>>(function_: T, params?: InvokeParams & {
45
+ businessConnectionId?: string;
46
+ }): Promise<R>;
65
47
  }
66
- export {};
67
48
  //# sourceMappingURL=1_types.d.ts.map
@@ -1 +1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AAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB,EAAE,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,IAAI,CAAC;IACrD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,CAAC,QAAQ,EAAE,CAAC,SAAS,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG;QAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9M"}
@@ -32,7 +32,7 @@ var _AccountManager_instances, _AccountManager_c, _AccountManager_toggleUsername
32
32
  import { unreachable } from "../0_deps.js";
33
33
  import { InputError } from "../0_errors.js";
34
34
  import { toUnixTimestamp } from "../1_utilities.js";
35
- import { chatIdToPeer, inputPeerToPeer, is } from "../2_tl.js";
35
+ import { Api } from "../2_tl.js";
36
36
  import { birthdayToTlObject, constructInactiveChat, constructUser } from "../3_types.js";
37
37
  import { canBeInputChannel, canBeInputUser, toInputChannel, toInputUser } from "./0_utilities.js";
38
38
  export class AccountManager {
@@ -52,7 +52,7 @@ export class AccountManager {
52
52
  async reorderUsernames(id, order) {
53
53
  __classPrivateFieldGet(this, _AccountManager_c, "f").storage.assertUser("reorderUsernames");
54
54
  const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(id);
55
- if (is("inputPeerSelf", peer)) {
55
+ if (Api.is("inputPeerSelf", peer)) {
56
56
  return await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.reorderUsernames", order });
57
57
  }
58
58
  else if (canBeInputUser(peer)) {
@@ -108,10 +108,10 @@ export class AccountManager {
108
108
  async getContacts() {
109
109
  __classPrivateFieldGet(this, _AccountManager_c, "f").storage.assertUser("getContacts");
110
110
  const result = await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "contacts.getContacts", hash: 0n });
111
- if (!is("contacts.contacts", result)) {
111
+ if (!Api.is("contacts.contacts", result)) {
112
112
  unreachable();
113
113
  }
114
- return result.users.map((v) => is("user", v) ? constructUser(v) : null).filter((v) => v != null);
114
+ return result.users.map((v) => Api.is("user", v) ? constructUser(v) : null).filter((v) => v != null);
115
115
  }
116
116
  async deleteContacts(userIds) {
117
117
  __classPrivateFieldGet(this, _AccountManager_c, "f").storage.assertUser("deleteContacts");
@@ -125,10 +125,10 @@ export class AccountManager {
125
125
  async addContact(userId, params) {
126
126
  __classPrivateFieldGet(this, _AccountManager_c, "f").storage.assertUser("addContact");
127
127
  const id = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputUser(userId);
128
- if (!is("inputPeerUser", id)) {
128
+ if (!Api.is("inputPeerUser", id)) {
129
129
  unreachable();
130
130
  }
131
- const user = await __classPrivateFieldGet(this, _AccountManager_c, "f").getEntity(inputPeerToPeer(id));
131
+ const user = await __classPrivateFieldGet(this, _AccountManager_c, "f").getEntity(Api.inputPeerToPeer(id));
132
132
  if (!user || !("first_name" in user)) {
133
133
  unreachable();
134
134
  }
@@ -142,8 +142,8 @@ export class AccountManager {
142
142
  __classPrivateFieldGet(this, _AccountManager_c, "f").storage.assertUser("updateProfile");
143
143
  const selfId = await __classPrivateFieldGet(this, _AccountManager_c, "f").getSelfId();
144
144
  const userFull = await __classPrivateFieldGet(this, _AccountManager_instances, "m", _AccountManager_getUserFull).call(this, selfId);
145
- const entity = await __classPrivateFieldGet(this, _AccountManager_c, "f").getEntity(chatIdToPeer(selfId));
146
- if (!is("user", entity)) {
145
+ const entity = await __classPrivateFieldGet(this, _AccountManager_c, "f").getEntity(Api.chatIdToPeer(selfId));
146
+ if (!Api.is("user", entity)) {
147
147
  unreachable();
148
148
  }
149
149
  params ??= {};
@@ -214,7 +214,7 @@ export class AccountManager {
214
214
  }
215
215
  _AccountManager_c = new WeakMap(), _AccountManager_instances = new WeakSet(), _AccountManager_toggleUsername = async function _AccountManager_toggleUsername(id, username, active) {
216
216
  const peer = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeer(id);
217
- if (is("inputPeerSelf", peer)) {
217
+ if (Api.is("inputPeerSelf", peer)) {
218
218
  await __classPrivateFieldGet(this, _AccountManager_c, "f").invoke({ _: "account.toggleUsername", username, active });
219
219
  }
220
220
  else if (canBeInputUser(peer)) {
@@ -231,7 +231,7 @@ _AccountManager_c = new WeakMap(), _AccountManager_instances = new WeakSet(), _A
231
231
  const chatId_ = await __classPrivateFieldGet(this, _AccountManager_c, "f").getInputPeerChatId(inputPeer);
232
232
  let fullChat = await __classPrivateFieldGet(this, _AccountManager_c, "f").storage.getFullChat(chatId_);
233
233
  if (fullChat != null) {
234
- if (!is("userFull", fullChat)) {
234
+ if (!Api.is("userFull", fullChat)) {
235
235
  unreachable();
236
236
  }
237
237
  return fullChat;
@@ -1 +1 @@
1
- {"version":3,"file":"2_business_connection_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_business_connection_manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,GAAG,EAAe,MAAM,YAAY,CAAC;AAC9C,OAAO,EAA+B,MAAM,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,QAAA,MAAM,gCAAgC,uCAE5B,CAAC;AAEX,KAAK,+BAA+B,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,gCAAgC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpG,qBAAa,yBAA0B,YAAW,eAAe,CAAC,+BAA+B,CAAC;;gBAGpF,CAAC,EAAE,CAAC;IAIV,qBAAqB,CAAC,EAAE,EAAE,MAAM;IAatC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,IAAI,+BAA+B;IAIxE,YAAY,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,MAAM,CAAC;CAS7E"}
1
+ {"version":3,"file":"2_business_connection_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_business_connection_manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAA+B,MAAM,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEjC,QAAA,MAAM,gCAAgC,uCAE5B,CAAC;AAEX,KAAK,+BAA+B,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,gCAAgC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpG,qBAAa,yBAA0B,YAAW,eAAe,CAAC,+BAA+B,CAAC;;gBAGpF,CAAC,EAAE,CAAC;IAIV,qBAAqB,CAAC,EAAE,EAAE,MAAM;IAatC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,IAAI,+BAA+B;IAIxE,YAAY,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,MAAM,CAAC;CAS7E"}
@@ -29,7 +29,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
29
29
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
30
  };
31
31
  var _BusinessConnectionManager_c;
32
- import { as, isOneOf } from "../2_tl.js";
32
+ import { Api } from "../2_tl.js";
33
33
  import { constructBusinessConnection } from "../3_types.js";
34
34
  const businessConnectionManagerUpdates = [
35
35
  "updateBotBusinessConnect",
@@ -43,8 +43,8 @@ export class BusinessConnectionManager {
43
43
  const connection_ = await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.getBusinessConnection(id);
44
44
  if (!connection_) {
45
45
  const connection_ = await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").invoke({ _: "account.getBotBusinessConnection", connection_id: id })
46
- .then((v) => as("updates", v))
47
- .then((v) => as("updateBotBusinessConnect", v.updates[0]).connection);
46
+ .then((v) => Api.as("updates", v))
47
+ .then((v) => Api.as("updateBotBusinessConnect", v.updates[0]).connection);
48
48
  await __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").messageStorage.setBusinessConnection(id, connection_);
49
49
  return await constructBusinessConnection(connection_, __classPrivateFieldGet(this, _BusinessConnectionManager_c, "f").getEntity);
50
50
  }
@@ -53,7 +53,7 @@ export class BusinessConnectionManager {
53
53
  }
54
54
  }
55
55
  canHandleUpdate(update) {
56
- return isOneOf(businessConnectionManagerUpdates, update);
56
+ return Api.isOneOf(businessConnectionManagerUpdates, update);
57
57
  }
58
58
  async handleUpdate(update) {
59
59
  if (update.connection.disabled) {
@@ -0,0 +1,58 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import { Api } from "../2_tl.js";
21
+ import { DC } from "../3_transport.js";
22
+ import { SessionEncrypted } from "../4_session.js";
23
+ import { ClientAbstract } from "./0_client_abstract.js";
24
+ import { ClientPlainParams } from "./1_client_plain.js";
25
+ export interface ClientEncryptedParams extends ClientPlainParams {
26
+ /** The app_version parameter to be passed to initConnection. It is recommended that this parameter is changed if users are authorized. Defaults to _MTKruto_. */
27
+ appVersion?: string;
28
+ /** The device_version parameter to be passed to initConnection. The default varies by the current runtime. */
29
+ deviceModel?: string;
30
+ /** The lang_pack parameter to be passed to initConnection. Defaults to the runtime's language or `"en"`. */
31
+ langCode?: string;
32
+ /** The lang_pack parameter to be passed to initConnection. Defaults to an empty string. */
33
+ langPack?: string;
34
+ /** The system_lang_code parameter to be passed to initConnection. Defaults to the runtime's language or `"en"`. */
35
+ systemLangCode?: string;
36
+ /** The system_version parameter to be passed to initConnection. The default varies by the current runtime. */
37
+ systemVersion?: string;
38
+ /** Whether to disable receiving updates. Defaults to `false`. */
39
+ disableUpdates?: boolean;
40
+ }
41
+ export interface ClientEncryptedHandlers {
42
+ onNewServerSalt?: (newServerSalt: bigint) => void;
43
+ onUpdate?: (update: Api.Updates | Api.Update) => void;
44
+ onDeserializationError?: () => void;
45
+ }
46
+ export declare class ClientEncrypted extends ClientAbstract {
47
+ #private;
48
+ handlers: ClientEncryptedHandlers;
49
+ session: SessionEncrypted;
50
+ constructor(dc: DC, apiId: number, params?: ClientEncryptedParams);
51
+ connect(): Promise<void>;
52
+ disconnect(): void;
53
+ get authKey(): Uint8Array;
54
+ setAuthKey(authKey: Uint8Array<ArrayBuffer>): Promise<void>;
55
+ lastRequest?: Date;
56
+ invoke<T extends Api.AnyFunction, R = T extends Api.AnyGenericFunction<infer X> ? Api.ReturnType<X> : T["_"] extends keyof Api.Functions ? Api.ReturnType<T> extends never ? Api.ReturnType<Api.Functions[T["_"]]> : never : never>(function_: T): Promise<R>;
57
+ }
58
+ //# sourceMappingURL=2_client_encrypted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"2_client_encrypted.d.ts","sourceRoot":"","sources":["../../src/client/2_client_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,GAAG,EAAc,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAe,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAKrE,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,iKAAiK;IACjK,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8GAA8G;IAC9G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mHAAmH;IACnH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8GAA8G;IAC9G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC;IACtD,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;AAQD,qBAAa,eAAgB,SAAQ,cAAc;;IAIjD,QAAQ,EAAE,uBAAuB,CAAM;IAIvC,OAAO,EAAE,gBAAgB,CAAC;gBAYd,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,qBAAqB;IAsBlD,OAAO;IAOb,UAAU;IAsCnB,IAAI,OAAO,IAAI,UAAU,CAExB;IAEK,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC;IAKjD,WAAW,CAAC,EAAE,IAAI,CAAC;IAuDb,MAAM,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAuEpQ"}
@@ -0,0 +1,265 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
+ if (kind === "m") throw new TypeError("Private method is not writable");
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
24
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
+ };
26
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
+ };
31
+ var _ClientEncrypted_instances, _a, _ClientEncrypted_SEND_MAX_TRIES, _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES, _ClientEncrypted_L, _ClientEncrypted_plain, _ClientEncrypted_pendingRequests, _ClientEncrypted_apiId, _ClientEncrypted_appVersion, _ClientEncrypted_deviceModel, _ClientEncrypted_langCode, _ClientEncrypted_langPack, _ClientEncrypted_systemLangCode, _ClientEncrypted_systemVersion, _ClientEncrypted_disableUpdates, _ClientEncrypted_createAuthKeyPromise, _ClientEncrypted_createAuthKey, _ClientEncrypted_createAuthKeyInner, _ClientEncrypted_connectionInited, _ClientEncrypted_send, _ClientEncrypted_resend, _ClientEncrypted_onUpdate, _ClientEncrypted_onNewServerSalt, _ClientEncrypted_onMessageFailed, _ClientEncrypted_onRpcError, _ClientEncrypted_onRpcResult;
32
+ import { getLogger } from "../1_utilities.js";
33
+ import { Api, X } from "../2_tl.js";
34
+ import { ConnectionNotInited } from "../3_errors.js";
35
+ import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "../4_constants.js";
36
+ import { constructTelegramError } from "../4_errors.js";
37
+ import { SessionEncrypted, SessionError } from "../4_session.js";
38
+ import { ClientAbstract } from "./0_client_abstract.js";
39
+ import { isCdnFunction, repr } from "./0_utilities.js";
40
+ import { ClientPlain } from "./1_client_plain.js";
41
+ // global ClientEncrypted ID counter for logs
42
+ let id = 0;
43
+ export class ClientEncrypted extends ClientAbstract {
44
+ constructor(dc, apiId, params) {
45
+ super();
46
+ _ClientEncrypted_instances.add(this);
47
+ Object.defineProperty(this, "handlers", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: {}
52
+ });
53
+ _ClientEncrypted_L.set(this, void 0);
54
+ _ClientEncrypted_plain.set(this, void 0);
55
+ Object.defineProperty(this, "session", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ _ClientEncrypted_pendingRequests.set(this, new Map());
62
+ _ClientEncrypted_apiId.set(this, void 0);
63
+ _ClientEncrypted_appVersion.set(this, void 0);
64
+ _ClientEncrypted_deviceModel.set(this, void 0);
65
+ _ClientEncrypted_langCode.set(this, void 0);
66
+ _ClientEncrypted_langPack.set(this, void 0);
67
+ _ClientEncrypted_systemLangCode.set(this, void 0);
68
+ _ClientEncrypted_systemVersion.set(this, void 0);
69
+ _ClientEncrypted_disableUpdates.set(this, void 0);
70
+ _ClientEncrypted_createAuthKeyPromise.set(this, void 0);
71
+ _ClientEncrypted_connectionInited.set(this, false);
72
+ Object.defineProperty(this, "lastRequest", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ __classPrivateFieldSet(this, _ClientEncrypted_L, getLogger("ClientEncrypted").client(id++), "f");
79
+ __classPrivateFieldSet(this, _ClientEncrypted_plain, new ClientPlain(dc, params), "f");
80
+ this.session = new SessionEncrypted(dc, params);
81
+ this.session.handlers.onUpdate = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onUpdate).bind(this);
82
+ this.session.handlers.onNewServerSalt = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onNewServerSalt).bind(this);
83
+ this.session.handlers.onMessageFailed = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onMessageFailed).bind(this);
84
+ this.session.handlers.onRpcError = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcError).bind(this);
85
+ this.session.handlers.onRpcResult = __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_onRpcResult).bind(this);
86
+ __classPrivateFieldSet(this, _ClientEncrypted_apiId, apiId, "f");
87
+ __classPrivateFieldSet(this, _ClientEncrypted_appVersion, params?.appVersion ?? APP_VERSION, "f");
88
+ __classPrivateFieldSet(this, _ClientEncrypted_deviceModel, params?.deviceModel ?? DEVICE_MODEL, "f");
89
+ __classPrivateFieldSet(this, _ClientEncrypted_langCode, params?.langCode ?? LANG_CODE, "f");
90
+ __classPrivateFieldSet(this, _ClientEncrypted_langPack, params?.langPack ?? LANG_PACK, "f");
91
+ __classPrivateFieldSet(this, _ClientEncrypted_systemLangCode, params?.systemLangCode ?? SYSTEM_LANG_CODE, "f");
92
+ __classPrivateFieldSet(this, _ClientEncrypted_systemVersion, params?.systemVersion ?? SYSTEM_VERSION, "f");
93
+ __classPrivateFieldSet(this, _ClientEncrypted_disableUpdates, params?.disableUpdates ?? false, "f");
94
+ }
95
+ async connect() {
96
+ if (!this.authKey.length) {
97
+ await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKey).call(this);
98
+ }
99
+ await super.connect();
100
+ }
101
+ disconnect() {
102
+ super.disconnect();
103
+ this.lastRequest = undefined;
104
+ }
105
+ get authKey() {
106
+ return this.session.authKey;
107
+ }
108
+ async setAuthKey(authKey) {
109
+ await this.session.setAuthKey(authKey);
110
+ }
111
+ async invoke(function_) {
112
+ const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, function_);
113
+ return (await new Promise((resolve, reject) => {
114
+ __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, { resolve, reject, call: function_ });
115
+ }));
116
+ }
117
+ }
118
+ _a = ClientEncrypted, _ClientEncrypted_L = new WeakMap(), _ClientEncrypted_plain = new WeakMap(), _ClientEncrypted_pendingRequests = new WeakMap(), _ClientEncrypted_apiId = new WeakMap(), _ClientEncrypted_appVersion = new WeakMap(), _ClientEncrypted_deviceModel = new WeakMap(), _ClientEncrypted_langCode = new WeakMap(), _ClientEncrypted_langPack = new WeakMap(), _ClientEncrypted_systemLangCode = new WeakMap(), _ClientEncrypted_systemVersion = new WeakMap(), _ClientEncrypted_disableUpdates = new WeakMap(), _ClientEncrypted_createAuthKeyPromise = new WeakMap(), _ClientEncrypted_connectionInited = new WeakMap(), _ClientEncrypted_instances = new WeakSet(), _ClientEncrypted_createAuthKey = function _ClientEncrypted_createAuthKey() {
119
+ return __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, __classPrivateFieldGet(this, _ClientEncrypted_createAuthKeyPromise, "f") ?? __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_createAuthKeyInner).call(this).finally(() => {
120
+ __classPrivateFieldSet(this, _ClientEncrypted_createAuthKeyPromise, undefined, "f");
121
+ }), "f");
122
+ }, _ClientEncrypted_createAuthKeyInner = async function _ClientEncrypted_createAuthKeyInner() {
123
+ let lastErr;
124
+ let errored = false;
125
+ for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES); ++i) {
126
+ try {
127
+ await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").connect();
128
+ const [authKey, serverSalt] = await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").createAuthKey();
129
+ await this.setAuthKey(authKey);
130
+ this.serverSalt = serverSalt;
131
+ errored = false;
132
+ break;
133
+ }
134
+ catch (err) {
135
+ errored = true;
136
+ lastErr = err;
137
+ if (this.disconnected) {
138
+ break;
139
+ }
140
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to create auth key:", err);
141
+ }
142
+ finally {
143
+ __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").disconnect();
144
+ }
145
+ }
146
+ if (errored) {
147
+ throw lastErr;
148
+ }
149
+ }, _ClientEncrypted_send = async function _ClientEncrypted_send(function_) {
150
+ this.lastRequest = new Date();
151
+ if (__classPrivateFieldGet(this, _ClientEncrypted_disableUpdates, "f") && !isCdnFunction(function_)) {
152
+ function_ = { _: "invokeWithoutUpdates", query: function_ };
153
+ }
154
+ if (!__classPrivateFieldGet(this, _ClientEncrypted_connectionInited, "f")) {
155
+ function_ = {
156
+ _: "initConnection",
157
+ api_id: __classPrivateFieldGet(this, _ClientEncrypted_apiId, "f"),
158
+ app_version: __classPrivateFieldGet(this, _ClientEncrypted_appVersion, "f"),
159
+ device_model: __classPrivateFieldGet(this, _ClientEncrypted_deviceModel, "f"),
160
+ lang_code: __classPrivateFieldGet(this, _ClientEncrypted_langCode, "f"),
161
+ lang_pack: __classPrivateFieldGet(this, _ClientEncrypted_langPack, "f"),
162
+ query: {
163
+ _: "invokeWithLayer",
164
+ layer: Api.LAYER,
165
+ query: function_,
166
+ },
167
+ system_lang_code: __classPrivateFieldGet(this, _ClientEncrypted_systemLangCode, "f"),
168
+ system_version: __classPrivateFieldGet(this, _ClientEncrypted_systemVersion, "f"),
169
+ };
170
+ __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, true, "f");
171
+ }
172
+ const body = Api.serializeObject(function_);
173
+ let lastErr;
174
+ for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES); ++i) {
175
+ let errored = false;
176
+ try {
177
+ return await this.session.send(body);
178
+ }
179
+ catch (err) {
180
+ errored = true;
181
+ lastErr = err;
182
+ if (this.disconnected) {
183
+ break;
184
+ }
185
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("send failed:", err);
186
+ }
187
+ finally {
188
+ if (!errored) {
189
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("invoked", repr(function_));
190
+ }
191
+ }
192
+ }
193
+ throw new Error(`Failed to invoke function after ${__classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES)} tries.`, { cause: lastErr });
194
+ }, _ClientEncrypted_resend = async function _ClientEncrypted_resend(request) {
195
+ try {
196
+ const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, request.call);
197
+ __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").set(messageId, request);
198
+ }
199
+ catch (err) {
200
+ request.reject(err);
201
+ }
202
+ }, _ClientEncrypted_onUpdate = async function _ClientEncrypted_onUpdate(body) {
203
+ let type;
204
+ try {
205
+ type = await Api.deserializeType(X, body);
206
+ }
207
+ catch (err) {
208
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize update:", err);
209
+ this.handlers.onDeserializationError?.();
210
+ return;
211
+ }
212
+ if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
213
+ this.handlers.onUpdate?.(type);
214
+ }
215
+ else {
216
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").warning("received unknown type:", repr(type));
217
+ }
218
+ }, _ClientEncrypted_onNewServerSalt = function _ClientEncrypted_onNewServerSalt(serverSalt) {
219
+ this.handlers.onNewServerSalt?.(serverSalt);
220
+ }, _ClientEncrypted_onMessageFailed = async function _ClientEncrypted_onMessageFailed(msgId, error) {
221
+ const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
222
+ if (request) {
223
+ __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
224
+ if (error instanceof SessionError) {
225
+ await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
226
+ }
227
+ else {
228
+ request.reject(error);
229
+ }
230
+ }
231
+ }, _ClientEncrypted_onRpcError = async function _ClientEncrypted_onRpcError(msgId, error) {
232
+ const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
233
+ if (request) {
234
+ __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
235
+ const reason = constructTelegramError(error, request.call);
236
+ if (reason instanceof ConnectionNotInited) {
237
+ __classPrivateFieldSet(this, _ClientEncrypted_connectionInited, false, "f");
238
+ await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
239
+ }
240
+ else {
241
+ request.reject(constructTelegramError(error, request.call));
242
+ }
243
+ }
244
+ }, _ClientEncrypted_onRpcResult = async function _ClientEncrypted_onRpcResult(msgId, body) {
245
+ const request = __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").get(msgId);
246
+ if (request) {
247
+ let type;
248
+ try {
249
+ type = await Api.deserializeType(Api.mustGetReturnType(request.call._), body);
250
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result", repr(type));
251
+ request.resolve(type);
252
+ }
253
+ catch (err) {
254
+ request.reject(err);
255
+ __classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize RPC result body:", err);
256
+ this.handlers.onDeserializationError?.();
257
+ return;
258
+ }
259
+ finally {
260
+ __classPrivateFieldGet(this, _ClientEncrypted_pendingRequests, "f").delete(msgId);
261
+ }
262
+ }
263
+ };
264
+ _ClientEncrypted_SEND_MAX_TRIES = { value: 10 };
265
+ _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES = { value: 10 };
@@ -1 +1 @@
1
- {"version":3,"file":"2_file_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,GAAG,EAAU,MAAM,YAAY,CAAC;AACzC,OAAO,EAA+C,UAAU,EAA8C,OAAO,EAAkB,MAAM,eAAe,CAAC;AAE7J,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9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