@mtkruto/node 0.1.0 → 0.1.101

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 (241) hide show
  1. package/esm/0_deps.d.ts +4 -3
  2. package/esm/0_deps.js +4 -3
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/0_message.js +3 -9
  6. package/esm/client/3_types.d.ts +2 -0
  7. package/esm/client/4_client.d.ts +19 -3
  8. package/esm/client/4_client.js +209 -68
  9. package/esm/connection/1_connection_web_socket.js +5 -2
  10. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.js +1 -0
  11. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.d.ts +2 -0
  12. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.js +24 -0
  13. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.d.ts +2 -0
  14. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.js +27 -0
  15. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/mod.d.ts +1 -0
  16. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/mod.js +21 -0
  17. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/util.d.ts +13 -0
  18. package/esm/deps/deno.land/std@0.203.0/crypto/_fnv/util.js +48 -0
  19. package/esm/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.d.ts +125 -0
  20. package/esm/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.js +3337 -0
  21. package/esm/deps/deno.land/std@0.203.0/crypto/_wasm/mod.d.ts +12 -0
  22. package/esm/deps/deno.land/std@0.203.0/crypto/_wasm/mod.js +39 -0
  23. package/esm/deps/deno.land/std@0.203.0/crypto/crypto.d.ts +157 -0
  24. package/esm/deps/deno.land/std@0.203.0/crypto/crypto.js +266 -0
  25. package/esm/deps/deno.land/std@0.203.0/crypto/keystack.d.ts +4 -0
  26. package/esm/deps/deno.land/std@0.203.0/crypto/keystack.js +6 -0
  27. package/esm/deps/deno.land/std@0.203.0/crypto/mod.d.ts +12 -0
  28. package/esm/deps/deno.land/std@0.203.0/crypto/mod.js +14 -0
  29. package/esm/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.d.ts +28 -0
  30. package/esm/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.js +54 -0
  31. package/esm/deps/deno.land/std@0.203.0/crypto/to_hash_string.d.ts +19 -0
  32. package/esm/deps/deno.land/std@0.203.0/crypto/to_hash_string.js +31 -0
  33. package/esm/deps/deno.land/std@0.203.0/crypto/unstable/keystack.d.ts +46 -0
  34. package/esm/deps/deno.land/std@0.203.0/crypto/unstable/keystack.js +149 -0
  35. package/esm/deps/deno.land/std@0.203.0/encoding/_util.d.ts +1 -0
  36. package/esm/deps/deno.land/std@0.203.0/encoding/_util.js +26 -0
  37. package/esm/deps/deno.land/std@0.203.0/encoding/base64.d.ts +23 -0
  38. package/{script/deps/deno.land/std@0.201.0 → esm/deps/deno.land/std@0.203.0}/encoding/base64.js +23 -18
  39. package/esm/deps/deno.land/std@0.203.0/encoding/base64url.d.ts +24 -0
  40. package/esm/deps/deno.land/std@0.203.0/encoding/base64url.js +80 -0
  41. package/esm/deps/deno.land/std@0.203.0/encoding/hex.d.ts +18 -0
  42. package/esm/deps/deno.land/std@0.203.0/encoding/hex.js +115 -0
  43. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.js +1 -1
  44. package/{script/deps/deno.land/x/tgcrypto@0.2.1 → esm/deps/deno.land/x/tgcrypto@0.3.3}/mod.d.ts +2 -6
  45. package/esm/deps/deno.land/x/tgcrypto@0.3.3/mod.js +164 -0
  46. package/esm/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +324 -0
  47. package/esm/transport/0_obfuscation.js +1 -1
  48. package/esm/transport/0_transport.js +2 -2
  49. package/esm/types/3_message.js +1 -1
  50. package/esm/utilities/0_bigint.d.ts +1 -0
  51. package/esm/utilities/0_bigint.js +1 -0
  52. package/esm/utilities/0_crypto.d.ts +1 -2
  53. package/esm/utilities/0_crypto.js +3 -12
  54. package/esm/utilities/0_queue.js +1 -1
  55. package/package.json +1 -1
  56. package/script/0_deps.d.ts +4 -3
  57. package/script/0_deps.js +7 -6
  58. package/script/4_constants.d.ts +1 -1
  59. package/script/4_constants.js +1 -1
  60. package/script/client/0_message.js +2 -8
  61. package/script/client/3_types.d.ts +2 -0
  62. package/script/client/4_client.d.ts +19 -3
  63. package/script/client/4_client.js +208 -66
  64. package/script/connection/1_connection_web_socket.js +5 -2
  65. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.js +1 -0
  66. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.d.ts +2 -0
  67. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.js +29 -0
  68. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.d.ts +2 -0
  69. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.js +32 -0
  70. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/mod.d.ts +1 -0
  71. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/mod.js +25 -0
  72. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/util.d.ts +13 -0
  73. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/util.js +54 -0
  74. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.d.ts +125 -0
  75. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.js +3345 -0
  76. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/mod.d.ts +12 -0
  77. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/mod.js +44 -0
  78. package/script/deps/deno.land/std@0.203.0/crypto/crypto.d.ts +157 -0
  79. package/script/deps/deno.land/std@0.203.0/crypto/crypto.js +292 -0
  80. package/script/deps/deno.land/std@0.203.0/crypto/keystack.d.ts +4 -0
  81. package/script/deps/deno.land/std@0.203.0/crypto/keystack.js +22 -0
  82. package/script/deps/deno.land/std@0.203.0/crypto/mod.d.ts +12 -0
  83. package/script/deps/deno.land/std@0.203.0/crypto/mod.js +30 -0
  84. package/script/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.d.ts +28 -0
  85. package/script/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.js +58 -0
  86. package/script/deps/deno.land/std@0.203.0/crypto/to_hash_string.d.ts +19 -0
  87. package/script/deps/deno.land/std@0.203.0/crypto/to_hash_string.js +35 -0
  88. package/script/deps/deno.land/std@0.203.0/crypto/unstable/keystack.d.ts +46 -0
  89. package/script/deps/deno.land/std@0.203.0/crypto/unstable/keystack.js +176 -0
  90. package/script/deps/deno.land/std@0.203.0/encoding/_util.d.ts +1 -0
  91. package/script/deps/deno.land/std@0.203.0/encoding/_util.js +30 -0
  92. package/script/deps/deno.land/std@0.203.0/encoding/base64.d.ts +23 -0
  93. package/{esm/deps/deno.land/std@0.201.0 → script/deps/deno.land/std@0.203.0}/encoding/base64.js +28 -13
  94. package/script/deps/deno.land/std@0.203.0/encoding/base64url.d.ts +24 -0
  95. package/script/deps/deno.land/std@0.203.0/encoding/base64url.js +108 -0
  96. package/script/deps/deno.land/std@0.203.0/encoding/hex.d.ts +18 -0
  97. package/script/deps/deno.land/std@0.203.0/encoding/hex.js +122 -0
  98. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.js +1 -1
  99. package/{esm/deps/deno.land/x/tgcrypto@0.2.1 → script/deps/deno.land/x/tgcrypto@0.3.3}/mod.d.ts +2 -6
  100. package/script/deps/deno.land/x/tgcrypto@0.3.3/mod.js +177 -0
  101. package/script/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +326 -0
  102. package/script/transport/0_obfuscation.js +1 -1
  103. package/script/transport/0_transport.js +2 -2
  104. package/script/types/3_message.js +1 -1
  105. package/script/utilities/0_bigint.d.ts +1 -0
  106. package/script/utilities/0_bigint.js +1 -0
  107. package/script/utilities/0_crypto.d.ts +1 -2
  108. package/script/utilities/0_crypto.js +2 -11
  109. package/script/utilities/0_queue.js +1 -1
  110. package/esm/deps/deno.land/std@0.201.0/encoding/base64.d.ts +0 -11
  111. package/esm/deps/deno.land/x/tgcrypto@0.2.1/mod.js +0 -81
  112. package/esm/deps/deno.land/x/tgcrypto@0.2.1/tgcrypto.js +0 -991
  113. package/script/deps/deno.land/std@0.201.0/encoding/base64.d.ts +0 -11
  114. package/script/deps/deno.land/x/tgcrypto@0.2.1/mod.js +0 -95
  115. package/script/deps/deno.land/x/tgcrypto@0.2.1/tgcrypto.js +0 -993
  116. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.d.ts +0 -0
  117. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.js +0 -0
  118. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.d.ts +0 -0
  119. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.js +0 -0
  120. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.d.ts +0 -0
  121. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.js +0 -0
  122. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.d.ts +0 -0
  123. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.js +0 -0
  124. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.d.ts +0 -0
  125. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.js +0 -0
  126. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.d.ts +0 -0
  127. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.js +0 -0
  128. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.d.ts +0 -0
  129. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.js +0 -0
  130. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.d.ts +0 -0
  131. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.js +0 -0
  132. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.d.ts +1 -1
  133. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.d.ts +0 -0
  134. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.js +0 -0
  135. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.d.ts +0 -0
  136. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.js +0 -0
  137. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.d.ts +0 -0
  138. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.js +0 -0
  139. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.d.ts +0 -0
  140. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.js +0 -0
  141. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.d.ts +0 -0
  142. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.js +0 -0
  143. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.d.ts +0 -0
  144. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.js +0 -0
  145. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.d.ts +0 -0
  146. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.js +0 -0
  147. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.d.ts +0 -0
  148. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.js +0 -0
  149. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.d.ts +0 -0
  150. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.js +0 -0
  151. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.d.ts +0 -0
  152. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.js +0 -0
  153. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.d.ts +0 -0
  154. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.js +0 -0
  155. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.d.ts +0 -0
  156. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.js +0 -0
  157. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.d.ts +0 -0
  158. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.js +0 -0
  159. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.d.ts +0 -0
  160. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.js +0 -0
  161. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.d.ts +0 -0
  162. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.js +0 -0
  163. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.d.ts +0 -0
  164. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.js +0 -0
  165. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.d.ts +0 -0
  166. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.js +0 -0
  167. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.d.ts +0 -0
  168. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.js +0 -0
  169. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.d.ts +0 -0
  170. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.js +0 -0
  171. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.d.ts +0 -0
  172. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.js +0 -0
  173. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.d.ts +0 -0
  174. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.js +0 -0
  175. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.d.ts +0 -0
  176. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.js +0 -0
  177. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.d.ts +0 -0
  178. package/esm/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.3}/tgcrypto.d.ts +0 -0
  179. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.d.ts +0 -0
  180. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.js +0 -0
  181. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.d.ts +0 -0
  182. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.js +0 -0
  183. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.d.ts +0 -0
  184. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.js +0 -0
  185. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.d.ts +0 -0
  186. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.js +0 -0
  187. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.d.ts +0 -0
  188. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.js +0 -0
  189. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.d.ts +0 -0
  190. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.js +0 -0
  191. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.d.ts +0 -0
  192. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.js +0 -0
  193. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.d.ts +0 -0
  194. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.js +0 -0
  195. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.d.ts +1 -1
  196. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.d.ts +0 -0
  197. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.js +0 -0
  198. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.d.ts +0 -0
  199. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.js +0 -0
  200. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.d.ts +0 -0
  201. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.js +0 -0
  202. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.d.ts +0 -0
  203. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.js +0 -0
  204. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.d.ts +0 -0
  205. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.js +0 -0
  206. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.d.ts +0 -0
  207. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.js +0 -0
  208. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.d.ts +0 -0
  209. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.js +0 -0
  210. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.d.ts +0 -0
  211. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.js +0 -0
  212. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.d.ts +0 -0
  213. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.js +0 -0
  214. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.d.ts +0 -0
  215. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.js +0 -0
  216. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.d.ts +0 -0
  217. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.js +0 -0
  218. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.d.ts +0 -0
  219. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.js +0 -0
  220. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.d.ts +0 -0
  221. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.js +0 -0
  222. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.d.ts +0 -0
  223. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.js +0 -0
  224. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.d.ts +0 -0
  225. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.js +0 -0
  226. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.d.ts +0 -0
  227. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.js +0 -0
  228. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.d.ts +0 -0
  229. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.js +0 -0
  230. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.d.ts +0 -0
  231. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.js +0 -0
  232. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.d.ts +0 -0
  233. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.js +0 -0
  234. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.d.ts +0 -0
  235. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.js +0 -0
  236. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.d.ts +0 -0
  237. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.js +0 -0
  238. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.d.ts +0 -0
  239. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.js +0 -0
  240. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.d.ts +0 -0
  241. /package/script/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.3}/tgcrypto.d.ts +0 -0
