@mtkruto/node 0.69.0 → 0.70.1

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 (565) hide show
  1. package/esm/0_deps.d.ts +3 -1
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +3 -1
  4. package/esm/3_types.d.ts +35 -35
  5. package/esm/3_types.d.ts.map +1 -1
  6. package/esm/3_types.js +35 -35
  7. package/esm/_dnt.polyfills.d.ts +20 -13
  8. package/esm/_dnt.polyfills.d.ts.map +1 -1
  9. package/esm/_dnt.polyfills.js +120 -11
  10. package/esm/client/0_abortable_loop.d.ts +27 -0
  11. package/esm/client/0_abortable_loop.d.ts.map +1 -0
  12. package/esm/client/0_abortable_loop.js +49 -0
  13. package/esm/client/0_client_abstract.d.ts +1 -0
  14. package/esm/client/0_client_abstract.d.ts.map +1 -1
  15. package/esm/client/0_client_abstract.js +3 -0
  16. package/esm/client/0_filters.d.ts +9 -3
  17. package/esm/client/0_filters.d.ts.map +1 -1
  18. package/esm/client/0_filters.js +4 -1
  19. package/esm/client/0_params.d.ts +1 -1
  20. package/esm/client/0_password.d.ts +2 -2
  21. package/esm/client/0_password.d.ts.map +1 -1
  22. package/esm/client/0_storage_operations.d.ts +53 -71
  23. package/esm/client/0_storage_operations.d.ts.map +1 -1
  24. package/esm/client/0_storage_operations.js +241 -238
  25. package/esm/client/0_update_processor.d.ts +2 -2
  26. package/esm/client/0_update_processor.d.ts.map +1 -1
  27. package/esm/client/0_utilities.d.ts +2 -2
  28. package/esm/client/0_utilities.d.ts.map +1 -1
  29. package/esm/client/1_types.d.ts +2 -2
  30. package/esm/client/1_types.d.ts.map +1 -1
  31. package/esm/client/2_account_manager.js +5 -5
  32. package/esm/client/2_business_connection_manager.d.ts +1 -1
  33. package/esm/client/2_business_connection_manager.d.ts.map +1 -1
  34. package/esm/client/2_business_connection_manager.js +3 -3
  35. package/esm/client/2_client_encrypted.d.ts +1 -1
  36. package/esm/client/2_client_encrypted.d.ts.map +1 -1
  37. package/esm/client/2_client_encrypted.js +26 -23
  38. package/esm/client/2_file_manager.js +2 -2
  39. package/esm/client/2_network_statistics_manager.d.ts +2 -2
  40. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  41. package/esm/client/2_network_statistics_manager.js +30 -4
  42. package/esm/client/2_payment_manager.d.ts +1 -1
  43. package/esm/client/2_payment_manager.d.ts.map +1 -1
  44. package/esm/client/2_payment_manager.js +2 -2
  45. package/esm/client/2_reaction_manager.d.ts +1 -1
  46. package/esm/client/2_reaction_manager.d.ts.map +1 -1
  47. package/esm/client/2_reaction_manager.js +2 -2
  48. package/esm/client/2_translations_manager.d.ts +1 -1
  49. package/esm/client/2_translations_manager.d.ts.map +1 -1
  50. package/esm/client/2_translations_manager.js +15 -11
  51. package/esm/client/2_update_manager.d.ts +4 -2
  52. package/esm/client/2_update_manager.d.ts.map +1 -1
  53. package/esm/client/2_update_manager.js +62 -80
  54. package/esm/client/3_message_manager.d.ts +2 -2
  55. package/esm/client/3_message_manager.d.ts.map +1 -1
  56. package/esm/client/3_message_manager.js +5 -5
  57. package/esm/client/3_video_chat_manager.d.ts +1 -1
  58. package/esm/client/3_video_chat_manager.d.ts.map +1 -1
  59. package/esm/client/4_callback_query_manager.d.ts +1 -1
  60. package/esm/client/4_callback_query_manager.d.ts.map +1 -1
  61. package/esm/client/4_callback_query_manager.js +1 -1
  62. package/esm/client/4_chat_list_manager.d.ts +2 -3
  63. package/esm/client/4_chat_list_manager.d.ts.map +1 -1
  64. package/esm/client/4_chat_list_manager.js +10 -265
  65. package/esm/client/4_chat_manager.d.ts +2 -2
  66. package/esm/client/4_chat_manager.d.ts.map +1 -1
  67. package/esm/client/4_chat_manager.js +7 -7
  68. package/esm/client/4_gift_manager.js +3 -3
  69. package/esm/client/4_inline_query_manager.d.ts +1 -1
  70. package/esm/client/4_inline_query_manager.d.ts.map +1 -1
  71. package/esm/client/4_inline_query_manager.js +3 -3
  72. package/esm/client/4_link_preview_manager.d.ts +1 -1
  73. package/esm/client/4_link_preview_manager.d.ts.map +1 -1
  74. package/esm/client/4_link_preview_manager.js +3 -3
  75. package/esm/client/4_poll_manager.d.ts +1 -1
  76. package/esm/client/4_poll_manager.d.ts.map +1 -1
  77. package/esm/client/4_poll_manager.js +1 -1
  78. package/esm/client/4_story_manager.d.ts +1 -1
  79. package/esm/client/4_story_manager.d.ts.map +1 -1
  80. package/esm/client/4_story_manager.js +7 -7
  81. package/esm/client/5_client.d.ts +15 -9
  82. package/esm/client/5_client.d.ts.map +1 -1
  83. package/esm/client/5_client.js +420 -382
  84. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts +12 -0
  85. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts.map +1 -0
  86. package/esm/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.js +69 -0
  87. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts +112 -0
  88. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts.map +1 -0
  89. package/esm/deps/jsr.io/@std/cache/0.2.0/lru_cache.js +140 -0
  90. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts +111 -0
  91. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts.map +1 -0
  92. package/esm/deps/jsr.io/@std/cache/0.2.0/memoize.js +82 -0
  93. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts +39 -0
  94. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  95. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.js +109 -0
  96. package/esm/session/1_session.d.ts +1 -0
  97. package/esm/session/1_session.d.ts.map +1 -1
  98. package/esm/session/1_session.js +3 -0
  99. package/esm/session/2_session_encrypted.d.ts +2 -2
  100. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  101. package/esm/session/2_session_encrypted.js +198 -135
  102. package/esm/storage/0_storage.d.ts +1 -0
  103. package/esm/storage/0_storage.d.ts.map +1 -1
  104. package/esm/storage/2_storage_indexed_db.d.ts +1 -0
  105. package/esm/storage/2_storage_indexed_db.d.ts.map +1 -1
  106. package/esm/storage/2_storage_indexed_db.js +3 -0
  107. package/esm/storage/2_storage_local_storage.node.d.ts +1 -0
  108. package/esm/storage/2_storage_local_storage.node.d.ts.map +1 -1
  109. package/esm/storage/2_storage_local_storage.node.js +3 -0
  110. package/esm/storage/2_storage_memory.d.ts +1 -0
  111. package/esm/storage/2_storage_memory.d.ts.map +1 -1
  112. package/esm/storage/2_storage_memory.js +3 -0
  113. package/esm/storage/2_storage_session_storage.d.ts +1 -0
  114. package/esm/storage/2_storage_session_storage.d.ts.map +1 -1
  115. package/esm/storage/2_storage_session_storage.js +3 -0
  116. package/esm/tl/0_utilities.d.ts +1 -0
  117. package/esm/tl/0_utilities.d.ts.map +1 -1
  118. package/esm/tl/0_utilities.js +20 -1
  119. package/esm/tl/1_telegram_api.d.ts +810 -254
  120. package/esm/tl/1_telegram_api.d.ts.map +1 -1
  121. package/esm/tl/1_telegram_api.js +912 -213
  122. package/esm/tl/1_tl_reader.d.ts +2 -2
  123. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  124. package/esm/tl/1_tl_writer.d.ts +2 -2
  125. package/esm/tl/1_tl_writer.d.ts.map +1 -1
  126. package/esm/tl/2_mtproto.d.ts +1 -1
  127. package/esm/tl/2_mtproto.d.ts.map +1 -1
  128. package/esm/tl/2_telegram.d.ts +1 -1
  129. package/esm/tl/2_telegram.d.ts.map +1 -1
  130. package/esm/types/0_file_source.d.ts +1 -1
  131. package/esm/types/0_file_source.d.ts.map +1 -1
  132. package/esm/types/1_chat_p.d.ts +10 -0
  133. package/esm/types/1_chat_p.d.ts.map +1 -1
  134. package/esm/types/1_chat_p.js +4 -0
  135. package/esm/types/2_chat.d.ts +2 -5
  136. package/esm/types/2_chat.d.ts.map +1 -1
  137. package/esm/types/2_chat.js +10 -15
  138. package/esm/types/{0_message_entity.d.ts → 2_message_entity.d.ts} +3 -3
  139. package/esm/types/{0_message_entity.d.ts.map → 2_message_entity.d.ts.map} +1 -1
  140. package/esm/types/{0_message_entity.js → 2_message_entity.js} +7 -7
  141. package/esm/types/2_message_reaction_count.d.ts +2 -3
  142. package/esm/types/2_message_reaction_count.d.ts.map +1 -1
  143. package/esm/types/2_message_reaction_count.js +4 -6
  144. package/esm/types/2_poll_answer.d.ts +2 -3
  145. package/esm/types/2_poll_answer.d.ts.map +1 -1
  146. package/esm/types/2_poll_answer.js +4 -5
  147. package/esm/types/2_story_interactive_area.d.ts +2 -2
  148. package/esm/types/2_story_interactive_area.d.ts.map +1 -1
  149. package/esm/types/2_story_interactive_area.js +2 -2
  150. package/esm/types/{1_story_privacy.d.ts → 2_story_privacy.d.ts} +3 -3
  151. package/esm/types/{1_story_privacy.d.ts.map → 2_story_privacy.d.ts.map} +1 -1
  152. package/esm/types/{1_story_privacy.js → 2_story_privacy.js} +10 -10
  153. package/{script/types/1_user.d.ts → esm/types/2_user.d.ts} +5 -1
  154. package/esm/types/2_user.d.ts.map +1 -0
  155. package/esm/types/{1_user.js → 2_user.js} +24 -0
  156. package/esm/types/{2_business_connection.d.ts → 3_business_connection.d.ts} +4 -4
  157. package/esm/types/3_business_connection.d.ts.map +1 -0
  158. package/esm/types/{2_business_connection.js → 3_business_connection.js} +10 -3
  159. package/{script/types/2_chat_member.d.ts → esm/types/3_chat_member.d.ts} +6 -4
  160. package/esm/types/{2_chat_member.d.ts.map → 3_chat_member.d.ts.map} +1 -1
  161. package/esm/types/{2_chat_member.js → 3_chat_member.js} +5 -5
  162. package/esm/types/{2_chat_settings.d.ts → 3_chat_settings.d.ts} +2 -2
  163. package/{script/types/2_chat_settings.d.ts.map → esm/types/3_chat_settings.d.ts.map} +1 -1
  164. package/esm/types/{2_chat_settings.js → 3_chat_settings.js} +1 -1
  165. package/esm/types/{2_chosen_inline_result.d.ts → 3_chosen_inline_result.d.ts} +4 -4
  166. package/esm/types/3_chosen_inline_result.d.ts.map +1 -0
  167. package/esm/types/{2_chosen_inline_result.js → 3_chosen_inline_result.js} +3 -3
  168. package/esm/types/{2_forward_header.d.ts → 3_forward_header.d.ts} +4 -5
  169. package/esm/types/3_forward_header.d.ts.map +1 -0
  170. package/esm/types/{2_forward_header.js → 3_forward_header.js} +11 -12
  171. package/{script/types/2_game.d.ts → esm/types/3_game.d.ts} +2 -2
  172. package/esm/types/3_game.d.ts.map +1 -0
  173. package/esm/types/{2_gift_upgraded_component.d.ts → 3_gift_upgraded_component.d.ts} +2 -2
  174. package/esm/types/{2_gift_upgraded_component.d.ts.map → 3_gift_upgraded_component.d.ts.map} +1 -1
  175. package/esm/types/{2_gift_upgraded_component.js → 3_gift_upgraded_component.js} +1 -1
  176. package/esm/types/{2_inline_query.d.ts → 3_inline_query.d.ts} +4 -4
  177. package/esm/types/3_inline_query.d.ts.map +1 -0
  178. package/esm/types/{2_inline_query.js → 3_inline_query.js} +5 -5
  179. package/{script/types/1_input_media.d.ts → esm/types/3_input_media.d.ts} +2 -2
  180. package/esm/types/{1_input_media.d.ts.map → 3_input_media.d.ts.map} +1 -1
  181. package/{script/types/2_invite_link.d.ts → esm/types/3_invite_link.d.ts} +4 -4
  182. package/{script/types/2_invite_link.d.ts.map → esm/types/3_invite_link.d.ts.map} +1 -1
  183. package/esm/types/{2_invite_link.js → 3_invite_link.js} +5 -5
  184. package/{script/types/2_message_reactions.d.ts → esm/types/3_message_reactions.d.ts} +5 -6
  185. package/esm/types/3_message_reactions.d.ts.map +1 -0
  186. package/esm/types/{2_message_reactions.js → 3_message_reactions.js} +10 -12
  187. package/esm/types/{1_poll_option.d.ts → 3_poll_option.d.ts} +2 -2
  188. package/esm/types/{1_poll_option.d.ts.map → 3_poll_option.d.ts.map} +1 -1
  189. package/esm/types/{1_poll_option.js → 3_poll_option.js} +1 -1
  190. package/esm/types/{2_pre_checkout_query.d.ts → 3_pre_checkout_query.d.ts} +4 -4
  191. package/esm/types/3_pre_checkout_query.d.ts.map +1 -0
  192. package/esm/types/{2_pre_checkout_query.js → 3_pre_checkout_query.js} +5 -5
  193. package/{script/types/1_reply_quote.d.ts → esm/types/3_reply_quote.d.ts} +2 -2
  194. package/esm/types/{1_reply_quote.d.ts.map → 3_reply_quote.d.ts.map} +1 -1
  195. package/esm/types/{1_reply_quote.js → 3_reply_quote.js} +1 -1
  196. package/esm/types/3_story.d.ts +4 -5
  197. package/esm/types/3_story.d.ts.map +1 -1
  198. package/esm/types/3_story.js +6 -7
  199. package/esm/types/{3_chat_member_updated.d.ts → 4_chat_member_updated.d.ts} +6 -7
  200. package/esm/types/4_chat_member_updated.d.ts.map +1 -0
  201. package/esm/types/{3_chat_member_updated.js → 4_chat_member_updated.js} +13 -14
  202. package/esm/types/{3_gift.d.ts → 4_gift.d.ts} +6 -6
  203. package/esm/types/{3_gift.d.ts.map → 4_gift.d.ts.map} +1 -1
  204. package/esm/types/{3_gift.js → 4_gift.js} +7 -7
  205. package/esm/types/{3_join_request.d.ts → 4_join_request.d.ts} +6 -7
  206. package/esm/types/4_join_request.d.ts.map +1 -0
  207. package/esm/types/{3_join_request.js → 4_join_request.js} +17 -18
  208. package/esm/types/{2_poll.d.ts → 4_poll.d.ts} +3 -3
  209. package/esm/types/{2_poll.d.ts.map → 4_poll.d.ts.map} +1 -1
  210. package/esm/types/{2_poll.js → 4_poll.js} +2 -2
  211. package/{script/types/2_reply_to.d.ts → esm/types/4_reply_to.d.ts} +2 -2
  212. package/esm/types/{2_reply_to.d.ts.map → 4_reply_to.d.ts.map} +1 -1
  213. package/esm/types/{4_claimed_gift.d.ts → 5_claimed_gift.d.ts} +5 -6
  214. package/esm/types/5_claimed_gift.d.ts.map +1 -0
  215. package/esm/types/{4_claimed_gift.js → 5_claimed_gift.js} +4 -4
  216. package/esm/types/{4_link_preview.d.ts → 5_link_preview.d.ts} +4 -4
  217. package/{script/types/4_link_preview.d.ts.map → esm/types/5_link_preview.d.ts.map} +1 -1
  218. package/esm/types/{4_link_preview.js → 5_link_preview.js} +3 -3
  219. package/esm/types/{5_claimed_gifts.d.ts → 6_claimed_gifts.d.ts} +4 -4
  220. package/esm/types/6_claimed_gifts.d.ts.map +1 -0
  221. package/esm/types/{5_claimed_gifts.js → 6_claimed_gifts.js} +4 -4
  222. package/esm/types/{5_message.d.ts → 6_message.d.ts} +10 -11
  223. package/esm/types/6_message.d.ts.map +1 -0
  224. package/esm/types/{5_message.js → 6_message.js} +41 -66
  225. package/{script/types/5_message_content.d.ts → esm/types/6_message_content.d.ts} +3 -3
  226. package/esm/types/{5_message_content.d.ts.map → 6_message_content.d.ts.map} +1 -1
  227. package/{script/types/6_callback_query.d.ts → esm/types/7_callback_query.d.ts} +5 -5
  228. package/esm/types/{6_callback_query.d.ts.map → 7_callback_query.d.ts.map} +1 -1
  229. package/esm/types/{6_callback_query.js → 7_callback_query.js} +5 -5
  230. package/{script/types/6_chat_list_item.d.ts → esm/types/7_chat_list_item.d.ts} +6 -7
  231. package/esm/types/7_chat_list_item.d.ts.map +1 -0
  232. package/esm/types/{6_chat_list_item.js → 7_chat_list_item.js} +11 -11
  233. package/{script/types/6_inline_query_result.d.ts → esm/types/7_inline_query_result.d.ts} +3 -3
  234. package/esm/types/{6_inline_query_result.d.ts.map → 7_inline_query_result.d.ts.map} +1 -1
  235. package/esm/types/{6_inline_query_result.js → 7_inline_query_result.js} +1 -1
  236. package/esm/types/{6_saved_chat.d.ts → 7_saved_chat.d.ts} +4 -5
  237. package/esm/types/7_saved_chat.d.ts.map +1 -0
  238. package/esm/types/{6_saved_chat.js → 7_saved_chat.js} +4 -4
  239. package/esm/types/{6_topic.d.ts → 7_topic.d.ts} +2 -2
  240. package/esm/types/{6_topic.d.ts.map → 7_topic.d.ts.map} +1 -1
  241. package/esm/types/{7_inline_query_answer.d.ts → 8_inline_query_answer.d.ts} +2 -2
  242. package/esm/types/{7_inline_query_answer.d.ts.map → 8_inline_query_answer.d.ts.map} +1 -1
  243. package/esm/types/{7_inline_query_answer.js → 8_inline_query_answer.js} +1 -1
  244. package/{script/types/7_saved_chats.d.ts → esm/types/8_saved_chats.d.ts} +5 -5
  245. package/esm/types/8_saved_chats.d.ts.map +1 -0
  246. package/esm/types/{7_saved_chats.js → 8_saved_chats.js} +3 -3
  247. package/esm/types/{7_update.d.ts → 8_update.d.ts} +35 -16
  248. package/esm/types/8_update.d.ts.map +1 -0
  249. package/esm/types/_file_id.d.ts +1 -1
  250. package/esm/types/_file_id.d.ts.map +1 -1
  251. package/esm/types/_getters.d.ts +0 -7
  252. package/esm/types/_getters.d.ts.map +1 -1
  253. package/esm/utilities/0_hash.d.ts +2 -2
  254. package/esm/utilities/0_hash.d.ts.map +1 -1
  255. package/esm/utilities/0_misc.d.ts +1 -0
  256. package/esm/utilities/0_misc.d.ts.map +1 -1
  257. package/esm/utilities/0_misc.js +14 -1
  258. package/esm/utilities/0_part_stream.d.ts +1 -1
  259. package/esm/utilities/0_part_stream.d.ts.map +1 -1
  260. package/package.json +1 -1
  261. package/script/0_deps.d.ts +3 -1
  262. package/script/0_deps.d.ts.map +1 -1
  263. package/script/0_deps.js +6 -1
  264. package/script/3_types.d.ts +35 -35
  265. package/script/3_types.d.ts.map +1 -1
  266. package/script/3_types.js +35 -35
  267. package/script/_dnt.polyfills.d.ts +20 -13
  268. package/script/_dnt.polyfills.d.ts.map +1 -1
  269. package/script/_dnt.polyfills.js +120 -11
  270. package/script/client/0_abortable_loop.d.ts +27 -0
  271. package/script/client/0_abortable_loop.d.ts.map +1 -0
  272. package/script/client/0_abortable_loop.js +53 -0
  273. package/script/client/0_client_abstract.d.ts +1 -0
  274. package/script/client/0_client_abstract.d.ts.map +1 -1
  275. package/script/client/0_client_abstract.js +3 -0
  276. package/script/client/0_filters.d.ts +9 -3
  277. package/script/client/0_filters.d.ts.map +1 -1
  278. package/script/client/0_filters.js +4 -1
  279. package/script/client/0_params.d.ts +1 -1
  280. package/script/client/0_password.d.ts +2 -2
  281. package/script/client/0_password.d.ts.map +1 -1
  282. package/script/client/0_storage_operations.d.ts +53 -71
  283. package/script/client/0_storage_operations.d.ts.map +1 -1
  284. package/script/client/0_storage_operations.js +239 -236
  285. package/script/client/0_update_processor.d.ts +2 -2
  286. package/script/client/0_update_processor.d.ts.map +1 -1
  287. package/script/client/0_utilities.d.ts +2 -2
  288. package/script/client/0_utilities.d.ts.map +1 -1
  289. package/script/client/1_types.d.ts +2 -2
  290. package/script/client/1_types.d.ts.map +1 -1
  291. package/script/client/2_account_manager.js +5 -5
  292. package/script/client/2_business_connection_manager.d.ts +1 -1
  293. package/script/client/2_business_connection_manager.d.ts.map +1 -1
  294. package/script/client/2_business_connection_manager.js +3 -3
  295. package/script/client/2_client_encrypted.d.ts +1 -1
  296. package/script/client/2_client_encrypted.d.ts.map +1 -1
  297. package/script/client/2_client_encrypted.js +26 -23
  298. package/script/client/2_file_manager.js +2 -2
  299. package/script/client/2_network_statistics_manager.d.ts +2 -2
  300. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  301. package/script/client/2_network_statistics_manager.js +30 -4
  302. package/script/client/2_payment_manager.d.ts +1 -1
  303. package/script/client/2_payment_manager.d.ts.map +1 -1
  304. package/script/client/2_payment_manager.js +2 -2
  305. package/script/client/2_reaction_manager.d.ts +1 -1
  306. package/script/client/2_reaction_manager.d.ts.map +1 -1
  307. package/script/client/2_reaction_manager.js +2 -2
  308. package/script/client/2_translations_manager.d.ts +1 -1
  309. package/script/client/2_translations_manager.d.ts.map +1 -1
  310. package/script/client/2_translations_manager.js +15 -11
  311. package/script/client/2_update_manager.d.ts +4 -2
  312. package/script/client/2_update_manager.d.ts.map +1 -1
  313. package/script/client/2_update_manager.js +62 -80
  314. package/script/client/3_message_manager.d.ts +2 -2
  315. package/script/client/3_message_manager.d.ts.map +1 -1
  316. package/script/client/3_message_manager.js +5 -5
  317. package/script/client/3_video_chat_manager.d.ts +1 -1
  318. package/script/client/3_video_chat_manager.d.ts.map +1 -1
  319. package/script/client/4_callback_query_manager.d.ts +1 -1
  320. package/script/client/4_callback_query_manager.d.ts.map +1 -1
  321. package/script/client/4_callback_query_manager.js +1 -1
  322. package/script/client/4_chat_list_manager.d.ts +2 -3
  323. package/script/client/4_chat_list_manager.d.ts.map +1 -1
  324. package/script/client/4_chat_list_manager.js +9 -264
  325. package/script/client/4_chat_manager.d.ts +2 -2
  326. package/script/client/4_chat_manager.d.ts.map +1 -1
  327. package/script/client/4_chat_manager.js +7 -7
  328. package/script/client/4_gift_manager.js +3 -3
  329. package/script/client/4_inline_query_manager.d.ts +1 -1
  330. package/script/client/4_inline_query_manager.d.ts.map +1 -1
  331. package/script/client/4_inline_query_manager.js +3 -3
  332. package/script/client/4_link_preview_manager.d.ts +1 -1
  333. package/script/client/4_link_preview_manager.d.ts.map +1 -1
  334. package/script/client/4_link_preview_manager.js +3 -3
  335. package/script/client/4_poll_manager.d.ts +1 -1
  336. package/script/client/4_poll_manager.d.ts.map +1 -1
  337. package/script/client/4_poll_manager.js +1 -1
  338. package/script/client/4_story_manager.d.ts +1 -1
  339. package/script/client/4_story_manager.d.ts.map +1 -1
  340. package/script/client/4_story_manager.js +7 -7
  341. package/script/client/5_client.d.ts +15 -9
  342. package/script/client/5_client.d.ts.map +1 -1
  343. package/script/client/5_client.js +418 -380
  344. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts +12 -0
  345. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.d.ts.map +1 -0
  346. package/script/deps/jsr.io/@std/cache/0.2.0/_serialize_arg_list.js +72 -0
  347. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts +112 -0
  348. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.d.ts.map +1 -0
  349. package/script/deps/jsr.io/@std/cache/0.2.0/lru_cache.js +144 -0
  350. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts +111 -0
  351. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.d.ts.map +1 -0
  352. package/script/deps/jsr.io/@std/cache/0.2.0/memoize.js +85 -0
  353. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts +39 -0
  354. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  355. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +113 -0
  356. package/script/session/1_session.d.ts +1 -0
  357. package/script/session/1_session.d.ts.map +1 -1
  358. package/script/session/1_session.js +3 -0
  359. package/script/session/2_session_encrypted.d.ts +2 -2
  360. package/script/session/2_session_encrypted.d.ts.map +1 -1
  361. package/script/session/2_session_encrypted.js +197 -134
  362. package/script/storage/0_storage.d.ts +1 -0
  363. package/script/storage/0_storage.d.ts.map +1 -1
  364. package/script/storage/2_storage_indexed_db.d.ts +1 -0
  365. package/script/storage/2_storage_indexed_db.d.ts.map +1 -1
  366. package/script/storage/2_storage_indexed_db.js +3 -0
  367. package/script/storage/2_storage_local_storage.node.d.ts +1 -0
  368. package/script/storage/2_storage_local_storage.node.d.ts.map +1 -1
  369. package/script/storage/2_storage_local_storage.node.js +3 -0
  370. package/script/storage/2_storage_memory.d.ts +1 -0
  371. package/script/storage/2_storage_memory.d.ts.map +1 -1
  372. package/script/storage/2_storage_memory.js +3 -0
  373. package/script/storage/2_storage_session_storage.d.ts +1 -0
  374. package/script/storage/2_storage_session_storage.d.ts.map +1 -1
  375. package/script/storage/2_storage_session_storage.js +3 -0
  376. package/script/tl/0_utilities.d.ts +1 -0
  377. package/script/tl/0_utilities.d.ts.map +1 -1
  378. package/script/tl/0_utilities.js +20 -0
  379. package/script/tl/1_telegram_api.d.ts +810 -254
  380. package/script/tl/1_telegram_api.d.ts.map +1 -1
  381. package/script/tl/1_telegram_api.js +912 -213
  382. package/script/tl/1_tl_reader.d.ts +2 -2
  383. package/script/tl/1_tl_reader.d.ts.map +1 -1
  384. package/script/tl/1_tl_writer.d.ts +2 -2
  385. package/script/tl/1_tl_writer.d.ts.map +1 -1
  386. package/script/tl/2_mtproto.d.ts +1 -1
  387. package/script/tl/2_mtproto.d.ts.map +1 -1
  388. package/script/tl/2_telegram.d.ts +1 -1
  389. package/script/tl/2_telegram.d.ts.map +1 -1
  390. package/script/types/0_file_source.d.ts +1 -1
  391. package/script/types/0_file_source.d.ts.map +1 -1
  392. package/script/types/1_chat_p.d.ts +10 -0
  393. package/script/types/1_chat_p.d.ts.map +1 -1
  394. package/script/types/1_chat_p.js +5 -0
  395. package/script/types/2_chat.d.ts +2 -5
  396. package/script/types/2_chat.d.ts.map +1 -1
  397. package/script/types/2_chat.js +10 -15
  398. package/script/types/{0_message_entity.d.ts → 2_message_entity.d.ts} +3 -3
  399. package/script/types/{0_message_entity.d.ts.map → 2_message_entity.d.ts.map} +1 -1
  400. package/script/types/{0_message_entity.js → 2_message_entity.js} +7 -7
  401. package/script/types/2_message_reaction_count.d.ts +2 -3
  402. package/script/types/2_message_reaction_count.d.ts.map +1 -1
  403. package/script/types/2_message_reaction_count.js +4 -6
  404. package/script/types/2_poll_answer.d.ts +2 -3
  405. package/script/types/2_poll_answer.d.ts.map +1 -1
  406. package/script/types/2_poll_answer.js +4 -5
  407. package/script/types/2_story_interactive_area.d.ts +2 -2
  408. package/script/types/2_story_interactive_area.d.ts.map +1 -1
  409. package/script/types/2_story_interactive_area.js +2 -2
  410. package/script/types/{1_story_privacy.d.ts → 2_story_privacy.d.ts} +3 -3
  411. package/script/types/{1_story_privacy.d.ts.map → 2_story_privacy.d.ts.map} +1 -1
  412. package/script/types/{1_story_privacy.js → 2_story_privacy.js} +10 -10
  413. package/{esm/types/1_user.d.ts → script/types/2_user.d.ts} +5 -1
  414. package/script/types/2_user.d.ts.map +1 -0
  415. package/script/types/{1_user.js → 2_user.js} +25 -0
  416. package/script/types/{2_business_connection.d.ts → 3_business_connection.d.ts} +4 -4
  417. package/script/types/3_business_connection.d.ts.map +1 -0
  418. package/script/types/{2_business_connection.js → 3_business_connection.js} +10 -3
  419. package/{esm/types/2_chat_member.d.ts → script/types/3_chat_member.d.ts} +6 -4
  420. package/script/types/{2_chat_member.d.ts.map → 3_chat_member.d.ts.map} +1 -1
  421. package/script/types/{2_chat_member.js → 3_chat_member.js} +5 -5
  422. package/script/types/{2_chat_settings.d.ts → 3_chat_settings.d.ts} +2 -2
  423. package/{esm/types/2_chat_settings.d.ts.map → script/types/3_chat_settings.d.ts.map} +1 -1
  424. package/script/types/{2_chat_settings.js → 3_chat_settings.js} +2 -2
  425. package/script/types/{2_chosen_inline_result.d.ts → 3_chosen_inline_result.d.ts} +4 -4
  426. package/script/types/3_chosen_inline_result.d.ts.map +1 -0
  427. package/script/types/{2_chosen_inline_result.js → 3_chosen_inline_result.js} +4 -4
  428. package/script/types/{2_forward_header.d.ts → 3_forward_header.d.ts} +4 -5
  429. package/script/types/3_forward_header.d.ts.map +1 -0
  430. package/script/types/{2_forward_header.js → 3_forward_header.js} +11 -12
  431. package/{esm/types/2_game.d.ts → script/types/3_game.d.ts} +2 -2
  432. package/script/types/3_game.d.ts.map +1 -0
  433. package/script/types/{2_gift_upgraded_component.d.ts → 3_gift_upgraded_component.d.ts} +2 -2
  434. package/script/types/{2_gift_upgraded_component.d.ts.map → 3_gift_upgraded_component.d.ts.map} +1 -1
  435. package/script/types/{2_gift_upgraded_component.js → 3_gift_upgraded_component.js} +2 -2
  436. package/script/types/{2_inline_query.d.ts → 3_inline_query.d.ts} +4 -4
  437. package/script/types/3_inline_query.d.ts.map +1 -0
  438. package/script/types/{2_inline_query.js → 3_inline_query.js} +5 -5
  439. package/{esm/types/1_input_media.d.ts → script/types/3_input_media.d.ts} +2 -2
  440. package/script/types/{1_input_media.d.ts.map → 3_input_media.d.ts.map} +1 -1
  441. package/{esm/types/2_invite_link.d.ts → script/types/3_invite_link.d.ts} +4 -4
  442. package/{esm/types/2_invite_link.d.ts.map → script/types/3_invite_link.d.ts.map} +1 -1
  443. package/script/types/{2_invite_link.js → 3_invite_link.js} +5 -5
  444. package/{esm/types/2_message_reactions.d.ts → script/types/3_message_reactions.d.ts} +5 -6
  445. package/script/types/3_message_reactions.d.ts.map +1 -0
  446. package/script/types/{2_message_reactions.js → 3_message_reactions.js} +10 -12
  447. package/script/types/{1_poll_option.d.ts → 3_poll_option.d.ts} +2 -2
  448. package/script/types/{1_poll_option.d.ts.map → 3_poll_option.d.ts.map} +1 -1
  449. package/script/types/{1_poll_option.js → 3_poll_option.js} +2 -2
  450. package/script/types/{2_pre_checkout_query.d.ts → 3_pre_checkout_query.d.ts} +4 -4
  451. package/script/types/3_pre_checkout_query.d.ts.map +1 -0
  452. package/script/types/{2_pre_checkout_query.js → 3_pre_checkout_query.js} +5 -5
  453. package/{esm/types/1_reply_quote.d.ts → script/types/3_reply_quote.d.ts} +2 -2
  454. package/script/types/{1_reply_quote.d.ts.map → 3_reply_quote.d.ts.map} +1 -1
  455. package/script/types/{1_reply_quote.js → 3_reply_quote.js} +2 -2
  456. package/script/types/3_story.d.ts +4 -5
  457. package/script/types/3_story.d.ts.map +1 -1
  458. package/script/types/3_story.js +8 -9
  459. package/script/types/{3_chat_member_updated.d.ts → 4_chat_member_updated.d.ts} +6 -7
  460. package/script/types/4_chat_member_updated.d.ts.map +1 -0
  461. package/script/types/{3_chat_member_updated.js → 4_chat_member_updated.js} +13 -14
  462. package/script/types/{3_gift.d.ts → 4_gift.d.ts} +6 -6
  463. package/script/types/{3_gift.d.ts.map → 4_gift.d.ts.map} +1 -1
  464. package/script/types/{3_gift.js → 4_gift.js} +9 -9
  465. package/script/types/{3_join_request.d.ts → 4_join_request.d.ts} +6 -7
  466. package/script/types/4_join_request.d.ts.map +1 -0
  467. package/script/types/{3_join_request.js → 4_join_request.js} +17 -18
  468. package/script/types/{2_poll.d.ts → 4_poll.d.ts} +3 -3
  469. package/script/types/{2_poll.d.ts.map → 4_poll.d.ts.map} +1 -1
  470. package/script/types/{2_poll.js → 4_poll.js} +5 -5
  471. package/{esm/types/2_reply_to.d.ts → script/types/4_reply_to.d.ts} +2 -2
  472. package/script/types/{2_reply_to.d.ts.map → 4_reply_to.d.ts.map} +1 -1
  473. package/script/types/{4_claimed_gift.d.ts → 5_claimed_gift.d.ts} +5 -6
  474. package/script/types/5_claimed_gift.d.ts.map +1 -0
  475. package/script/types/{4_claimed_gift.js → 5_claimed_gift.js} +5 -5
  476. package/script/types/{4_link_preview.d.ts → 5_link_preview.d.ts} +4 -4
  477. package/{esm/types/4_link_preview.d.ts.map → script/types/5_link_preview.d.ts.map} +1 -1
  478. package/script/types/{4_link_preview.js → 5_link_preview.js} +3 -3
  479. package/script/types/{5_claimed_gifts.d.ts → 6_claimed_gifts.d.ts} +4 -4
  480. package/script/types/6_claimed_gifts.d.ts.map +1 -0
  481. package/script/types/{5_claimed_gifts.js → 6_claimed_gifts.js} +4 -4
  482. package/script/types/{5_message.d.ts → 6_message.d.ts} +10 -11
  483. package/script/types/6_message.d.ts.map +1 -0
  484. package/script/types/{5_message.js → 6_message.js} +45 -70
  485. package/{esm/types/5_message_content.d.ts → script/types/6_message_content.d.ts} +3 -3
  486. package/script/types/{5_message_content.d.ts.map → 6_message_content.d.ts.map} +1 -1
  487. package/{esm/types/6_callback_query.d.ts → script/types/7_callback_query.d.ts} +5 -5
  488. package/script/types/{6_callback_query.d.ts.map → 7_callback_query.d.ts.map} +1 -1
  489. package/script/types/{6_callback_query.js → 7_callback_query.js} +5 -5
  490. package/{esm/types/6_chat_list_item.d.ts → script/types/7_chat_list_item.d.ts} +6 -7
  491. package/script/types/7_chat_list_item.d.ts.map +1 -0
  492. package/script/types/{6_chat_list_item.js → 7_chat_list_item.js} +11 -11
  493. package/{esm/types/6_inline_query_result.d.ts → script/types/7_inline_query_result.d.ts} +3 -3
  494. package/script/types/{6_inline_query_result.d.ts.map → 7_inline_query_result.d.ts.map} +1 -1
  495. package/script/types/{6_inline_query_result.js → 7_inline_query_result.js} +3 -3
  496. package/script/types/{6_saved_chat.d.ts → 7_saved_chat.d.ts} +4 -5
  497. package/script/types/7_saved_chat.d.ts.map +1 -0
  498. package/script/types/{6_saved_chat.js → 7_saved_chat.js} +4 -4
  499. package/script/types/{6_topic.d.ts → 7_topic.d.ts} +2 -2
  500. package/script/types/{6_topic.d.ts.map → 7_topic.d.ts.map} +1 -1
  501. package/script/types/{7_inline_query_answer.d.ts → 8_inline_query_answer.d.ts} +2 -2
  502. package/script/types/{7_inline_query_answer.d.ts.map → 8_inline_query_answer.d.ts.map} +1 -1
  503. package/script/types/{7_inline_query_answer.js → 8_inline_query_answer.js} +2 -2
  504. package/{esm/types/7_saved_chats.d.ts → script/types/8_saved_chats.d.ts} +5 -5
  505. package/script/types/8_saved_chats.d.ts.map +1 -0
  506. package/script/types/{7_saved_chats.js → 8_saved_chats.js} +3 -3
  507. package/script/types/{7_update.d.ts → 8_update.d.ts} +35 -16
  508. package/script/types/8_update.d.ts.map +1 -0
  509. package/script/types/_file_id.d.ts +1 -1
  510. package/script/types/_file_id.d.ts.map +1 -1
  511. package/script/types/_getters.d.ts +0 -7
  512. package/script/types/_getters.d.ts.map +1 -1
  513. package/script/utilities/0_hash.d.ts +2 -2
  514. package/script/utilities/0_hash.d.ts.map +1 -1
  515. package/script/utilities/0_misc.d.ts +1 -0
  516. package/script/utilities/0_misc.d.ts.map +1 -1
  517. package/script/utilities/0_misc.js +14 -0
  518. package/script/utilities/0_part_stream.d.ts +1 -1
  519. package/script/utilities/0_part_stream.d.ts.map +1 -1
  520. package/esm/types/1_user.d.ts.map +0 -1
  521. package/esm/types/2_business_connection.d.ts.map +0 -1
  522. package/esm/types/2_chosen_inline_result.d.ts.map +0 -1
  523. package/esm/types/2_forward_header.d.ts.map +0 -1
  524. package/esm/types/2_game.d.ts.map +0 -1
  525. package/esm/types/2_inline_query.d.ts.map +0 -1
  526. package/esm/types/2_message_reactions.d.ts.map +0 -1
  527. package/esm/types/2_pre_checkout_query.d.ts.map +0 -1
  528. package/esm/types/3_chat_member_updated.d.ts.map +0 -1
  529. package/esm/types/3_join_request.d.ts.map +0 -1
  530. package/esm/types/4_claimed_gift.d.ts.map +0 -1
  531. package/esm/types/5_claimed_gifts.d.ts.map +0 -1
  532. package/esm/types/5_message.d.ts.map +0 -1
  533. package/esm/types/6_chat_list_item.d.ts.map +0 -1
  534. package/esm/types/6_saved_chat.d.ts.map +0 -1
  535. package/esm/types/7_saved_chats.d.ts.map +0 -1
  536. package/esm/types/7_update.d.ts.map +0 -1
  537. package/script/types/1_user.d.ts.map +0 -1
  538. package/script/types/2_business_connection.d.ts.map +0 -1
  539. package/script/types/2_chosen_inline_result.d.ts.map +0 -1
  540. package/script/types/2_forward_header.d.ts.map +0 -1
  541. package/script/types/2_game.d.ts.map +0 -1
  542. package/script/types/2_inline_query.d.ts.map +0 -1
  543. package/script/types/2_message_reactions.d.ts.map +0 -1
  544. package/script/types/2_pre_checkout_query.d.ts.map +0 -1
  545. package/script/types/3_chat_member_updated.d.ts.map +0 -1
  546. package/script/types/3_join_request.d.ts.map +0 -1
  547. package/script/types/4_claimed_gift.d.ts.map +0 -1
  548. package/script/types/5_claimed_gifts.d.ts.map +0 -1
  549. package/script/types/5_message.d.ts.map +0 -1
  550. package/script/types/6_chat_list_item.d.ts.map +0 -1
  551. package/script/types/6_saved_chat.d.ts.map +0 -1
  552. package/script/types/7_saved_chats.d.ts.map +0 -1
  553. package/script/types/7_update.d.ts.map +0 -1
  554. /package/esm/types/{2_game.js → 3_game.js} +0 -0
  555. /package/esm/types/{1_input_media.js → 3_input_media.js} +0 -0
  556. /package/esm/types/{2_reply_to.js → 4_reply_to.js} +0 -0
  557. /package/esm/types/{5_message_content.js → 6_message_content.js} +0 -0
  558. /package/esm/types/{6_topic.js → 7_topic.js} +0 -0
  559. /package/esm/types/{7_update.js → 8_update.js} +0 -0
  560. /package/script/types/{2_game.js → 3_game.js} +0 -0
  561. /package/script/types/{1_input_media.js → 3_input_media.js} +0 -0
  562. /package/script/types/{2_reply_to.js → 4_reply_to.js} +0 -0
  563. /package/script/types/{5_message_content.js → 6_message_content.js} +0 -0
  564. /package/script/types/{6_topic.js → 7_topic.js} +0 -0
  565. /package/script/types/{7_update.js → 8_update.js} +0 -0
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ // Copyright 2009 The Go Authors. All rights reserved.
3
+ // https://github.com/golang/go/blob/master/LICENSE
4
+ // Copyright 2018-2025 the Deno authors. MIT license.
5
+ // This module is browser compatible.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.encodeHex = encodeHex;
8
+ exports.decodeHex = decodeHex;
9
+ /**
10
+ * Port of the Go
11
+ * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
12
+ * library.
13
+ *
14
+ * ```ts
15
+ * import {
16
+ * decodeHex,
17
+ * encodeHex,
18
+ * } from "@std/encoding/hex";
19
+ * import { assertEquals } from "@std/assert";
20
+ *
21
+ * assertEquals(encodeHex("abc"), "616263");
22
+ *
23
+ * assertEquals(
24
+ * decodeHex("616263"),
25
+ * new TextEncoder().encode("abc"),
26
+ * );
27
+ * ```
28
+ *
29
+ * @module
30
+ */
31
+ const _validate_binary_like_js_1 = require("./_validate_binary_like.js");
32
+ const hexTable = new TextEncoder().encode("0123456789abcdef");
33
+ const textEncoder = new TextEncoder();
34
+ const textDecoder = new TextDecoder();
35
+ function errInvalidByte(byte) {
36
+ return new TypeError(`Invalid byte '${String.fromCharCode(byte)}'`);
37
+ }
38
+ function errLength(len) {
39
+ return new RangeError(`Cannot decode the hex string as the input length should be even: length is ${len}`);
40
+ }
41
+ /** Converts a hex character into its value. */
42
+ function fromHexChar(byte) {
43
+ // '0' <= byte && byte <= '9'
44
+ if (48 <= byte && byte <= 57)
45
+ return byte - 48;
46
+ // 'a' <= byte && byte <= 'f'
47
+ if (97 <= byte && byte <= 102)
48
+ return byte - 97 + 10;
49
+ // 'A' <= byte && byte <= 'F'
50
+ if (65 <= byte && byte <= 70)
51
+ return byte - 65 + 10;
52
+ throw errInvalidByte(byte);
53
+ }
54
+ /**
55
+ * Converts data into a hex-encoded string.
56
+ *
57
+ * @param src The data to encode.
58
+ *
59
+ * @returns The hex-encoded string.
60
+ *
61
+ * @example Usage
62
+ * ```ts
63
+ * import { encodeHex } from "@std/encoding/hex";
64
+ * import { assertEquals } from "@std/assert";
65
+ *
66
+ * assertEquals(encodeHex("abc"), "616263");
67
+ * ```
68
+ */
69
+ function encodeHex(src) {
70
+ const u8 = (0, _validate_binary_like_js_1.validateBinaryLike)(src);
71
+ const dst = new Uint8Array(u8.length * 2);
72
+ for (let i = 0; i < u8.length; i++) {
73
+ const v = u8[i];
74
+ dst[i * 2] = hexTable[v >> 4];
75
+ dst[i * 2 + 1] = hexTable[v & 0x0f];
76
+ }
77
+ return textDecoder.decode(dst);
78
+ }
79
+ /**
80
+ * Decodes the given hex-encoded string. If the input is malformed, an error is
81
+ * thrown.
82
+ *
83
+ * @param src The hex-encoded string to decode.
84
+ *
85
+ * @returns The decoded data.
86
+ *
87
+ * @example Usage
88
+ * ```ts
89
+ * import { decodeHex } from "@std/encoding/hex";
90
+ * import { assertEquals } from "@std/assert";
91
+ *
92
+ * assertEquals(
93
+ * decodeHex("616263"),
94
+ * new TextEncoder().encode("abc"),
95
+ * );
96
+ * ```
97
+ */
98
+ function decodeHex(src) {
99
+ const u8 = textEncoder.encode(src);
100
+ const dst = new Uint8Array(u8.length / 2);
101
+ for (let i = 0; i < dst.length; i++) {
102
+ const a = fromHexChar(u8[i * 2]);
103
+ const b = fromHexChar(u8[i * 2 + 1]);
104
+ dst[i] = (a << 4) | b;
105
+ }
106
+ if (u8.length % 2 === 1) {
107
+ // Check for invalid char before reporting bad length,
108
+ // since the invalid char (if present) is an earlier problem.
109
+ fromHexChar(u8[dst.length * 2]);
110
+ throw errLength(u8.length);
111
+ }
112
+ return dst;
113
+ }
@@ -21,6 +21,7 @@ export declare abstract class Session {
21
21
  get dc(): DC;
22
22
  get cdn(): boolean;
23
23
  set serverSalt(serverSalt: bigint);
24
+ get serverSalt(): bigint;
24
25
  get connected(): boolean;
25
26
  connect(): Promise<void>;
26
27
  protected waitUntilConnected(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,8BAAsB,OAAO;;IAG3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAsB;IACnD,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;gBAMvC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAc1C,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IA6BD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGK,OAAO;cAeG,kBAAkB;IAIlC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,UAAU;IAOV,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CACjD"}
1
+ {"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,8BAAsB,OAAO;;IAG3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAsB;IACnD,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;gBAMvC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAc1C,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IA6BD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGK,OAAO;cAeG,kBAAkB;IAIlC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,UAAU;IAOV,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CACjD"}
@@ -98,6 +98,9 @@ class Session {
98
98
  set serverSalt(serverSalt) {
99
99
  this.state.serverSalt = serverSalt;
100
100
  }
101
+ get serverSalt() {
102
+ return this.state.serverSalt;
103
+ }
101
104
  #lastState;
102
105
  async #stateChangeHandler(connected) {
103
106
  if (this.#lastState !== connected) {
@@ -33,9 +33,9 @@ export declare class SessionEncrypted extends Session implements Session {
33
33
  handlers: Handlers;
34
34
  constructor(dc: DC, params?: SessionParams);
35
35
  setAuthKey(key: Uint8Array<ArrayBuffer>): Promise<void>;
36
- get authKey(): Uint8Array;
36
+ get authKey(): Uint8Array<ArrayBuffer>;
37
37
  connect(): Promise<void>;
38
38
  disconnect(): void;
39
- send(body: Uint8Array): Promise<bigint>;
39
+ send(body: Uint8Array<ArrayBuffer>): Promise<bigint>;
40
40
  }
41
41
  //# sourceMappingURL=2_session_encrypted.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAS7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAQD,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAQZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAMpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAExB;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAa9B,UAAU,IAAI,IAAI;IAuDrB,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CAyU9C"}
1
+ {"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAiBZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAQpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAErC;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CA6W3D"}
@@ -24,6 +24,7 @@ const _0_deps_js_1 = require("../0_deps.js");
24
24
  const _0_errors_js_1 = require("../0_errors.js");
25
25
  const _1_utilities_js_1 = require("../1_utilities.js");
26
26
  const _2_tl_js_1 = require("../2_tl.js");
27
+ const _0_abortable_loop_js_1 = require("../client/0_abortable_loop.js");
27
28
  const _1_tl_writer_js_1 = require("../tl/1_tl_writer.js");
28
29
  const _0_session_error_js_1 = require("./0_session_error.js");
29
30
  const _1_session_js_1 = require("./1_session.js");
@@ -33,19 +34,27 @@ const GZIP_PACKED = 0x3072CFA1;
33
34
  const RPC_RESULT = 0xF35C6D01;
34
35
  const RPC_ERROR = _2_tl_js_1.Mtproto.schema.definitions["rpc_error"][0];
35
36
  class SessionEncrypted extends _1_session_js_1.Session {
37
+ static #TGCRYPTO_INITED = false;
36
38
  #id = (0, _1_utilities_js_1.getRandomId)();
39
+ handlers = {};
40
+ #L;
41
+ #LsendLoop;
42
+ #LreceiveLoop;
43
+ #LpingLoop;
37
44
  #authKey = new Uint8Array();
38
45
  #authKeyId = 0n;
39
- handlers = {};
40
- #toAcknowledge = new Array();
41
- #pendingMessages = new Set();
46
+ #sentMessages = new Set();
47
+ #pendingMessages = new Array();
48
+ #containers = new _0_deps_js_1.LruCache(20_000);
42
49
  #pendingPings = new Map();
43
- #L;
44
- static #TGCRYPTO_INITED = false;
50
+ #toAcknowledge = new Array();
51
+ #pendingAcks = new _0_deps_js_1.LruCache(100);
45
52
  constructor(dc, params) {
46
53
  super(dc, params);
47
54
  const L = this.#L = (0, _1_utilities_js_1.getLogger)("SessionEncrypted").client(id++);
48
- this.#LpingLoop = L.branch("#pingLoop");
55
+ this.#LsendLoop = L.branch("sendLoop");
56
+ this.#LreceiveLoop = L.branch("receiveLoop");
57
+ this.#LpingLoop = L.branch("pingLoop");
49
58
  }
50
59
  async setAuthKey(key) {
51
60
  const hash = await (0, _1_utilities_js_1.sha1)(key);
@@ -64,14 +73,17 @@ class SessionEncrypted extends _1_session_js_1.Session {
64
73
  await (0, _0_deps_js_1.initTgCrypto)();
65
74
  SessionEncrypted.#TGCRYPTO_INITED = true;
66
75
  }
67
- this.#startReceiveLoop();
68
- this.#startPingLoop();
76
+ this.#receiveLoop.start();
77
+ this.#sendLoop.start();
78
+ this.#pingLoop.start();
79
+ this.#awakeSendLoop?.();
69
80
  }
70
81
  disconnect() {
71
82
  super.disconnect();
72
83
  this.state.reset();
73
84
  this.#id = (0, _1_utilities_js_1.getRandomId)();
74
- this.#pingLoopAbortController?.abort();
85
+ this.#pingLoop.abort();
86
+ this.#awakeSendLoop?.();
75
87
  this.#rejectAllPending(new _0_errors_js_1.ConnectionError("Not connected."));
76
88
  }
77
89
  #assertNotDisconnected() {
@@ -88,17 +100,34 @@ class SessionEncrypted extends _1_session_js_1.Session {
88
100
  this.#rejectAllPending(new _0_session_error_js_1.SessionError("Session invalidated."));
89
101
  }
90
102
  #rejectAllPending(reason) {
91
- for (const id of this.#pendingMessages) {
103
+ for (const id of this.#sentMessages) {
92
104
  this.#onMessageFailed(id, reason);
93
105
  }
94
- this.#pendingMessages.clear();
95
106
  for (const pendingPing of this.#pendingPings.values()) {
96
- pendingPing.reject(reason);
107
+ pendingPing.promiseWithResolvers.reject(reason);
97
108
  }
109
+ this.#sentMessages.clear();
98
110
  this.#pendingPings.clear();
111
+ this.#containers.clear();
99
112
  }
100
113
  #onMessageFailed(id, reason) {
101
- this.#pendingMessages.delete(id);
114
+ this.#sentMessages.delete(id);
115
+ const pendingContainer = this.#containers.get(id);
116
+ if (pendingContainer) {
117
+ for (const id of pendingContainer) {
118
+ this.#onMessageFailed(id, reason);
119
+ }
120
+ this.#containers.delete(id);
121
+ return;
122
+ }
123
+ const pendingAck = this.#pendingAcks.get(id);
124
+ if (pendingAck) {
125
+ for (const id of pendingAck) {
126
+ this.#toAcknowledge.push(id);
127
+ }
128
+ this.#pendingAcks.delete(id);
129
+ return;
130
+ }
102
131
  const pendingPing = this.#pendingPings.get(id);
103
132
  if (pendingPing) {
104
133
  this.#pendingPings.delete(id);
@@ -106,13 +135,12 @@ class SessionEncrypted extends _1_session_js_1.Session {
106
135
  (0, _1_utilities_js_1.drop)(this.#resendPendingPing(pendingPing));
107
136
  }
108
137
  else {
109
- pendingPing.reject(reason);
138
+ pendingPing.promiseWithResolvers.reject(reason);
110
139
  }
140
+ return;
111
141
  }
112
- else {
113
- // message was not sent by us
114
- this.handlers.onMessageFailed?.(id, reason);
115
- }
142
+ // message was not sent by us
143
+ this.handlers.onMessageFailed?.(id, reason);
116
144
  }
117
145
  #setServerSalt(newServerSalt) {
118
146
  this.state.serverSalt = newServerSalt;
@@ -123,36 +151,10 @@ class SessionEncrypted extends _1_session_js_1.Session {
123
151
  await super.waitUntilConnected();
124
152
  }
125
153
  this.#assertNotDisconnected();
126
- const msg_id = this.state.nextMessageId();
127
- const seqno = this.state.nextSeqNo(true);
128
- let message = {
129
- _: "message",
130
- msg_id,
131
- seqno,
132
- body,
133
- };
134
- if (this.#toAcknowledge.length) {
135
- const ack = {
136
- _: "message",
137
- msg_id: this.state.nextMessageId(),
138
- seqno: this.state.nextSeqNo(false),
139
- body: _2_tl_js_1.Mtproto.serializeObject({ _: "msgs_ack", msg_ids: this.#toAcknowledge.splice(0, 8192) }),
140
- };
141
- message = {
142
- _: "message",
143
- msg_id: this.state.nextMessageId(),
144
- seqno: this.state.nextSeqNo(false),
145
- body: {
146
- _: "msg_container",
147
- messages: [message, ack],
148
- },
149
- };
150
- }
151
- this.#L.out(message);
152
- const payload = await this.#encryptMessage(message);
153
- await this.transport.transport.send(payload);
154
- this.#pendingMessages.add(msg_id);
155
- return msg_id;
154
+ const pendingMessage = { body, promiseWithResolvers: Promise.withResolvers() };
155
+ this.#pendingMessages.push(pendingMessage);
156
+ this.#awakeSendLoop?.();
157
+ return await pendingMessage.promiseWithResolvers.promise;
156
158
  }
157
159
  async #receive() {
158
160
  this.#assertNotDisconnected();
@@ -205,60 +207,133 @@ class SessionEncrypted extends _1_session_js_1.Session {
205
207
  const _sessionId_ = plainReader.readInt64(false);
206
208
  return (0, _2_tl_js_1.deserializeMessage)(plainReader);
207
209
  }
208
- //// RECEIVE LOOP ////
209
- #startReceiveLoop() {
210
- if (!this.#receiveLoopActive) {
211
- (0, _1_utilities_js_1.drop)(this.#receiveLoop());
210
+ //// SEND LOOP ////
211
+ #awakeSendLoop;
212
+ #sendLoop = new _0_abortable_loop_js_1.AbortableLoop(this.#sendLoopBody.bind(this), (err) => {
213
+ this.#LsendLoop.error("unhandled receive loop error:", err);
214
+ });
215
+ async #sendLoopBody(loop, signal) {
216
+ if (!this.connected) {
217
+ this.#LsendLoop.debug("aborting as not connected");
218
+ loop.abort();
219
+ return;
220
+ }
221
+ const pendingMessage = this.#pendingMessages.shift();
222
+ if (pendingMessage === undefined) {
223
+ this.#LsendLoop.debug("no pending messages");
224
+ return await new Promise((resolve) => {
225
+ const onAbort = () => {
226
+ this.#LsendLoop.debug("got aborted while sleeping");
227
+ resolve();
228
+ };
229
+ signal.addEventListener("abort", onAbort);
230
+ this.#awakeSendLoop = () => {
231
+ this.#LsendLoop.debug("got awaken");
232
+ resolve();
233
+ signal.removeEventListener("abort", onAbort);
234
+ };
235
+ });
236
+ }
237
+ const msg_id = this.state.nextMessageId();
238
+ const seqno = this.state.nextSeqNo(true);
239
+ let message = {
240
+ _: "message",
241
+ msg_id,
242
+ seqno,
243
+ body: pendingMessage.body,
244
+ };
245
+ this.#LsendLoop.debug("msg_id =", msg_id, "seqno =", seqno);
246
+ if (this.#toAcknowledge.length) {
247
+ const msg_ids = this.#toAcknowledge.splice(0, 8192);
248
+ this.#LsendLoop.debug("acknowledging", msg_ids.length, "message(s) while sending this one");
249
+ const ack = {
250
+ _: "message",
251
+ msg_id: this.state.nextMessageId(),
252
+ seqno: this.state.nextSeqNo(false),
253
+ body: _2_tl_js_1.Mtproto.serializeObject({ _: "msgs_ack", msg_ids }),
254
+ };
255
+ this.#LsendLoop.debug("msgs_ack msg_id =", ack.msg_id, "seqno =", seqno);
256
+ this.#pendingAcks.set(ack.msg_id, msg_ids);
257
+ message = {
258
+ _: "message",
259
+ msg_id: this.state.nextMessageId(),
260
+ seqno: this.state.nextSeqNo(false),
261
+ body: {
262
+ _: "msg_container",
263
+ messages: [message, ack],
264
+ },
265
+ };
266
+ this.#LsendLoop.debug("container msg_id =", message.msg_id, "seqno =", message.seqno);
267
+ }
268
+ try {
269
+ const payload = await this.#encryptMessage(message);
270
+ await this.transport.transport.send(payload);
271
+ pendingMessage.promiseWithResolvers.resolve(msg_id);
272
+ }
273
+ catch (err) {
274
+ pendingMessage.promiseWithResolvers.reject(err);
275
+ return;
276
+ }
277
+ this.#LsendLoop.out(message);
278
+ this.#sentMessages.add(msg_id);
279
+ if (!(message.body instanceof Uint8Array)) {
280
+ const msg_ids = message.body.messages.map((v) => v.msg_id);
281
+ this.#LsendLoop.debug("sent container", message.msg_id, "with messages", ...msg_ids);
282
+ this.#containers.set(message.msg_id, msg_ids);
283
+ }
284
+ else {
285
+ this.#LsendLoop.debug("sent message", message.msg_id);
212
286
  }
213
287
  }
214
- #receiveLoopActive = false;
215
- async #receiveLoop() {
216
- this.#receiveLoopActive = true;
288
+ //// RECEIVE LOOP ////
289
+ #receiveLoop = new _0_abortable_loop_js_1.AbortableLoop(this.#receiveLoopBody.bind(this), (err) => {
290
+ this.#LreceiveLoop.error("unhandled receive loop error:", err);
291
+ });
292
+ async #receiveLoopBody(loop) {
293
+ let message;
217
294
  try {
218
- while (this.connected) {
219
- let message;
220
- try {
221
- message = await this.#receive();
222
- }
223
- catch (err) {
224
- this.#L.error("failed to receive message:", err);
225
- if (!this.connected) {
226
- break;
227
- }
228
- else {
229
- continue;
230
- }
231
- }
232
- try {
233
- if (message.body instanceof Uint8Array) {
234
- this.#onMessage(message.msg_id, message.body);
235
- }
236
- else {
237
- this.#onMessageContainer(message.msg_id, message.body);
238
- }
239
- }
240
- catch (err) {
241
- this.#L.error("failed to handle message:", err);
242
- }
295
+ message = await this.#receive();
296
+ }
297
+ catch (err) {
298
+ this.#LreceiveLoop.error("failed to receive message:", err);
299
+ if (!this.connected) {
300
+ this.#LreceiveLoop.debug("aborting as not connected");
301
+ loop.abort();
302
+ return;
303
+ }
304
+ else {
305
+ return;
243
306
  }
244
307
  }
245
- finally {
246
- this.#receiveLoopActive = false;
308
+ try {
309
+ if (message.body instanceof Uint8Array) {
310
+ this.#onMessage(message.msg_id, message.body, null);
311
+ }
312
+ else {
313
+ this.#onMessageContainer(message.msg_id, message.body);
314
+ }
315
+ }
316
+ catch (err) {
317
+ this.#LreceiveLoop.error("failed to handle message:", err);
247
318
  }
248
319
  }
249
320
  //// RECEIVE LOOP HANDLERS ////
250
- async #onMessage(msgId, body) {
321
+ async #onMessage(msgId, body, containerId) {
322
+ this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.length, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
323
+ const logger = this.#LreceiveLoop.branch(msgId + "");
251
324
  let reader = new _2_tl_js_1.TLReader(body);
252
325
  let id = reader.readInt32(false);
253
326
  if (id === GZIP_PACKED) {
327
+ logger.debug("unpacking compressed body");
254
328
  reader = new _2_tl_js_1.TLReader(await (0, _1_utilities_js_1.gunzip)(reader.readBytes()));
255
329
  id = reader.readInt32(false);
256
330
  }
257
331
  if (id === RPC_RESULT) {
258
- this.#onRpcResult(msgId, reader.buffer);
332
+ this.#onRpcResult(msgId, reader.buffer, logger);
259
333
  return;
260
334
  }
261
335
  if (!_2_tl_js_1.Mtproto.schema.identifierToName[id]) {
336
+ logger.debug("identified body as a non-MTProto constructor");
262
337
  reader.unreadInt32();
263
338
  this.handlers.onUpdate?.(reader.buffer);
264
339
  return;
@@ -269,10 +344,10 @@ class SessionEncrypted extends _1_session_js_1.Session {
269
344
  type = await _2_tl_js_1.Mtproto.deserializeType(_2_tl_js_1.X, reader);
270
345
  }
271
346
  catch (err) {
272
- this.#L.error("failed to deserialize MTProto type:", err);
347
+ logger.error("failed to deserialize MTProto type:", err);
273
348
  return;
274
349
  }
275
- this.#L.debug("received", (0, _2_tl_js_1.repr)(type));
350
+ logger.debug("received", (0, _2_tl_js_1.repr)(type));
276
351
  if (_2_tl_js_1.Mtproto.is("new_session_created", type)) {
277
352
  this.#onNewSessionCreated(msgId, type);
278
353
  }
@@ -283,24 +358,26 @@ class SessionEncrypted extends _1_session_js_1.Session {
283
358
  this.#onBadServerSalt(type);
284
359
  }
285
360
  else if (_2_tl_js_1.Mtproto.is("bad_msg_notification", type)) {
286
- await this.#onBadMsgNotification(msgId, type);
361
+ await this.#onBadMsgNotification(msgId, type, logger);
287
362
  }
288
363
  else if (_2_tl_js_1.Mtproto.is("msg_detailed_info", type)) {
289
- this.#onMsgDetailedInfo(type);
364
+ this.#onMsgDetailedInfo(type, logger);
290
365
  }
291
366
  else if (_2_tl_js_1.Mtproto.is("msg_new_detailed_info", type)) {
292
- this.#onMsgNewDetailedInfo(type);
367
+ this.#onMsgNewDetailedInfo(type, logger);
293
368
  }
294
369
  else {
295
- this.#L.debug(`unhandled MTProto type: ${(0, _2_tl_js_1.repr)(type)}`);
370
+ logger.warning(`unhandled MTProto type: ${(0, _2_tl_js_1.repr)(type)}`);
296
371
  }
297
372
  }
298
- async #onRpcResult(msgId, body) {
373
+ async #onRpcResult(msgId, body, logger) {
374
+ logger.debug("received rpc_result");
299
375
  this.#toAcknowledge.push(msgId);
300
376
  let reader = new _2_tl_js_1.TLReader(body);
301
377
  const reqMsgId = reader.readInt64();
302
378
  let id = reader.readInt32(false);
303
379
  if (id === GZIP_PACKED) {
380
+ logger.debug("unpacking compressed rpc_result");
304
381
  reader = new _2_tl_js_1.TLReader(await (0, _1_utilities_js_1.gunzip)(reader.readBytes()));
305
382
  id = reader.readInt32(false);
306
383
  reader.unreadInt32();
@@ -309,6 +386,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
309
386
  reader.unreadInt32();
310
387
  }
311
388
  if (id === RPC_ERROR) {
389
+ logger.debug("received rpc_error from message", msgId);
312
390
  const error = await _2_tl_js_1.Mtproto.deserializeType("rpc_error", reader);
313
391
  this.handlers.onRpcError?.(reqMsgId, error);
314
392
  }
@@ -316,13 +394,15 @@ class SessionEncrypted extends _1_session_js_1.Session {
316
394
  this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
317
395
  }
318
396
  }
319
- #onMsgDetailedInfo(msgDetailedInfo) {
397
+ #onMsgDetailedInfo(msgDetailedInfo, logger) {
398
+ logger.debug("scheduling the acknowledgement of", msgDetailedInfo.answer_msg_id, "because of", msgDetailedInfo._);
320
399
  this.#toAcknowledge.push(msgDetailedInfo.answer_msg_id);
321
400
  }
322
- #onMsgNewDetailedInfo(msgNewDetailedInfo) {
401
+ #onMsgNewDetailedInfo(msgNewDetailedInfo, logger) {
402
+ logger.debug("scheduling the acknowledgement of", msgNewDetailedInfo.answer_msg_id, "because of", msgNewDetailedInfo._);
323
403
  this.#toAcknowledge.push(msgNewDetailedInfo.answer_msg_id);
324
404
  }
