@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,109 @@
1
+ // Copyright 2009 The Go Authors. All rights reserved.
2
+ // https://github.com/golang/go/blob/master/LICENSE
3
+ // Copyright 2018-2025 the Deno authors. MIT license.
4
+ // This module is browser compatible.
5
+ /**
6
+ * Port of the Go
7
+ * {@link https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go | encoding/hex}
8
+ * library.
9
+ *
10
+ * ```ts
11
+ * import {
12
+ * decodeHex,
13
+ * encodeHex,
14
+ * } from "@std/encoding/hex";
15
+ * import { assertEquals } from "@std/assert";
16
+ *
17
+ * assertEquals(encodeHex("abc"), "616263");
18
+ *
19
+ * assertEquals(
20
+ * decodeHex("616263"),
21
+ * new TextEncoder().encode("abc"),
22
+ * );
23
+ * ```
24
+ *
25
+ * @module
26
+ */
27
+ import { validateBinaryLike } from "./_validate_binary_like.js";
28
+ const hexTable = new TextEncoder().encode("0123456789abcdef");
29
+ const textEncoder = new TextEncoder();
30
+ const textDecoder = new TextDecoder();
31
+ function errInvalidByte(byte) {
32
+ return new TypeError(`Invalid byte '${String.fromCharCode(byte)}'`);
33
+ }
34
+ function errLength(len) {
35
+ return new RangeError(`Cannot decode the hex string as the input length should be even: length is ${len}`);
36
+ }
37
+ /** Converts a hex character into its value. */
38
+ function fromHexChar(byte) {
39
+ // '0' <= byte && byte <= '9'
40
+ if (48 <= byte && byte <= 57)
41
+ return byte - 48;
42
+ // 'a' <= byte && byte <= 'f'
43
+ if (97 <= byte && byte <= 102)
44
+ return byte - 97 + 10;
45
+ // 'A' <= byte && byte <= 'F'
46
+ if (65 <= byte && byte <= 70)
47
+ return byte - 65 + 10;
48
+ throw errInvalidByte(byte);
49
+ }
50
+ /**
51
+ * Converts data into a hex-encoded string.
52
+ *
53
+ * @param src The data to encode.
54
+ *
55
+ * @returns The hex-encoded string.
56
+ *
57
+ * @example Usage
58
+ * ```ts
59
+ * import { encodeHex } from "@std/encoding/hex";
60
+ * import { assertEquals } from "@std/assert";
61
+ *
62
+ * assertEquals(encodeHex("abc"), "616263");
63
+ * ```
64
+ */
65
+ export function encodeHex(src) {
66
+ const u8 = validateBinaryLike(src);
67
+ const dst = new Uint8Array(u8.length * 2);
68
+ for (let i = 0; i < u8.length; i++) {
69
+ const v = u8[i];
70
+ dst[i * 2] = hexTable[v >> 4];
71
+ dst[i * 2 + 1] = hexTable[v & 0x0f];
72
+ }
73
+ return textDecoder.decode(dst);
74
+ }
75
+ /**
76
+ * Decodes the given hex-encoded string. If the input is malformed, an error is
77
+ * thrown.
78
+ *
79
+ * @param src The hex-encoded string to decode.
80
+ *
81
+ * @returns The decoded data.
82
+ *
83
+ * @example Usage
84
+ * ```ts
85
+ * import { decodeHex } from "@std/encoding/hex";
86
+ * import { assertEquals } from "@std/assert";
87
+ *
88
+ * assertEquals(
89
+ * decodeHex("616263"),
90
+ * new TextEncoder().encode("abc"),
91
+ * );
92
+ * ```
93
+ */
94
+ export function decodeHex(src) {
95
+ const u8 = textEncoder.encode(src);
96
+ const dst = new Uint8Array(u8.length / 2);
97
+ for (let i = 0; i < dst.length; i++) {
98
+ const a = fromHexChar(u8[i * 2]);
99
+ const b = fromHexChar(u8[i * 2 + 1]);
100
+ dst[i] = (a << 4) | b;
101
+ }
102
+ if (u8.length % 2 === 1) {
103
+ // Check for invalid char before reporting bad length,
104
+ // since the invalid char (if present) is an earlier problem.
105
+ fromHexChar(u8[dst.length * 2]);
106
+ throw errLength(u8.length);
107
+ }
108
+ return dst;
109
+ }
@@ -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"}
@@ -62,6 +62,9 @@ export class Session {
62
62
  set serverSalt(serverSalt) {
63
63
  this.state.serverSalt = serverSalt;
64
64
  }
65
+ get serverSalt() {
66
+ return this.state.serverSalt;
67
+ }
65
68
  #lastState;
66
69
  async #stateChangeHandler(connected) {
67
70
  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"}
@@ -17,10 +17,11 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- import { assertEquals, concat, delay, ige256Decrypt, ige256Encrypt, initTgCrypto, SECOND } from "../0_deps.js";
20
+ import { assertEquals, concat, delay, ige256Decrypt, ige256Encrypt, initTgCrypto, LruCache, SECOND } from "../0_deps.js";
21
21
  import { ConnectionError, TransportError } from "../0_errors.js";
22
22
  import { bigIntFromBuffer, bufferFromBigInt, drop, getLogger, getRandomId, gunzip, mod, sha1, sha256, toUnixTimestamp } from "../1_utilities.js";
23
23
  import { deserializeMessage, Mtproto, repr, serializeMessage, TLReader, X } from "../2_tl.js";
24
+ import { AbortableLoop } from "../client/0_abortable_loop.js";
24
25
  import { TLWriter } from "../tl/1_tl_writer.js";
25
26
  import { SessionError } from "./0_session_error.js";
26
27
  import { Session } from "./1_session.js";
@@ -30,19 +31,27 @@ const GZIP_PACKED = 0x3072CFA1;
30
31
  const RPC_RESULT = 0xF35C6D01;
31
32
  const RPC_ERROR = Mtproto.schema.definitions["rpc_error"][0];
32
33
  export class SessionEncrypted extends Session {
34
+ static #TGCRYPTO_INITED = false;
33
35
  #id = getRandomId();
36
+ handlers = {};
37
+ #L;
38
+ #LsendLoop;
39
+ #LreceiveLoop;
40
+ #LpingLoop;
34
41
  #authKey = new Uint8Array();
35
42
  #authKeyId = 0n;
36
- handlers = {};
37
- #toAcknowledge = new Array();
38
- #pendingMessages = new Set();
43
+ #sentMessages = new Set();
44
+ #pendingMessages = new Array();
45
+ #containers = new LruCache(20_000);
39
46
  #pendingPings = new Map();
40
- #L;
41
- static #TGCRYPTO_INITED = false;
47
+ #toAcknowledge = new Array();
48
+ #pendingAcks = new LruCache(100);
42
49
  constructor(dc, params) {
43
50
  super(dc, params);
44
51
  const L = this.#L = getLogger("SessionEncrypted").client(id++);
45
- this.#LpingLoop = L.branch("#pingLoop");
52
+ this.#LsendLoop = L.branch("sendLoop");
53
+ this.#LreceiveLoop = L.branch("receiveLoop");
54
+ this.#LpingLoop = L.branch("pingLoop");
46
55
  }
47
56
  async setAuthKey(key) {
48
57
  const hash = await sha1(key);
@@ -61,14 +70,17 @@ export class SessionEncrypted extends Session {
61
70
  await initTgCrypto();
62
71
  SessionEncrypted.#TGCRYPTO_INITED = true;
63
72
  }
64
- this.#startReceiveLoop();
65
- this.#startPingLoop();
73
+ this.#receiveLoop.start();
74
+ this.#sendLoop.start();
75
+ this.#pingLoop.start();
76
+ this.#awakeSendLoop?.();
66
77
  }
67
78
  disconnect() {
68
79
  super.disconnect();
69
80
  this.state.reset();
70
81
  this.#id = getRandomId();
71
- this.#pingLoopAbortController?.abort();
82
+ this.#pingLoop.abort();
83
+ this.#awakeSendLoop?.();
72
84
  this.#rejectAllPending(new ConnectionError("Not connected."));
73
85
  }
74
86
  #assertNotDisconnected() {
@@ -85,17 +97,34 @@ export class SessionEncrypted extends Session {
85
97
  this.#rejectAllPending(new SessionError("Session invalidated."));
86
98
  }
87
99
  #rejectAllPending(reason) {
88
- for (const id of this.#pendingMessages) {
100
+ for (const id of this.#sentMessages) {
89
101
  this.#onMessageFailed(id, reason);
90
102
  }
91
- this.#pendingMessages.clear();
92
103
  for (const pendingPing of this.#pendingPings.values()) {
93
- pendingPing.reject(reason);
104
+ pendingPing.promiseWithResolvers.reject(reason);
94
105
  }
106
+ this.#sentMessages.clear();
95
107
  this.#pendingPings.clear();
108
+ this.#containers.clear();
96
109
  }
97
110
  #onMessageFailed(id, reason) {
98
- this.#pendingMessages.delete(id);
111
+ this.#sentMessages.delete(id);
112
+ const pendingContainer = this.#containers.get(id);
113
+ if (pendingContainer) {
114
+ for (const id of pendingContainer) {
115
+ this.#onMessageFailed(id, reason);
116
+ }
117
+ this.#containers.delete(id);
118
+ return;
119
+ }
120
+ const pendingAck = this.#pendingAcks.get(id);
121
+ if (pendingAck) {
122
+ for (const id of pendingAck) {
123
+ this.#toAcknowledge.push(id);
124
+ }
125
+ this.#pendingAcks.delete(id);
126
+ return;
127
+ }
99
128
  const pendingPing = this.#pendingPings.get(id);
100
129
  if (pendingPing) {
101
130
  this.#pendingPings.delete(id);
@@ -103,13 +132,12 @@ export class SessionEncrypted extends Session {
103
132
  drop(this.#resendPendingPing(pendingPing));
104
133
  }
105
134
  else {
106
- pendingPing.reject(reason);
135
+ pendingPing.promiseWithResolvers.reject(reason);
107
136
  }
137
+ return;
108
138
  }
109
- else {
110
- // message was not sent by us
111
- this.handlers.onMessageFailed?.(id, reason);
112
- }
139
+ // message was not sent by us
140
+ this.handlers.onMessageFailed?.(id, reason);
113
141
  }
114
142
  #setServerSalt(newServerSalt) {
115
143
  this.state.serverSalt = newServerSalt;
@@ -120,36 +148,10 @@ export class SessionEncrypted extends Session {
120
148
  await super.waitUntilConnected();
121
149
  }
122
150
  this.#assertNotDisconnected();
123
- const msg_id = this.state.nextMessageId();
124
- const seqno = this.state.nextSeqNo(true);
125
- let message = {
126
- _: "message",
127
- msg_id,
128
- seqno,
129
- body,
130
- };
131
- if (this.#toAcknowledge.length) {
132
- const ack = {
133
- _: "message",
134
- msg_id: this.state.nextMessageId(),
135
- seqno: this.state.nextSeqNo(false),
136
- body: Mtproto.serializeObject({ _: "msgs_ack", msg_ids: this.#toAcknowledge.splice(0, 8192) }),
137
- };
138
- message = {
139
- _: "message",
140
- msg_id: this.state.nextMessageId(),
141
- seqno: this.state.nextSeqNo(false),
142
- body: {
143
- _: "msg_container",
144
- messages: [message, ack],
145
- },
146
- };
147
- }
148
- this.#L.out(message);
149
- const payload = await this.#encryptMessage(message);
150
- await this.transport.transport.send(payload);
151
- this.#pendingMessages.add(msg_id);
152
- return msg_id;
151
+ const pendingMessage = { body, promiseWithResolvers: Promise.withResolvers() };
152
+ this.#pendingMessages.push(pendingMessage);
153
+ this.#awakeSendLoop?.();
154
+ return await pendingMessage.promiseWithResolvers.promise;
153
155
  }
154
156
  async #receive() {
155
157
  this.#assertNotDisconnected();
@@ -202,60 +204,133 @@ export class SessionEncrypted extends Session {
202
204
  const _sessionId_ = plainReader.readInt64(false);
203
205
  return deserializeMessage(plainReader);
204
206
  }
205
- //// RECEIVE LOOP ////
206
- #startReceiveLoop() {
207
- if (!this.#receiveLoopActive) {
208
- drop(this.#receiveLoop());
207
+ //// SEND LOOP ////
208
+ #awakeSendLoop;
209
+ #sendLoop = new AbortableLoop(this.#sendLoopBody.bind(this), (err) => {
210
+ this.#LsendLoop.error("unhandled receive loop error:", err);
211
+ });
212
+ async #sendLoopBody(loop, signal) {
213
+ if (!this.connected) {
214
+ this.#LsendLoop.debug("aborting as not connected");
215
+ loop.abort();
216
+ return;
217
+ }
218
+ const pendingMessage = this.#pendingMessages.shift();
219
+ if (pendingMessage === undefined) {
220
+ this.#LsendLoop.debug("no pending messages");
221
+ return await new Promise((resolve) => {
222
+ const onAbort = () => {
223
+ this.#LsendLoop.debug("got aborted while sleeping");
224
+ resolve();
225
+ };
226
+ signal.addEventListener("abort", onAbort);
227
+ this.#awakeSendLoop = () => {
228
+ this.#LsendLoop.debug("got awaken");
229
+ resolve();
230
+ signal.removeEventListener("abort", onAbort);
231
+ };
232
+ });
233
+ }
234
+ const msg_id = this.state.nextMessageId();
235
+ const seqno = this.state.nextSeqNo(true);
236
+ let message = {
237
+ _: "message",
238
+ msg_id,
239
+ seqno,
240
+ body: pendingMessage.body,
241
+ };
242
+ this.#LsendLoop.debug("msg_id =", msg_id, "seqno =", seqno);
243
+ if (this.#toAcknowledge.length) {
244
+ const msg_ids = this.#toAcknowledge.splice(0, 8192);
245
+ this.#LsendLoop.debug("acknowledging", msg_ids.length, "message(s) while sending this one");
246
+ const ack = {
247
+ _: "message",
248
+ msg_id: this.state.nextMessageId(),
249
+ seqno: this.state.nextSeqNo(false),
250
+ body: Mtproto.serializeObject({ _: "msgs_ack", msg_ids }),
251
+ };
252
+ this.#LsendLoop.debug("msgs_ack msg_id =", ack.msg_id, "seqno =", seqno);
253
+ this.#pendingAcks.set(ack.msg_id, msg_ids);
254
+ message = {
255
+ _: "message",
256
+ msg_id: this.state.nextMessageId(),
257
+ seqno: this.state.nextSeqNo(false),
258
+ body: {
259
+ _: "msg_container",
260
+ messages: [message, ack],
261
+ },
262
+ };
263
+ this.#LsendLoop.debug("container msg_id =", message.msg_id, "seqno =", message.seqno);
264
+ }
265
+ try {
266
+ const payload = await this.#encryptMessage(message);
267
+ await this.transport.transport.send(payload);
268
+ pendingMessage.promiseWithResolvers.resolve(msg_id);
269
+ }
270
+ catch (err) {
271
+ pendingMessage.promiseWithResolvers.reject(err);
272
+ return;
273
+ }
274
+ this.#LsendLoop.out(message);
275
+ this.#sentMessages.add(msg_id);
276
+ if (!(message.body instanceof Uint8Array)) {
277
+ const msg_ids = message.body.messages.map((v) => v.msg_id);
278
+ this.#LsendLoop.debug("sent container", message.msg_id, "with messages", ...msg_ids);
279
+ this.#containers.set(message.msg_id, msg_ids);
280
+ }
281
+ else {
282
+ this.#LsendLoop.debug("sent message", message.msg_id);
209
283
  }
210
284
  }
211
- #receiveLoopActive = false;
212
- async #receiveLoop() {
213
- this.#receiveLoopActive = true;
285
+ //// RECEIVE LOOP ////
286
+ #receiveLoop = new AbortableLoop(this.#receiveLoopBody.bind(this), (err) => {
287
+ this.#LreceiveLoop.error("unhandled receive loop error:", err);
288
+ });
289
+ async #receiveLoopBody(loop) {
290
+ let message;
214
291
  try {
215
- while (this.connected) {
216
- let message;
217
- try {
218
- message = await this.#receive();
219
- }
220
- catch (err) {
221
- this.#L.error("failed to receive message:", err);
222
- if (!this.connected) {
223
- break;
224
- }
225
- else {
226
- continue;
227
- }
228
- }
229
- try {
230
- if (message.body instanceof Uint8Array) {
231
- this.#onMessage(message.msg_id, message.body);
232
- }
233
- else {
234
- this.#onMessageContainer(message.msg_id, message.body);
235
- }
236
- }
237
- catch (err) {
238
- this.#L.error("failed to handle message:", err);
239
- }
292
+ message = await this.#receive();
293
+ }
294
+ catch (err) {
295
+ this.#LreceiveLoop.error("failed to receive message:", err);
296
+ if (!this.connected) {
297
+ this.#LreceiveLoop.debug("aborting as not connected");
298
+ loop.abort();
299
+ return;
300
+ }
301
+ else {
302
+ return;
240
303
  }
241
304
  }
242
- finally {
243
- this.#receiveLoopActive = false;
305
+ try {
306
+ if (message.body instanceof Uint8Array) {
307
+ this.#onMessage(message.msg_id, message.body, null);
308
+ }
309
+ else {
310
+ this.#onMessageContainer(message.msg_id, message.body);
311
+ }
312
+ }
313
+ catch (err) {
314
+ this.#LreceiveLoop.error("failed to handle message:", err);
244
315
  }
245
316
  }
246
317
  //// RECEIVE LOOP HANDLERS ////
247
- async #onMessage(msgId, body) {
318
+ async #onMessage(msgId, body, containerId) {
319
+ this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.length, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
320
+ const logger = this.#LreceiveLoop.branch(msgId + "");
248
321
  let reader = new TLReader(body);
249
322
  let id = reader.readInt32(false);
250
323
  if (id === GZIP_PACKED) {
324
+ logger.debug("unpacking compressed body");
251
325
  reader = new TLReader(await gunzip(reader.readBytes()));
252
326
  id = reader.readInt32(false);
253
327
  }
254
328
  if (id === RPC_RESULT) {
255
- this.#onRpcResult(msgId, reader.buffer);
329
+ this.#onRpcResult(msgId, reader.buffer, logger);
256
330
  return;
257
331
  }
258
332
  if (!Mtproto.schema.identifierToName[id]) {
333
+ logger.debug("identified body as a non-MTProto constructor");
259
334
  reader.unreadInt32();
260
335
  this.handlers.onUpdate?.(reader.buffer);
261
336
  return;
@@ -266,10 +341,10 @@ export class SessionEncrypted extends Session {
266
341
  type = await Mtproto.deserializeType(X, reader);
267
342
  }
268
343
  catch (err) {
269
- this.#L.error("failed to deserialize MTProto type:", err);
344
+ logger.error("failed to deserialize MTProto type:", err);
270
345
  return;
271
346
  }
272
- this.#L.debug("received", repr(type));
347
+ logger.debug("received", repr(type));
273
348
  if (Mtproto.is("new_session_created", type)) {
274
349
  this.#onNewSessionCreated(msgId, type);
275
350
  }
@@ -280,24 +355,26 @@ export class SessionEncrypted extends Session {
280
355
  this.#onBadServerSalt(type);
281
356
  }
282
357
  else if (Mtproto.is("bad_msg_notification", type)) {
283
- await this.#onBadMsgNotification(msgId, type);
358
+ await this.#onBadMsgNotification(msgId, type, logger);
284
359
  }
285
360
  else if (Mtproto.is("msg_detailed_info", type)) {
286
- this.#onMsgDetailedInfo(type);
361
+ this.#onMsgDetailedInfo(type, logger);
287
362
  }
288
363
  else if (Mtproto.is("msg_new_detailed_info", type)) {
289
- this.#onMsgNewDetailedInfo(type);
364
+ this.#onMsgNewDetailedInfo(type, logger);
290
365
  }
291
366
  else {
292
- this.#L.debug(`unhandled MTProto type: ${repr(type)}`);
367
+ logger.warning(`unhandled MTProto type: ${repr(type)}`);
293
368
  }
294
369
  }
295
- async #onRpcResult(msgId, body) {
370
+ async #onRpcResult(msgId, body, logger) {
371
+ logger.debug("received rpc_result");
296
372
  this.#toAcknowledge.push(msgId);
297
373
  let reader = new TLReader(body);
298
374
  const reqMsgId = reader.readInt64();
299
375
  let id = reader.readInt32(false);
300
376
  if (id === GZIP_PACKED) {
377
+ logger.debug("unpacking compressed rpc_result");
301
378
  reader = new TLReader(await gunzip(reader.readBytes()));
302
379
  id = reader.readInt32(false);
303
380
  reader.unreadInt32();
@@ -306,6 +383,7 @@ export class SessionEncrypted extends Session {
306
383
  reader.unreadInt32();
307
384
  }
308
385
  if (id === RPC_ERROR) {
386
+ logger.debug("received rpc_error from message", msgId);
309
387
  const error = await Mtproto.deserializeType("rpc_error", reader);
310
388
  this.handlers.onRpcError?.(reqMsgId, error);
311
389
  }
@@ -313,13 +391,15 @@ export class SessionEncrypted extends Session {
313
391
  this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
314
392
  }
315
393
  }
316
- #onMsgDetailedInfo(msgDetailedInfo) {
394
+ #onMsgDetailedInfo(msgDetailedInfo, logger) {
395
+ logger.debug("scheduling the acknowledgement of", msgDetailedInfo.answer_msg_id, "because of", msgDetailedInfo._);
317
396
  this.#toAcknowledge.push(msgDetailedInfo.answer_msg_id);
318
397
  }