@@ -1,5 +1,6 @@
1
1
  export declare function modExp(a: bigint, b: bigint, n: bigint): bigint;
2
2
  export declare function mod(n: bigint, m: bigint): bigint;
3
+ export declare function mod(n: number, m: number): number;
3
4
  export declare function bigIntFromBuffer(buffer: Uint8Array, little?: boolean, signed?: boolean): bigint;
4
5
  export declare function getRandomBigInt(byteLength: number, little?: boolean, signed?: boolean): bigint;
5
6
  export declare function getRandomId(): bigint;
@@ -16,6 +16,7 @@ export function modExp(a, b, n) {
16
16
  return result;
17
17
  }
18
18
  export function mod(n, m) {
19
+ // @ts-ignore: TODO: do sth
19
20
  return ((n % m) + m) % m;
20
21
  }
21
22
  export function bigIntFromBuffer(buffer, little = true, signed = false) {
@@ -3,6 +3,5 @@ export declare class CTR {
3
3
  iv: Uint8Array;
4
4
  state: Uint8Array;
5
5
  constructor(key: Uint8Array, iv: Uint8Array);
6
- encrypt(data: Uint8Array): Uint8Array;
7
- decrypt(data: Uint8Array): Uint8Array;
6
+ call(data: Uint8Array): Uint8Array;
8
7
  }
@@ -1,4 +1,4 @@
1
- import { ctr256Decrypt, ctr256Encrypt } from "../0_deps.js";
1
+ import { ctr256 } from "../0_deps.js";
2
2
  export class CTR {
3
3
  constructor(key, iv) {
4
4
  Object.defineProperty(this, "key", {
@@ -20,18 +20,9 @@ export class CTR {
20
20
  value: new Uint8Array(1)
21
21
  });
22
22
  }
23
- encrypt(data) {
23
+ call(data) {
24
24
  const v = new Uint8Array(data); // TODO: don't copy
25
- const [iv, state] = ctr256Encrypt(v, this.key, this.iv, this.state);
26
- this.iv = iv;
27
- this.state = state;
28
- return v;
29
- }
30
- decrypt(data) {
31
- const v = new Uint8Array(data); // TODO: don't copy
32
- const [iv, state] = ctr256Decrypt(v, this.key, this.iv, this.state);
33
- this.iv = iv;
34
- this.state = state;
25
+ ctr256(v, this.key, this.iv, this.state);
35
26
  return v;
36
27
  }
37
28
  }
@@ -36,7 +36,7 @@ export class Queue {
36
36
  if (fn !== undefined) {
37
37
  fn()
38
38
  .catch((err) => {
39
- this.d("%o", err);
39
+ this.d("%o", "stack" in err ? err.stack : err);
40
40
  })
41
41
  .finally(() => {
42
42
  this.busy = false;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.1.0",
5
+ "version": "0.1.101",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1,8 +1,9 @@
1
- export * from "./deps/deno.land/std@0.201.0/assert/mod.js";
2
- export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.2.1/mod.js";
1
+ export * from "./deps/deno.land/std@0.203.0/assert/mod.js";
2
+ export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.3/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/gzip/gzip.js";
4
4
  export { Mutex, type MutexInterface } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
6
  import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/main/mod.js";
7
7
  export declare const debug: typeof debug_;
8
- export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.201.0/encoding/base64.js";
8
+ export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.203.0/encoding/base64.js";
9
+ export { crypto } from "./deps/deno.land/std@0.203.0/crypto/mod.js";
package/script/0_deps.js CHANGED
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.base64Encode = exports.base64Decode = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256Encrypt = exports.ctr256Decrypt = void 0;
18
- __exportStar(require("./deps/deno.land/std@0.201.0/assert/mod.js"), exports);
19
- var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.2.1/mod.js");
20
- Object.defineProperty(exports, "ctr256Decrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Decrypt; } });
21
- Object.defineProperty(exports, "ctr256Encrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Encrypt; } });
17
+ exports.crypto = exports.base64Encode = exports.base64Decode = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256 = void 0;
18
+ __exportStar(require("./deps/deno.land/std@0.203.0/assert/mod.js"), exports);
19
+ var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.3.3/mod.js");
20
+ Object.defineProperty(exports, "ctr256", { enumerable: true, get: function () { return mod_js_1.ctr256; } });
22
21
  Object.defineProperty(exports, "factorize", { enumerable: true, get: function () { return mod_js_1.factorize; } });
23
22
  Object.defineProperty(exports, "ige256Decrypt", { enumerable: true, get: function () { return mod_js_1.ige256Decrypt; } });
24
23
  Object.defineProperty(exports, "ige256Encrypt", { enumerable: true, get: function () { return mod_js_1.ige256Encrypt; } });
@@ -33,6 +32,8 @@ Object.defineProperty(exports, "Parser", { enumerable: true, get: function () {
33
32
  const mod_js_3 = require("./deps/raw.githubusercontent.com/MTKruto/debug/main/mod.js");
34
33
  const debug = (v) => (0, mod_js_3.debug)(v);
35
34
  exports.debug = debug;
36
- var base64_js_1 = require("./deps/deno.land/std@0.201.0/encoding/base64.js");
35
+ var base64_js_1 = require("./deps/deno.land/std@0.203.0/encoding/base64.js");
37
36
  Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64_js_1.decode; } });
38
37
  Object.defineProperty(exports, "base64Encode", { enumerable: true, get: function () { return base64_js_1.encode; } });
38
+ var mod_js_4 = require("./deps/deno.land/std@0.203.0/crypto/mod.js");
39
+ Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return mod_js_4.crypto; } });
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.1.0";
8
+ export declare const APP_VERSION = "MTKruto 0.1.101";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.1.0";
83
+ exports.APP_VERSION = "MTKruto 0.1.101";
84
84
  // @ts-ignore: lib
85
85
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -43,14 +43,8 @@ async function encryptMessage(message, authKey, authKeyId, salt, sessionId) {
43
43
  payloadWriter.writeInt32(message.seqNo);
44
44
  payloadWriter.writeInt32(encoded.length);
45
45
  payloadWriter.write(encoded);
46
- payloadWriter.write(new Uint8Array(payloadWriter.buffer.length + 12 % 16 + 12));
47
- let payload = payloadWriter.buffer;
48
- while (true) {
49
- if (payload.length % 16 == 0 && (payload.length) % 4 == 0) {
50
- break;
51
- }
52
- payload = (0, _1_utilities_js_1.concat)(payload, new Uint8Array(1));
53
- }
46
+ payloadWriter.write(new Uint8Array((0, _1_utilities_js_1.mod)(-(payloadWriter.buffer.length + 12), 16) + 12));
47
+ const payload = payloadWriter.buffer;
54
48
  const messageKey = (await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.slice(88, 120), payload))).slice(8, 24);
55
49
  const a = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(messageKey, authKey.slice(0, 36)));
56
50
  const b = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.slice(40, 76), messageKey));
@@ -1,4 +1,5 @@
1
1
  import { MaybePromise } from "../1_utilities.js";
2
+ import { functions, types } from "../2_tl.js";
2
3
  import { CallbackQuery, ChatID, ForceReply, InlineKeyboardMarkup, InlineQuery, Message, MessageEntity, ReplyKeyboardMarkup, ReplyKeyboardRemove } from "../3_types.js";
3
4
  import { With } from "./0_utilities.js";
4
5
  import { ClientPlainParams } from "./2_client_plain.js";
@@ -36,6 +37,7 @@ export interface ClientParams extends ClientPlainParams {
36
37
  * Whether to automatically call `start` with no parameters in the first `invoke` call. Defaults to `true`.
37
38
  */
38
39
  autoStart?: boolean;
40
+ errorHandler?: (err: unknown, function_: types.Type | functions.Function<unknown>, n: number) => MaybePromise<boolean>;
39
41
  }
40
42
  export interface AnswerCallbackQueryParams {
41
43
  /** Text of the answer */
@@ -12,8 +12,9 @@ export declare const getStickerSetName: unique symbol;
12
12
  export declare const handleMigrationError: unique symbol;
13
13
  export declare const getMessageWithReply: unique symbol;
14
14
  export declare const restartAuth: unique symbol;
15
+ export declare class ConnectionError extends Error {
16
+ }
15
17
  export declare class Client extends ClientAbstract {
16
- readonly storage: Storage;
17
18
  readonly apiId: number | null;
18
19
  readonly apiHash: string | null;
19
20
  private auth;
@@ -22,6 +23,8 @@ export declare class Client extends ClientAbstract {
22
23
  private promises;
23
24
  private toAcknowledge;
24
25
  private updateState?;
26
+ private readonly errorHandler?;
27
+ readonly storage: Storage;
25
28
  readonly parseMode: ParseMode;
26
29
  readonly appVersion: string;
27
30
  readonly deviceModel: string;
@@ -38,7 +41,7 @@ export declare class Client extends ClientAbstract {
38
41
  * @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
39
42
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
40
43
  */
41
- constructor(storage?: Storage, apiId?: number | null, apiHash?: string | null, params?: ClientParams);
44
+ constructor(storage: Storage | null, apiId?: number | null, apiHash?: string | null, params?: ClientParams);
42
45
  private propagateConnectionState;
43
46
  private lastPropagatedConnectionState;
44
47
  protected stateChangeHandler: (connected: boolean) => void;
@@ -91,6 +94,7 @@ export declare class Client extends ClientAbstract {
91
94
  start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
92
95
  private receiveLoop;
93
96
  private pingLoop;
97
+ private pingLoopStarted;
94
98
  private autoStarted;
95
99
  private lastMsgId;
96
100
  /**
@@ -164,7 +168,9 @@ export declare class Client extends ClientAbstract {
164
168
  *
165
169
  * @param fileId The identifier of the file to download.
166
170
  */
167
- download(fileId: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
171
+ download(fileId: string, params?: {
172
+ chunkSize?: number;
173
+ }): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
168
174
  [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
169
175
  /**
170
176
  * Forward multiple messages.
@@ -212,6 +218,16 @@ export declare class Client extends ClientAbstract {
212
218
  * @param messageThreadId The thread to send the chat action to.
213
219
  */
214
220
  sendChatAction(chatId: ChatID, action_: ChatAction, messageThreadId?: number): Promise<void>;
221
+ /**
222
+ * Upload a file.
223
+ *
224
+ * @param contents The contents of the file.
225
+ */
226
+ upload(contents: Uint8Array, params?: {
227
+ fileName?: string;
228
+ chunkSize?: number;
229
+ signal?: AbortSignal | null;
230
+ }): Promise<types.InputFile | types.InputFileBig>;
215
231
  setMyCommands(commands: BotCommand[], params?: {
216
232
  languageCode?: string;
217
233
  scope?: BotCommandScope;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = exports.restartAuth = exports.getMessageWithReply = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
3
+ exports.Client = exports.ConnectionError = exports.restartAuth = exports.getMessageWithReply = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
4
4
  const _0_deps_js_1 = require("../0_deps.js");
5
5
  const _1_utilities_js_1 = require("../1_utilities.js");
6
6
  const _2_tl_js_1 = require("../2_tl.js");
@@ -20,11 +20,15 @@ const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
20
20
  const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
21
21
  const dAuth = (0, _0_deps_js_1.debug)("Client/authorize");
22
22
  const dRecv = (0, _0_deps_js_1.debug)("Client/receiveLoop");
23
+ const dUpload = (0, _0_deps_js_1.debug)("Client/upload");
23
24
  exports.getEntity = Symbol();
24
25
  exports.getStickerSetName = Symbol();
25
26
  exports.handleMigrationError = Symbol();
26
27
  exports.getMessageWithReply = Symbol();
27
28
  exports.restartAuth = Symbol();
29
+ class ConnectionError extends Error {
30
+ }
31
+ exports.ConnectionError = ConnectionError;
28
32
  class Client extends _1_client_abstract_js_1.ClientAbstract {
29
33
  /**
30
34
  * Constructs the client.
@@ -33,14 +37,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
33
37
  * @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
34
38
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
35
39
  */
36
- constructor(storage = new _3_storage_js_1.StorageMemory(), apiId = 0, apiHash = "", params) {
40
+ constructor(storage, apiId = 0, apiHash = "", params) {
37
41
  super(params);
38
- Object.defineProperty(this, "storage", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: storage
43
- });
44
42
  Object.defineProperty(this, "apiId", {
45
43
  enumerable: true,
46
44
  configurable: true,
@@ -89,6 +87,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
89
87
  writable: true,
90
88
  value: void 0
91
89
  });
90
+ Object.defineProperty(this, "errorHandler", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: void 0
95
+ });
96
+ Object.defineProperty(this, "storage", {
97
+ enumerable: true,
98
+ configurable: true,
99
+ writable: true,
100
+ value: void 0
101
+ });
92
102
  Object.defineProperty(this, "parseMode", {
93
103
  enumerable: true,
94
104
  configurable: true,
@@ -192,6 +202,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
192
202
  writable: true,
193
203
  value: null
194
204
  });
205
+ Object.defineProperty(this, "pingLoopStarted", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: false
210
+ });
195
211
  Object.defineProperty(this, "autoStarted", {
196
212
  enumerable: true,
197
213
  configurable: true,
@@ -231,6 +247,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
231
247
  writable: true,
232
248
  value: _3_types_js_2.skip
233
249
  });
250
+ this.storage = storage ?? new _3_storage_js_1.StorageMemory();
234
251
  this.parseMode = params?.parseMode ?? null;
235
252
  this.appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
236
253
  this.deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
@@ -240,6 +257,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
240
257
  this.systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
241
258
  this.publicKeys = params?.publicKeys;
242
259
  this.autoStart = params?.autoStart ?? true;
260
+ this.errorHandler = params?.errorHandler;
243
261
  }
244
262
  propagateConnectionState(connectionState) {
245
263
  return this.handle({ connectionState }, _0_utilities_js_1.resolve);
@@ -309,7 +327,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
309
327
  }
310
328
  d("encrypted client connected");
311
329
  (0, _1_utilities_js_1.drop)(this.receiveLoop());
312
- (0, _1_utilities_js_1.drop)(this.pingLoop());
313
330
  }
314
331
  finally {
315
332
  release();
@@ -551,7 +568,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
551
568
  }
552
569
  async receiveLoop() {
553
570
  if (!this.auth || !this.transport) {
554
- throw new Error("Not connected");
571
+ throw new ConnectionError("Not connected");
555
572
  }
556
573
  while (this.connected) {
557
574
  try {
@@ -579,6 +596,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
579
596
  if (body instanceof _2_tl_js_1.types._TypeUpdates || body instanceof _2_tl_js_1.types._TypeUpdate) {
580
597
  this.processUpdatesQueue.add(() => this.processUpdates(body));
581
598
  }
599
+ else if (body instanceof _2_tl_js_1.types.NewSessionCreated) {
600
+ this.state.salt = body.serverSalt;
601
+ }
582
602
  else if (message.body instanceof _2_tl_js_1.RPCResult) {
583
603
  let result = message.body.result;
584
604
  if (result instanceof _2_tl_js_1.types.GZIPPacked) {
@@ -642,10 +662,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
642
662
  (0, _1_utilities_js_1.drop)(this.recoverUpdateGap("deserialize"));
643
663
  }
644
664
  else {
645
- throw err;
665
+ dRecv("uncaught error: %o", err);
646
666
  }
647
667
  }
648
668
  }
669
+ if (!this.connected) {
670
+ for (const { reject } of this.promises.values()) {
671
+ reject(new ConnectionError("Connection was closed"));
672
+ }
673
+ }
674
+ else {
675
+ (0, _1_utilities_js_1.UNREACHABLE)();
676
+ }
649
677
  }
650
678
  async pingLoop() {
651
679
  while (this.connected) {
@@ -664,41 +692,61 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
664
692
  await this.start();
665
693
  }
666
694
  else {
667
- throw new Error("Not connected");
695
+ throw new ConnectionError("Not connected");
668
696
  }
669
697
  }
670
698
  if (!this.auth || !this.transport) {
671
699
  (0, _1_utilities_js_1.UNREACHABLE)();
672
700
  }
673
- let seqNo = this.state.seqNo * 2;
674
- if (!(function_ instanceof _2_tl_js_1.functions.Ping) && !(function_ instanceof _2_tl_js_1.types.MsgsAck)) {
675
- seqNo++;
676
- this.state.seqNo++;
677
- }
678
- const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
679
- const message = new _2_tl_js_1.Message_(messageId, seqNo, function_);
680
- await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
681
- d("invoked %s", function_.constructor.name);
682
- if (noWait) {
683
- return;
684
- }
685
- let result;
686
- try {
687
- result = await new Promise((resolve, reject) => {
688
- this.promises.set(message.id, { resolve, reject });
689
- });
690
- }
691
- catch (err) {
692
- if (err instanceof _4_errors_js_1.AuthKeyUnregistered) {
693
- await this.propagateAuthorizationState(false);
701
+ let n = 1;
702
+ while (true) {
703
+ try {
704
+ let seqNo = this.state.seqNo * 2;
705
+ if (!(function_ instanceof _2_tl_js_1.functions.Ping) && !(function_ instanceof _2_tl_js_1.types.MsgsAck)) {
706
+ seqNo++;
707
+ this.state.seqNo++;
708
+ }
709
+ const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
710
+ const message = new _2_tl_js_1.Message_(messageId, seqNo, function_);
711
+ await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
712
+ d("invoked %s", function_.constructor.name);
713
+ if (noWait) {
714
+ return;
715
+ }
716
+ let result;
717
+ try {
718
+ result = await new Promise((resolve, reject) => {
719
+ this.promises.set(message.id, { resolve, reject });
720
+ });
721
+ }
722
+ catch (err) {
723
+ if (err instanceof _4_errors_js_1.AuthKeyUnregistered) {
724
+ await this.propagateAuthorizationState(false);
725
+ }
726
+ throw err;
727
+ }
728
+ if (result instanceof _2_tl_js_1.types.BadServerSalt) {
729
+ return await this.invoke(function_);
730
+ }
731
+ else {
732
+ if (!this.pingLoopStarted) {
733
+ (0, _1_utilities_js_1.drop)(this.pingLoop());
734
+ this.pingLoopStarted = true;
735
+ }
736
+ return result;
737
+ }
738
+ }
739
+ catch (err) {
740
+ if (this.errorHandler === undefined) {
741
+ throw err;
742
+ }
743
+ if (this.errorHandler !== undefined && await this.errorHandler(err, function_, n++)) {
744
+ continue;
745
+ }
746
+ else {
747
+ throw err;
748
+ }
694
749
  }
695
- throw err;
696
- }
697
- if (result instanceof _2_tl_js_1.types.BadServerSalt) {
698
- return await this.invoke(function_);
699
- }
700
- else {
701
- return result;
702
750
  }
703
751
  }
704
752
  /**
@@ -1308,29 +1356,30 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1308
1356
  const messages = await this.getMessages(chatId, [messageId]);
1309
1357
  return messages[0] ?? null;
1310
1358
  }
1311
- async *downloadInner(location, dcId) {
1312
- let client = null;
1313
- if (dcId != undefined && dcId != this.dcId) {
1314
- const exportedAuth = await this.invoke(new _2_tl_js_1.functions.AuthExportAuthorization({ dcId }));
1315
- client = new Client(new _3_storage_js_1.StorageMemory(), this.apiId, this.apiHash, {
1316
- transportProvider: this.transportProvider,
1317
- appVersion: this.appVersion,
1318
- deviceModel: this.deviceModel,
1319
- langCode: this.langCode,
1320
- langPack: this.langPack,
1321
- systemLangCode: this.systemLangCode,
1322
- systemVersion: this.systemVersion,
1323
- cdn: true,
1324
- });
1325
- let dc = String(dcId);
1326
- if (this.dcId < 0) {
1327
- dc += "-test";
1328
- }
1329
- await client.setDc(dc);
1330
- await client.connect();
1331
- await client.authorize(exportedAuth);
1332
- }
1333
- const limit = 1024 * 1024;
1359
+ async *downloadInner(location, dcId, params) {
1360
+ const chunkSize = params?.chunkSize ?? 1024 * 1024;
1361
+ if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
1362
+ throw new Error("chunkSize must be divisible by 1024");
1363
+ }
1364
+ const exportedAuth = await this.invoke(new _2_tl_js_1.functions.AuthExportAuthorization({ dcId }));
1365
+ const client = new Client(new _3_storage_js_1.StorageMemory(), this.apiId, this.apiHash, {
1366
+ transportProvider: this.transportProvider,
1367
+ appVersion: this.appVersion,
1368
+ deviceModel: this.deviceModel,
1369
+ langCode: this.langCode,
1370
+ langPack: this.langPack,
1371
+ systemLangCode: this.systemLangCode,
1372
+ systemVersion: this.systemVersion,
1373
+ cdn: true,
1374
+ });
1375
+ let dc = String(dcId);
1376
+ if (this.dcId < 0) {
1377
+ dc += "-test";
1378
+ }
1379
+ await client.setDc(dc);
1380
+ await client.connect();
1381
+ await client.authorize(exportedAuth);
1382
+ const limit = chunkSize;
1334
1383
  let offset = 0n;
1335
1384
  while (true) {
1336
1385
  const file = await (client ?? this).invoke(new _2_tl_js_1.functions.UploadGetFile({ location, offset, limit }));
@@ -1353,14 +1402,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1353
1402
  *
1354
1403
  * @param fileId The identifier of the file to download.
1355
1404
  */
1356
- async download(fileId) {
1405
+ async download(fileId, params) {
1357
1406
  const fileId_ = _3_types_js_1.FileID.decode(fileId);
1358
1407
  switch (fileId_.fileType) {
1359
1408
  case _3_types_js_1.FileType.ChatPhoto: {
1360
1409
  const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
1361
1410
  const peer = await this.getInputPeer(fileId_.params.chatId);
1362
1411
  const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
1363
- return this.downloadInner(location);
1412
+ return this.downloadInner(location, fileId_.dcId, params);
1364
1413
  }
1365
1414
  case _3_types_js_1.FileType.Photo: {
1366
1415
  if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
@@ -1372,7 +1421,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1372
1421
  fileReference: fileId_.params.fileReference,
1373
1422
  thumbSize: fileId_.params.thumbnailSize,
1374
1423
  });
1375
- return this.downloadInner(location);
1424
+ return this.downloadInner(location, fileId_.dcId, params);
1376
1425
  }
1377
1426
  default:
1378
1427
  (0, _1_utilities_js_1.UNREACHABLE)();
@@ -1610,6 +1659,99 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1610
1659
  }
1611
1660
  await this.invoke(new _2_tl_js_1.functions.MessagesSetTyping({ peer: await this.getInputPeer(chatId), action, topMsgId: messageThreadId }));
1612
1661
  }
1662
+ /**
1663
+ * Upload a file.
1664
+ *
1665
+ * @param contents The contents of the file.
1666
+ */
1667
+ async upload(contents, params) {
1668
+ const isBig = contents.length > 1048576; // 10 MB
1669
+ const chunkSize = params?.chunkSize ?? 512 * 1024;
1670
+ if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
1671
+ throw new Error("chunkSize must be divisible by 1024");
1672
+ }
1673
+ const signal = params?.signal;
1674
+ dUpload("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
1675
+ const fileId = (0, _1_utilities_js_1.getRandomId)();
1676
+ const name = params?.fileName ?? fileId.toString();
1677
+ const client = new Client(this.storage, this.apiId, this.apiHash, {
1678
+ transportProvider: this.transportProvider,
1679
+ appVersion: this.appVersion,
1680
+ deviceModel: this.deviceModel,
1681
+ langCode: this.langCode,
1682
+ langPack: this.langPack,
1683
+ systemLangCode: this.systemLangCode,
1684
+ systemVersion: this.systemVersion,
1685
+ cdn: true,
1686
+ initialDc: this.initialDc,
1687
+ autoStart: false,
1688
+ });
1689
+ signal?.addEventListener("abort", () => (0, _1_utilities_js_1.drop)(client.disconnect()));
1690
+ client.state.salt = this.state.salt;
1691
+ await client.connect();
1692
+ let part = 0;
1693
+ const md5sum = await _0_deps_js_1.crypto.subtle.digest("MD5", contents).then((v) => [...new Uint8Array(v)]
1694
+ .map((b) => b.toString(16).padStart(2, "0"))
1695
+ .join(""));
1696
+ const partCount = Math.ceil(contents.length / chunkSize);
1697
+ try {
1698
+ main: for (; part < partCount; part++) {
1699
+ chunk: while (true) {
1700
+ try {
1701
+ const start = part * chunkSize;
1702
+ const end = start + chunkSize;
1703
+ const bytes = contents.slice(start, end);
1704
+ if (bytes.length == 0) {
1705
+ continue main;
1706
+ }
1707
+ if (isBig) {
1708
+ await client.invoke(new _2_tl_js_1.functions.UploadSaveBigFilePart({ fileId, filePart: part, bytes, fileTotalParts: partCount }));
1709
+ }
1710
+ else {
1711
+ await client.invoke(new _2_tl_js_1.functions.UploadSaveFilePart({ fileId, bytes, filePart: part }));
1712
+ }
1713
+ dUpload((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
1714
+ break chunk;
1715
+ }
1716
+ catch (err) {
1717
+ if (signal?.aborted) {
1718
+ break main;
1719
+ }
1720
+ if (err instanceof _4_errors_js_1.FloodWait) {
1721
+ dUpload("got a flood wait of " + err.seconds + " seconds");
1722
+ await new Promise((r) => setTimeout(r, err.seconds * 1000));
1723
+ }
1724
+ else if (err instanceof ConnectionError) {
1725
+ while (true) {
1726
+ try {
1727
+ await new Promise((r) => setTimeout(r, 3000));
1728
+ await client.connect();
1729
+ }
1730
+ catch {
1731
+ if (signal?.aborted) {
1732
+ break main;
1733
+ }
1734
+ }
1735
+ }
1736
+ }
1737
+ else {
1738
+ throw err;
1739
+ }
1740
+ }
1741
+ }
1742
+ }
1743
+ }
1744
+ finally {
1745
+ (0, _1_utilities_js_1.drop)(client.disconnect());
1746
+ }
1747
+ dUpload("uploaded all " + partCount + " chunk(s)");
1748
+ if (isBig) {
1749
+ return new _2_tl_js_1.types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
1750
+ }
1751
+ else {
1752
+ return new _2_tl_js_1.types.InputFile({ id: fileId, name, parts: part, md5Checksum: md5sum });
1753
+ }
1754
+ }
1613
1755
  async setMyCommands(commands, params) {
1614
1756
  await this.invoke(new _2_tl_js_1.functions.BotsSetBotCommands({
1615
1757
  commands: commands.map((v) => new _2_tl_js_1.types.BotCommand(v)),