@mtkruto/node 0.1.100 → 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 (231) 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/esm/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/mod.js +10 -4
  45. package/esm/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +324 -0
  46. package/esm/types/3_message.js +1 -1
  47. package/esm/utilities/0_bigint.d.ts +1 -0
  48. package/esm/utilities/0_bigint.js +1 -0
  49. package/esm/utilities/0_queue.js +1 -1
  50. package/package.json +1 -1
  51. package/script/0_deps.d.ts +4 -3
  52. package/script/0_deps.js +6 -4
  53. package/script/4_constants.d.ts +1 -1
  54. package/script/4_constants.js +1 -1
  55. package/script/client/0_message.js +2 -8
  56. package/script/client/3_types.d.ts +2 -0
  57. package/script/client/4_client.d.ts +19 -3
  58. package/script/client/4_client.js +208 -66
  59. package/script/connection/1_connection_web_socket.js +5 -2
  60. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.js +1 -0
  61. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.d.ts +2 -0
  62. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv32.js +29 -0
  63. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.d.ts +2 -0
  64. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/fnv64.js +32 -0
  65. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/mod.d.ts +1 -0
  66. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/mod.js +25 -0
  67. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/util.d.ts +13 -0
  68. package/script/deps/deno.land/std@0.203.0/crypto/_fnv/util.js +54 -0
  69. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.d.ts +125 -0
  70. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.js +3345 -0
  71. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/mod.d.ts +12 -0
  72. package/script/deps/deno.land/std@0.203.0/crypto/_wasm/mod.js +44 -0
  73. package/script/deps/deno.land/std@0.203.0/crypto/crypto.d.ts +157 -0
  74. package/script/deps/deno.land/std@0.203.0/crypto/crypto.js +292 -0
  75. package/script/deps/deno.land/std@0.203.0/crypto/keystack.d.ts +4 -0
  76. package/script/deps/deno.land/std@0.203.0/crypto/keystack.js +22 -0
  77. package/script/deps/deno.land/std@0.203.0/crypto/mod.d.ts +12 -0
  78. package/script/deps/deno.land/std@0.203.0/crypto/mod.js +30 -0
  79. package/script/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.d.ts +28 -0
  80. package/script/deps/deno.land/std@0.203.0/crypto/timing_safe_equal.js +58 -0
  81. package/script/deps/deno.land/std@0.203.0/crypto/to_hash_string.d.ts +19 -0
  82. package/script/deps/deno.land/std@0.203.0/crypto/to_hash_string.js +35 -0
  83. package/script/deps/deno.land/std@0.203.0/crypto/unstable/keystack.d.ts +46 -0
  84. package/script/deps/deno.land/std@0.203.0/crypto/unstable/keystack.js +176 -0
  85. package/script/deps/deno.land/std@0.203.0/encoding/_util.d.ts +1 -0
  86. package/script/deps/deno.land/std@0.203.0/encoding/_util.js +30 -0
  87. package/script/deps/deno.land/std@0.203.0/encoding/base64.d.ts +23 -0
  88. package/{esm/deps/deno.land/std@0.201.0 → script/deps/deno.land/std@0.203.0}/encoding/base64.js +28 -13
  89. package/script/deps/deno.land/std@0.203.0/encoding/base64url.d.ts +24 -0
  90. package/script/deps/deno.land/std@0.203.0/encoding/base64url.js +108 -0
  91. package/script/deps/deno.land/std@0.203.0/encoding/hex.d.ts +18 -0
  92. package/script/deps/deno.land/std@0.203.0/encoding/hex.js +122 -0
  93. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.js +1 -1
  94. package/script/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/mod.js +10 -4
  95. package/script/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +326 -0
  96. package/script/types/3_message.js +1 -1
  97. package/script/utilities/0_bigint.d.ts +1 -0
  98. package/script/utilities/0_bigint.js +1 -0
  99. package/script/utilities/0_queue.js +1 -1
  100. package/esm/deps/deno.land/std@0.201.0/encoding/base64.d.ts +0 -11
  101. package/esm/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +0 -308
  102. package/script/deps/deno.land/std@0.201.0/encoding/base64.d.ts +0 -11
  103. package/script/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +0 -310
  104. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.d.ts +0 -0
  105. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.js +0 -0
  106. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.d.ts +0 -0
  107. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.js +0 -0
  108. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.d.ts +0 -0
  109. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.js +0 -0
  110. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.d.ts +0 -0
  111. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.js +0 -0
  112. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.d.ts +0 -0
  113. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.js +0 -0
  114. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.d.ts +0 -0
  115. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.js +0 -0
  116. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.d.ts +0 -0
  117. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.js +0 -0
  118. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.d.ts +0 -0
  119. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.js +0 -0
  120. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.d.ts +1 -1
  121. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.d.ts +0 -0
  122. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.js +0 -0
  123. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.d.ts +0 -0
  124. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.js +0 -0
  125. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.d.ts +0 -0
  126. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.js +0 -0
  127. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.d.ts +0 -0
  128. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.js +0 -0
  129. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.d.ts +0 -0
  130. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.js +0 -0
  131. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.d.ts +0 -0
  132. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.js +0 -0
  133. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.d.ts +0 -0
  134. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.js +0 -0
  135. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.d.ts +0 -0
  136. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.js +0 -0
  137. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.d.ts +0 -0
  138. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.js +0 -0
  139. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.d.ts +0 -0
  140. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.js +0 -0
  141. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.d.ts +0 -0
  142. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.js +0 -0
  143. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.d.ts +0 -0
  144. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.js +0 -0
  145. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.d.ts +0 -0
  146. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.js +0 -0
  147. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.d.ts +0 -0
  148. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.js +0 -0
  149. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.d.ts +0 -0
  150. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.js +0 -0
  151. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.d.ts +0 -0
  152. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.js +0 -0
  153. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.d.ts +0 -0
  154. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.js +0 -0
  155. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.d.ts +0 -0
  156. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.js +0 -0
  157. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.d.ts +0 -0
  158. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.js +0 -0
  159. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.d.ts +0 -0
  160. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.js +0 -0
  161. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.d.ts +0 -0
  162. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.js +0 -0
  163. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.d.ts +0 -0
  164. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.js +0 -0
  165. package/esm/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.d.ts +0 -0
  166. package/esm/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/mod.d.ts +0 -0
  167. package/esm/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/tgcrypto.d.ts +0 -0
  168. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.d.ts +0 -0
  169. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_constants.js +0 -0
  170. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.d.ts +0 -0
  171. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_diff.js +0 -0
  172. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.d.ts +0 -0
  173. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/_format.js +0 -0
  174. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.d.ts +0 -0
  175. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert.js +0 -0
  176. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.d.ts +0 -0
  177. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_almost_equals.js +0 -0
  178. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.d.ts +0 -0
  179. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_array_includes.js +0 -0
  180. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.d.ts +0 -0
  181. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_equals.js +0 -0
  182. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.d.ts +0 -0
  183. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_exists.js +0 -0
  184. package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_false.d.ts +1 -1
  185. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.d.ts +0 -0
  186. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater.js +0 -0
  187. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.d.ts +0 -0
  188. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_greater_or_equal.js +0 -0
  189. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.d.ts +0 -0
  190. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_instance_of.js +0 -0
  191. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.d.ts +0 -0
  192. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_is_error.js +0 -0
  193. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.d.ts +0 -0
  194. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less.js +0 -0
  195. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.d.ts +0 -0
  196. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_less_or_equal.js +0 -0
  197. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.d.ts +0 -0
  198. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_match.js +0 -0
  199. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.d.ts +0 -0
  200. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_equals.js +0 -0
  201. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.d.ts +0 -0
  202. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_instance_of.js +0 -0
  203. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.d.ts +0 -0
  204. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_match.js +0 -0
  205. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.d.ts +0 -0
  206. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_not_strict_equals.js +0 -0
  207. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.d.ts +0 -0
  208. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_object_match.js +0 -0
  209. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.d.ts +0 -0
  210. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_rejects.js +0 -0
  211. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.d.ts +0 -0
  212. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_strict_equals.js +0 -0
  213. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.d.ts +0 -0
  214. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_string_includes.js +0 -0
  215. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.d.ts +0 -0
  216. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assert_throws.js +0 -0
  217. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.d.ts +0 -0
  218. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/assertion_error.js +0 -0
  219. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.d.ts +0 -0
  220. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/equal.js +0 -0
  221. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.d.ts +0 -0
  222. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/fail.js +0 -0
  223. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.d.ts +0 -0
  224. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/mod.js +0 -0
  225. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.d.ts +0 -0
  226. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unimplemented.js +0 -0
  227. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.d.ts +0 -0
  228. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/assert/unreachable.js +0 -0
  229. /package/script/deps/deno.land/{std@0.201.0 → std@0.203.0}/fmt/colors.d.ts +0 -0
  230. /package/script/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/mod.d.ts +0 -0
  231. /package/script/deps/deno.land/x/{tgcrypto@0.3.2 → tgcrypto@0.3.3}/tgcrypto.d.ts +0 -0