319
- #onMsgNewDetailedInfo(msgNewDetailedInfo) {
398
+ #onMsgNewDetailedInfo(msgNewDetailedInfo, logger) {
399
+ logger.debug("scheduling the acknowledgement of", msgNewDetailedInfo.answer_msg_id, "because of", msgNewDetailedInfo._);
320
400
  this.#toAcknowledge.push(msgNewDetailedInfo.answer_msg_id);
321
401
  }
322
- async #onBadMsgNotification(msgId, badMsgNotification) {
402
+ async #onBadMsgNotification(msgId, badMsgNotification, logger) {
323
403
  let low = false;
324
404
  switch (badMsgNotification.error_code) {
325
405
  case 16: // message ID too low
@@ -329,11 +409,12 @@ export class SessionEncrypted extends Session {
329
409
  this.state.timeDifference = Math.abs(toUnixTimestamp(new Date()) - Number(msgId >> 32n));
330
410
  if (!low) {
331
411
  this.state.timeDifference = -this.state.timeDifference;
412
+ logger.debug("resetting time difference to", -this.state.timeDifference, "because the ID of the message", badMsgNotification.bad_msg_id, "was too high");
332
413
  await this.#invalidateSession("message ID too high");
333
414
  return;
334
415
  }
335
416
  else {
336
- this.#L.debug("message ID too low, resending message");
417
+ logger.debug("resending message", badMsgNotification.bad_msg_id, "because its ID was too low");
337
418
  }
338
419
  break;
339
420
  case 48: // bad server salt
@@ -354,7 +435,7 @@ export class SessionEncrypted extends Session {
354
435
  this.#toAcknowledge.push(msgId);
355
436
  const pendingPing = this.#pendingPings.get(pong.msg_id);
356
437
  if (pendingPing) {
357
- pendingPing.resolve(pong);
438
+ pendingPing.promiseWithResolvers.resolve(pong);
358
439
  this.#pendingPings.delete(pong.msg_id);
359
440
  }
360
441
  else {
@@ -367,9 +448,10 @@ export class SessionEncrypted extends Session {
367
448
  this.#toAcknowledge.push(msgId);
368
449
  }
369
450
  #onMessageContainer(msgId, msgContainer) {
451
+ this.#LreceiveLoop.debug("received container with ID", msgId, "and", msgContainer.messages.length, "message(s)");
370
452
  for (const message of msgContainer.messages) {
371
453
  if (message.body instanceof Uint8Array) {
372
- this.#onMessage(message.msg_id, message.body);
454
+ this.#onMessage(message.msg_id, message.body, msgId);
373
455
  }
374
456
  else {
375
457
  this.#onMessageContainer(msgId, message.body);
@@ -378,49 +460,30 @@ export class SessionEncrypted extends Session {
378
460
  }
379
461
  //// PING LOOP ////
380
462
  #pingInterval = 56 * SECOND;
381
- #startPingLoop() {
382
- drop(this.#pingLoop());
383
- }
384
- #pingLoopAbortController;
385
- #LpingLoop;
386
- async #pingLoop() {
387
- this.#pingLoopAbortController?.abort();
388
- const controller = this.#pingLoopAbortController = new AbortController();
463
+ #pingLoop = new AbortableLoop(this.#pingLoopBody.bind(this), (err) => {
464
+ this.#LpingLoop.error(err);
465
+ });
466
+ async #pingLoopBody(_loop, signal) {
389
467
  let timeElapsed = 0;
390
- while (this.connected) {
391
- try {
392
- await delay(Math.max(0, this.#pingInterval - timeElapsed), { signal: controller.signal });
393
- if (!this.connected) {
394
- continue;
395
- }
396
- controller.signal.throwIfAborted();
397
- const then = Date.now();
398
- try {
399
- await this.#sendPingDelayDisconnect(this.#pingInterval / SECOND + 15);
400
- }
401
- finally {
402
- timeElapsed = Date.now() - then;
403
- }
404
- controller.signal.throwIfAborted();
405
- }
406
- catch (err) {
407
- if (err instanceof DOMException && err.name === "AbortError") {
408
- break;
409
- }
410
- else if (!this.connected) {
411
- break;
412
- }
413
- this.#LpingLoop.error(err);
414
- }
468
+ await delay(Math.max(0, this.#pingInterval - timeElapsed), { signal });
469
+ if (!this.connected) {
470
+ return;
471
+ }
472
+ signal.throwIfAborted();
473
+ const then = Date.now();
474
+ try {
475
+ await this.#sendPingDelayDisconnect(this.#pingInterval / SECOND + 15);
476
+ }
477
+ finally {
478
+ timeElapsed = Date.now() - then;
415
479
  }
480
+ signal.throwIfAborted();
416
481
  }
417
482
  async #sendPingDelayDisconnect(disconnect_delay) {
418
483
  const ping_id = getRandomId();
419
484
  const call = { _: "ping_delay_disconnect", ping_id, disconnect_delay };
420
485
  const messageId = await this.send(Mtproto.serializeObject(call));
421
- await new Promise((resolve, reject) => {
422
- this.#pendingPings.set(messageId, { call, resolve, reject });
423
- });
486
+ this.#pendingPings.set(messageId, { call, promiseWithResolvers: Promise.withResolvers() });
424
487
  }
425
488
  async #resendPendingPing(pendingPing) {
426
489
  try {
@@ -428,7 +491,7 @@ export class SessionEncrypted extends Session {
428
491
  this.#pendingPings.set(messageId, pendingPing);
429
492
  }
430
493
  catch (err) {
431
- pendingPing.reject(err);
494
+ pendingPing.promiseWithResolvers.reject(err);
432
495
  }
433
496
  }
434
497
  }