325
- async #onBadMsgNotification(msgId, badMsgNotification) {
405
+ async #onBadMsgNotification(msgId, badMsgNotification, logger) {
326
406
  let low = false;
327
407
  switch (badMsgNotification.error_code) {
328
408
  case 16: // message ID too low
@@ -332,11 +412,12 @@ class SessionEncrypted extends _1_session_js_1.Session {
332
412
  this.state.timeDifference = Math.abs((0, _1_utilities_js_1.toUnixTimestamp)(new Date()) - Number(msgId >> 32n));
333
413
  if (!low) {
334
414
  this.state.timeDifference = -this.state.timeDifference;
415
+ logger.debug("resetting time difference to", -this.state.timeDifference, "because the ID of the message", badMsgNotification.bad_msg_id, "was too high");
335
416
  await this.#invalidateSession("message ID too high");
336
417
  return;
337
418
  }
338
419
  else {
339
- this.#L.debug("message ID too low, resending message");
420
+ logger.debug("resending message", badMsgNotification.bad_msg_id, "because its ID was too low");
340
421
  }
341
422
  break;
342
423
  case 48: // bad server salt
@@ -357,7 +438,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
357
438
  this.#toAcknowledge.push(msgId);
358
439
  const pendingPing = this.#pendingPings.get(pong.msg_id);
359
440
  if (pendingPing) {
360
- pendingPing.resolve(pong);
441
+ pendingPing.promiseWithResolvers.resolve(pong);
361
442
  this.#pendingPings.delete(pong.msg_id);
362
443
  }
363
444
  else {
@@ -370,9 +451,10 @@ class SessionEncrypted extends _1_session_js_1.Session {
370
451
  this.#toAcknowledge.push(msgId);
371
452
  }
372
453
  #onMessageContainer(msgId, msgContainer) {
454
+ this.#LreceiveLoop.debug("received container with ID", msgId, "and", msgContainer.messages.length, "message(s)");
373
455
  for (const message of msgContainer.messages) {
374
456
  if (message.body instanceof Uint8Array) {
375
- this.#onMessage(message.msg_id, message.body);
457
+ this.#onMessage(message.msg_id, message.body, msgId);
376
458
  }
377
459
  else {
378
460
  this.#onMessageContainer(msgId, message.body);
@@ -381,49 +463,30 @@ class SessionEncrypted extends _1_session_js_1.Session {
381
463
  }
382
464
  //// PING LOOP ////
383
465
  #pingInterval = 56 * _0_deps_js_1.SECOND;
384
- #startPingLoop() {
385
- (0, _1_utilities_js_1.drop)(this.#pingLoop());
386
- }
387
- #pingLoopAbortController;
388
- #LpingLoop;
389
- async #pingLoop() {
390
- this.#pingLoopAbortController?.abort();
391
- const controller = this.#pingLoopAbortController = new AbortController();
466
+ #pingLoop = new _0_abortable_loop_js_1.AbortableLoop(this.#pingLoopBody.bind(this), (err) => {
467
+ this.#LpingLoop.error(err);
468
+ });
469
+ async #pingLoopBody(_loop, signal) {
392
470
  let timeElapsed = 0;
393
- while (this.connected) {
394
- try {
395
- await (0, _0_deps_js_1.delay)(Math.max(0, this.#pingInterval - timeElapsed), { signal: controller.signal });
396
- if (!this.connected) {
397
- continue;
398
- }
399
- controller.signal.throwIfAborted();
400
- const then = Date.now();
401
- try {
402
- await this.#sendPingDelayDisconnect(this.#pingInterval / _0_deps_js_1.SECOND + 15);
403
- }
404
- finally {
405
- timeElapsed = Date.now() - then;
406
- }
407
- controller.signal.throwIfAborted();
408
- }
409
- catch (err) {
410
- if (err instanceof DOMException && err.name === "AbortError") {
411
- break;
412
- }
413
- else if (!this.connected) {
414
- break;
415
- }
416
- this.#LpingLoop.error(err);
417
- }
471
+ await (0, _0_deps_js_1.delay)(Math.max(0, this.#pingInterval - timeElapsed), { signal });
472
+ if (!this.connected) {
473
+ return;
474
+ }
475
+ signal.throwIfAborted();
476
+ const then = Date.now();
477
+ try {
478
+ await this.#sendPingDelayDisconnect(this.#pingInterval / _0_deps_js_1.SECOND + 15);
479
+ }
480
+ finally {
481
+ timeElapsed = Date.now() - then;
418
482
  }
483
+ signal.throwIfAborted();
419
484
  }
420
485
  async #sendPingDelayDisconnect(disconnect_delay) {
421
486
  const ping_id = (0, _1_utilities_js_1.getRandomId)();
422
487
  const call = { _: "ping_delay_disconnect", ping_id, disconnect_delay };
423
488
  const messageId = await this.send(_2_tl_js_1.Mtproto.serializeObject(call));
424
- await new Promise((resolve, reject) => {
425
- this.#pendingPings.set(messageId, { call, resolve, reject });
426
- });
489
+ this.#pendingPings.set(messageId, { call, promiseWithResolvers: Promise.withResolvers() });
427
490
  }
428
491
  async #resendPendingPing(pendingPing) {
429
492
  try {
@@ -431,7 +494,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
431
494
  this.#pendingPings.set(messageId, pendingPing);
432
495
  }
433
496
  catch (err) {
434
- pendingPing.reject(err);
497
+ pendingPing.promiseWithResolvers.reject(err);
435
498
  }
436
499
  }
437
500
  }