package/esm/0_deps.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from "./deps/deno.land/std@0.201.0/assert/mod.js";
2
- export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.2/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/esm/0_deps.js CHANGED
@@ -1,8 +1,9 @@
1
- export * from "./deps/deno.land/std@0.201.0/assert/mod.js";
2
- export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.2/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 } 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 const debug = (v) => debug_(v);
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";
@@ -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.100";
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 = "";
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 161;
57
- export const APP_VERSION = "MTKruto 0.1.100";
57
+ export const APP_VERSION = "MTKruto 0.1.101";
58
58
  // @ts-ignore: lib
59
59
  export const 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;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,5 +1,5 @@
1
1
  import { assertEquals, ige256Decrypt, ige256Encrypt } from "../0_deps.js";
2
- import { bufferFromBigInt, concat, sha256 } from "../1_utilities.js";
2
+ import { bufferFromBigInt, concat, mod, sha256 } from "../1_utilities.js";
3
3
  import { id, Message_, MessageContainer, RPCResult, serialize, TLReader, TLWriter } from "../2_tl.js";
4
4
  export function getMessageId(lastMsgId) {
5
5
  const now = new Date().getTime() / 1000 + 0;
@@ -37,14 +37,8 @@ export async function encryptMessage(message, authKey, authKeyId, salt, sessionI
37
37
  payloadWriter.writeInt32(message.seqNo);
38
38
  payloadWriter.writeInt32(encoded.length);
39
39
  payloadWriter.write(encoded);
40
- payloadWriter.write(new Uint8Array(payloadWriter.buffer.length + 12 % 16 + 12));
41
- let payload = payloadWriter.buffer;
42
- while (true) {
43
- if (payload.length % 16 == 0 && (payload.length) % 4 == 0) {
44
- break;
45
- }
46
- payload = concat(payload, new Uint8Array(1));
47
- }
40
+ payloadWriter.write(new Uint8Array(mod(-(payloadWriter.buffer.length + 12), 16) + 12));
41
+ const payload = payloadWriter.buffer;
48
42
  const messageKey = (await sha256(concat(authKey.slice(88, 120), payload))).slice(8, 24);
49
43
  const a = await sha256(concat(messageKey, authKey.slice(0, 36)));
50
44
  const b = await sha256(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,10 +1,10 @@
1
- import { debug, gunzip, Mutex } from "../0_deps.js";
2
- import { bigIntFromBuffer, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE } from "../1_utilities.js";
1
+ import { crypto, debug, gunzip, Mutex } from "../0_deps.js";
2
+ import { bigIntFromBuffer, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE } from "../1_utilities.js";
3
3
  import { as, functions, getChannelChatId, Message_, MessageContainer, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
4
4
  import { StorageMemory } from "../3_storage.js";
5
5
  import { botCommandScopeToTlObject, constructCallbackQuery, constructInlineQuery, constructMessage, constructUser, FileID, FileType, inlineQueryResultToTlObject, messageEntityToTlObject, replyMarkupToTlObject, ThumbnailSource } from "../3_types.js";
6
6
  import { ACK_THRESHOLD, APP_VERSION, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL, ZERO_CHANNEL_ID } from "../4_constants.js";
7
- import { AuthKeyUnregistered, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, upgradeInstance } from "../4_errors.js";
7
+ import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, upgradeInstance } from "../4_errors.js";
8
8
  import { parseHtml } from "./0_html.js";
9
9
  import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
10
10
  import { checkPassword } from "./0_password.js";
@@ -17,11 +17,14 @@ const dGap = debug("Client/recoverUpdateGap");
17
17
  const dGapC = debug("Client/recoverChannelUpdateGap");
18
18
  const dAuth = debug("Client/authorize");
19
19
  const dRecv = debug("Client/receiveLoop");
20
+ const dUpload = debug("Client/upload");
20
21
  export const getEntity = Symbol();
21
22
  export const getStickerSetName = Symbol();
22
23
  export const handleMigrationError = Symbol();
23
24
  export const getMessageWithReply = Symbol();
24
25
  export const restartAuth = Symbol();
26
+ export class ConnectionError extends Error {
27
+ }
25
28
  export class Client extends ClientAbstract {
26
29
  /**
27
30
  * Constructs the client.
@@ -30,14 +33,8 @@ export class Client extends ClientAbstract {
30
33
  * @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
31
34
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
32
35
  */
33
- constructor(storage = new StorageMemory(), apiId = 0, apiHash = "", params) {
36
+ constructor(storage, apiId = 0, apiHash = "", params) {
34
37
  super(params);
35
- Object.defineProperty(this, "storage", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: storage
40
- });
41
38
  Object.defineProperty(this, "apiId", {
42
39
  enumerable: true,
43
40
  configurable: true,
@@ -86,6 +83,18 @@ export class Client extends ClientAbstract {
86
83
  writable: true,
87
84
  value: void 0
88
85
  });
86
+ Object.defineProperty(this, "errorHandler", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ Object.defineProperty(this, "storage", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: void 0
97
+ });
89
98
  Object.defineProperty(this, "parseMode", {
90
99
  enumerable: true,
91
100
  configurable: true,
@@ -189,6 +198,12 @@ export class Client extends ClientAbstract {
189
198
  writable: true,
190
199
  value: null
191
200
  });
201
+ Object.defineProperty(this, "pingLoopStarted", {
202
+ enumerable: true,
203
+ configurable: true,
204
+ writable: true,
205
+ value: false
206
+ });
192
207
  Object.defineProperty(this, "autoStarted", {
193
208
  enumerable: true,
194
209
  configurable: true,
@@ -228,6 +243,7 @@ export class Client extends ClientAbstract {
228
243
  writable: true,
229
244
  value: skip
230
245
  });
246
+ this.storage = storage ?? new StorageMemory();
231
247
  this.parseMode = params?.parseMode ?? null;
232
248
  this.appVersion = params?.appVersion ?? APP_VERSION;
233
249
  this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
@@ -237,6 +253,7 @@ export class Client extends ClientAbstract {
237
253
  this.systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
238
254
  this.publicKeys = params?.publicKeys;
239
255
  this.autoStart = params?.autoStart ?? true;
256
+ this.errorHandler = params?.errorHandler;
240
257
  }
241
258
  propagateConnectionState(connectionState) {
242
259
  return this.handle({ connectionState }, resolve);
@@ -306,7 +323,6 @@ export class Client extends ClientAbstract {
306
323
  }
307
324
  d("encrypted client connected");
308
325
  drop(this.receiveLoop());
309
- drop(this.pingLoop());
310
326
  }
311
327
  finally {
312
328
  release();
@@ -548,7 +564,7 @@ export class Client extends ClientAbstract {
548
564
  }
549
565
  async receiveLoop() {
550
566
  if (!this.auth || !this.transport) {
551
- throw new Error("Not connected");
567
+ throw new ConnectionError("Not connected");
552
568
  }
553
569
  while (this.connected) {
554
570
  try {
@@ -576,6 +592,9 @@ export class Client extends ClientAbstract {
576
592
  if (body instanceof types._TypeUpdates || body instanceof types._TypeUpdate) {
577
593
  this.processUpdatesQueue.add(() => this.processUpdates(body));
578
594
  }
595
+ else if (body instanceof types.NewSessionCreated) {
596
+ this.state.salt = body.serverSalt;
597
+ }
579
598
  else if (message.body instanceof RPCResult) {
580
599
  let result = message.body.result;
581
600
  if (result instanceof types.GZIPPacked) {
@@ -639,10 +658,18 @@ export class Client extends ClientAbstract {
639
658
  drop(this.recoverUpdateGap("deserialize"));
640
659
  }
641
660
  else {
642
- throw err;
661
+ dRecv("uncaught error: %o", err);
643
662
  }
644
663
  }
645
664
  }
665
+ if (!this.connected) {
666
+ for (const { reject } of this.promises.values()) {
667
+ reject(new ConnectionError("Connection was closed"));
668
+ }
669
+ }
670
+ else {
671
+ UNREACHABLE();
672
+ }
646
673
  }
647
674
  async pingLoop() {
648
675
  while (this.connected) {
@@ -661,41 +688,61 @@ export class Client extends ClientAbstract {
661
688
  await this.start();
662
689
  }
663
690
  else {
664
- throw new Error("Not connected");
691
+ throw new ConnectionError("Not connected");
665
692
  }
666
693
  }
667
694
  if (!this.auth || !this.transport) {
668
695
  UNREACHABLE();
669
696
  }
670
- let seqNo = this.state.seqNo * 2;
671
- if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
672
- seqNo++;
673
- this.state.seqNo++;
674
- }
675
- const messageId = this.lastMsgId = getMessageId(this.lastMsgId);
676
- const message = new Message_(messageId, seqNo, function_);
677
- await this.transport.transport.send(await encryptMessage(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
678
- d("invoked %s", function_.constructor.name);
679
- if (noWait) {
680
- return;
681
- }
682
- let result;
683
- try {
684
- result = await new Promise((resolve, reject) => {
685
- this.promises.set(message.id, { resolve, reject });
686
- });
687
- }
688
- catch (err) {
689
- if (err instanceof AuthKeyUnregistered) {
690
- await this.propagateAuthorizationState(false);
697
+ let n = 1;
698
+ while (true) {
699
+ try {
700
+ let seqNo = this.state.seqNo * 2;
701
+ if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
702
+ seqNo++;
703
+ this.state.seqNo++;
704
+ }
705
+ const messageId = this.lastMsgId = getMessageId(this.lastMsgId);
706
+ const message = new Message_(messageId, seqNo, function_);
707
+ await this.transport.transport.send(await encryptMessage(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
708
+ d("invoked %s", function_.constructor.name);
709
+ if (noWait) {
710
+ return;
711
+ }
712
+ let result;
713
+ try {
714
+ result = await new Promise((resolve, reject) => {
715
+ this.promises.set(message.id, { resolve, reject });
716
+ });
717
+ }
718
+ catch (err) {
719
+ if (err instanceof AuthKeyUnregistered) {
720
+ await this.propagateAuthorizationState(false);
721
+ }
722
+ throw err;
723
+ }
724
+ if (result instanceof types.BadServerSalt) {
725
+ return await this.invoke(function_);
726
+ }
727
+ else {
728
+ if (!this.pingLoopStarted) {
729
+ drop(this.pingLoop());
730
+ this.pingLoopStarted = true;
731
+ }
732
+ return result;
733
+ }
734
+ }
735
+ catch (err) {
736
+ if (this.errorHandler === undefined) {
737
+ throw err;
738
+ }
739
+ if (this.errorHandler !== undefined && await this.errorHandler(err, function_, n++)) {
740
+ continue;
741
+ }
742
+ else {
743
+ throw err;
744
+ }
691
745
  }
692
- throw err;
693
- }
694
- if (result instanceof types.BadServerSalt) {
695
- return await this.invoke(function_);
696
- }
697
- else {
698
- return result;
699
746
  }
700
747
  }
701
748
  /**
@@ -1305,29 +1352,30 @@ export class Client extends ClientAbstract {
1305
1352
  const messages = await this.getMessages(chatId, [messageId]);
1306
1353
  return messages[0] ?? null;
1307
1354
  }
1308
- async *downloadInner(location, dcId) {
1309
- let client = null;
1310
- if (dcId != undefined && dcId != this.dcId) {
1311
- const exportedAuth = await this.invoke(new functions.AuthExportAuthorization({ dcId }));
1312
- client = new Client(new StorageMemory(), this.apiId, this.apiHash, {
1313
- transportProvider: this.transportProvider,
1314
- appVersion: this.appVersion,
1315
- deviceModel: this.deviceModel,
1316
- langCode: this.langCode,
1317
- langPack: this.langPack,
1318
- systemLangCode: this.systemLangCode,
1319
- systemVersion: this.systemVersion,
1320
- cdn: true,
1321
- });
1322
- let dc = String(dcId);
1323
- if (this.dcId < 0) {
1324
- dc += "-test";
1325
- }
1326
- await client.setDc(dc);
1327
- await client.connect();
1328
- await client.authorize(exportedAuth);
1329
- }
1330
- const limit = 1024 * 1024;
1355
+ async *downloadInner(location, dcId, params) {
1356
+ const chunkSize = params?.chunkSize ?? 1024 * 1024;
1357
+ if (mod(chunkSize, 1024) != 0) {
1358
+ throw new Error("chunkSize must be divisible by 1024");
1359
+ }
1360
+ const exportedAuth = await this.invoke(new functions.AuthExportAuthorization({ dcId }));
1361
+ const client = new Client(new StorageMemory(), this.apiId, this.apiHash, {
1362
+ transportProvider: this.transportProvider,
1363
+ appVersion: this.appVersion,
1364
+ deviceModel: this.deviceModel,
1365
+ langCode: this.langCode,
1366
+ langPack: this.langPack,
1367
+ systemLangCode: this.systemLangCode,
1368
+ systemVersion: this.systemVersion,
1369
+ cdn: true,
1370
+ });
1371
+ let dc = String(dcId);
1372
+ if (this.dcId < 0) {
1373
+ dc += "-test";
1374
+ }
1375
+ await client.setDc(dc);
1376
+ await client.connect();
1377
+ await client.authorize(exportedAuth);
1378
+ const limit = chunkSize;
1331
1379
  let offset = 0n;
1332
1380
  while (true) {
1333
1381
  const file = await (client ?? this).invoke(new functions.UploadGetFile({ location, offset, limit }));
@@ -1350,14 +1398,14 @@ export class Client extends ClientAbstract {
1350
1398
  *
1351
1399
  * @param fileId The identifier of the file to download.
1352
1400
  */
1353
- async download(fileId) {
1401
+ async download(fileId, params) {
1354
1402
  const fileId_ = FileID.decode(fileId);
1355
1403
  switch (fileId_.fileType) {
1356
1404
  case FileType.ChatPhoto: {
1357
1405
  const big = fileId_.params.thumbnailSource == ThumbnailSource.ChatPhotoBig;
1358
1406
  const peer = await this.getInputPeer(fileId_.params.chatId);
1359
1407
  const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId_.params.mediaId });
1360
- return this.downloadInner(location);
1408
+ return this.downloadInner(location, fileId_.dcId, params);
1361
1409
  }
1362
1410
  case FileType.Photo: {
1363
1411
  if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
@@ -1369,7 +1417,7 @@ export class Client extends ClientAbstract {
1369
1417
  fileReference: fileId_.params.fileReference,
1370
1418
  thumbSize: fileId_.params.thumbnailSize,
1371
1419
  });
1372
- return this.downloadInner(location);
1420
+ return this.downloadInner(location, fileId_.dcId, params);
1373
1421
  }
1374
1422
  default:
1375
1423
  UNREACHABLE();
@@ -1607,6 +1655,99 @@ export class Client extends ClientAbstract {
1607
1655
  }
1608
1656
  await this.invoke(new functions.MessagesSetTyping({ peer: await this.getInputPeer(chatId), action, topMsgId: messageThreadId }));
1609
1657
  }
1658
+ /**
1659
+ * Upload a file.
1660
+ *
1661
+ * @param contents The contents of the file.
1662
+ */
1663
+ async upload(contents, params) {
1664
+ const isBig = contents.length > 1048576; // 10 MB
1665
+ const chunkSize = params?.chunkSize ?? 512 * 1024;
1666
+ if (mod(chunkSize, 1024) != 0) {
1667
+ throw new Error("chunkSize must be divisible by 1024");
1668
+ }
1669
+ const signal = params?.signal;
1670
+ dUpload("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
1671
+ const fileId = getRandomId();
1672
+ const name = params?.fileName ?? fileId.toString();
1673
+ const client = new Client(this.storage, this.apiId, this.apiHash, {
1674
+ transportProvider: this.transportProvider,
1675
+ appVersion: this.appVersion,
1676
+ deviceModel: this.deviceModel,
1677
+ langCode: this.langCode,
1678
+ langPack: this.langPack,
1679
+ systemLangCode: this.systemLangCode,
1680
+ systemVersion: this.systemVersion,
1681
+ cdn: true,
1682
+ initialDc: this.initialDc,
1683
+ autoStart: false,
1684
+ });
1685
+ signal?.addEventListener("abort", () => drop(client.disconnect()));
1686
+ client.state.salt = this.state.salt;
1687
+ await client.connect();
1688
+ let part = 0;
1689
+ const md5sum = await crypto.subtle.digest("MD5", contents).then((v) => [...new Uint8Array(v)]
1690
+ .map((b) => b.toString(16).padStart(2, "0"))
1691
+ .join(""));
1692
+ const partCount = Math.ceil(contents.length / chunkSize);
1693
+ try {
1694
+ main: for (; part < partCount; part++) {
1695
+ chunk: while (true) {
1696
+ try {
1697
+ const start = part * chunkSize;
1698
+ const end = start + chunkSize;
1699
+ const bytes = contents.slice(start, end);
1700
+ if (bytes.length == 0) {
1701
+ continue main;
1702
+ }
1703
+ if (isBig) {
1704
+ await client.invoke(new functions.UploadSaveBigFilePart({ fileId, filePart: part, bytes, fileTotalParts: partCount }));
1705
+ }
1706
+ else {
1707
+ await client.invoke(new functions.UploadSaveFilePart({ fileId, bytes, filePart: part }));
1708
+ }
1709
+ dUpload((part + 1) + " out of " + partCount + " chunks have been uploaded so far");
1710
+ break chunk;
1711
+ }
1712
+ catch (err) {
1713
+ if (signal?.aborted) {
1714
+ break main;
1715
+ }
1716
+ if (err instanceof FloodWait) {
1717
+ dUpload("got a flood wait of " + err.seconds + " seconds");
1718
+ await new Promise((r) => setTimeout(r, err.seconds * 1000));
1719
+ }
1720
+ else if (err instanceof ConnectionError) {
1721
+ while (true) {
1722
+ try {
1723
+ await new Promise((r) => setTimeout(r, 3000));
1724
+ await client.connect();
1725
+ }
1726
+ catch {
1727
+ if (signal?.aborted) {
1728
+ break main;
1729
+ }
1730
+ }
1731
+ }
1732
+ }
1733
+ else {
1734
+ throw err;
1735
+ }
1736
+ }
1737
+ }
1738
+ }
1739
+ }
1740
+ finally {
1741
+ drop(client.disconnect());
1742
+ }
1743
+ dUpload("uploaded all " + partCount + " chunk(s)");
1744
+ if (isBig) {
1745
+ return new types.InputFileBig({ id: fileId, parts: contents.length / chunkSize, name });
1746
+ }
1747
+ else {
1748
+ return new types.InputFile({ id: fileId, name, parts: part, md5Checksum: md5sum });
1749
+ }
1750
+ }
1610
1751
  async setMyCommands(commands, params) {
1611
1752
  await this.invoke(new functions.BotsSetBotCommands({
1612
1753
  commands: commands.map((v) => new types.BotCommand(v)),
@@ -81,7 +81,7 @@ export class ConnectionWebSocket extends ConnectionUnframed {
81
81
  this.buffer.push(byte);
82
82
  }
83
83
  if (this.nextResolve != null && this.buffer.length >= this.nextResolve[0]) {
84
- this.nextResolve[1]();
84
+ this.nextResolve[1].resolve();
85
85
  this.nextResolve = null;
86
86
  }
87
87
  release();
@@ -136,7 +136,7 @@ export class ConnectionWebSocket extends ConnectionUnframed {
136
136
  const release = await this.rMutex.acquire();
137
137
  try {
138
138
  if (this.buffer.length < p.length) {
139
- await new Promise((r) => this.nextResolve = [p.length, r]);
139
+ await new Promise((resolve, reject) => this.nextResolve = [p.length, { resolve, reject }]);
140
140
  }
141
141
  p.set(this.buffer.splice(0, p.length));
142
142
  }
@@ -161,5 +161,8 @@ export class ConnectionWebSocket extends ConnectionUnframed {
161
161
  throw new Error("Connection not open");
162
162
  }
163
163
  this.webSocket.close(1000, "method");
164
+ if (this.nextResolve != null) {
165
+ this.nextResolve[1].reject(new Error("Connection not open"));
166
+ }
164
167
  }
165
168
  }
@@ -1,5 +1,6 @@
1
1
  // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
2
  import { AssertionError } from "./assertion_error.js";
3
+ /** Make an assertion, error will be thrown if `expr` have truthy value. */
3
4
  export function assertFalse(expr, msg = "") {
4
5
  if (expr) {
5
6
  throw new AssertionError(msg);
@@ -0,0 +1,2 @@
1
+ export declare const fnv32: (data: Uint8Array) => ArrayBuffer;
2
+ export declare const fnv32a: (data: Uint8Array) => ArrayBuffer;
@@ -0,0 +1,24 @@
1
+ // Ported from Go:
2
+ // https://github.com/golang/go/tree/go1.13.10/src/hash/fnv/fnv.go
3
+ // Copyright 2011 The Go Authors. All rights reserved. BSD license.
4
+ // https://github.com/golang/go/blob/master/LICENSE
5
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
6
+ // This module is browser compatible.
7
+ import { mul32, swap32 } from "./util.js";
8
+ const prime32 = 16777619;
9
+ export const fnv32 = (data) => {
10
+ let hash = 2166136261;
11
+ data.forEach((c) => {
12
+ hash = mul32(hash, prime32);
13
+ hash ^= c;
14
+ });
15
+ return Uint32Array.from([swap32(hash)]).buffer;
16
+ };
17
+ export const fnv32a = (data) => {
18
+ let hash = 2166136261;
19
+ data.forEach((c) => {
20
+ hash ^= c;
21
+ hash = mul32(hash, prime32);
22
+ });
23
+ return Uint32Array.from([swap32(hash)]).buffer;
24
+ };
@@ -0,0 +1,2 @@
1
+ export declare const fnv64: (data: Uint8Array) => ArrayBuffer;
2
+ export declare const fnv64a: (data: Uint8Array) => ArrayBuffer;
@@ -0,0 +1,27 @@
1
+ // Ported from Go:
2
+ // https://github.com/golang/go/tree/go1.13.10/src/hash/fnv/fnv.go
3
+ // Copyright 2011 The Go Authors. All rights reserved. BSD license.
4
+ // https://github.com/golang/go/blob/master/LICENSE
5
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
6
+ // This module is browser compatible.
7
+ import { mul64, swap32 } from "./util.js";
8
+ const prime64Lo = 435;
9
+ const prime64Hi = 256;
10
+ export const fnv64 = (data) => {
11
+ let hashLo = 2216829733;
12
+ let hashHi = 3421674724;
13
+ data.forEach((c) => {
14
+ [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]);
15
+ hashLo ^= c;
16
+ });
17
+ return new Uint32Array([swap32(hashHi >>> 0), swap32(hashLo >>> 0)]).buffer;
18
+ };
19
+ export const fnv64a = (data) => {
20
+ let hashLo = 2216829733;
21
+ let hashHi = 3421674724;
22
+ data.forEach((c) => {
23
+ hashLo ^= c;
24
+ [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]);
25
+ });
26
+ return new Uint32Array([swap32(hashHi >>> 0), swap32(hashLo >>> 0)]).buffer;
27
+ };
@@ -0,0 +1 @@
1
+ export declare function fnv(name: string, buf?: Uint8Array): ArrayBuffer;