@mtkruto/node 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/esm/0_deps.d.ts +1 -2
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +1 -2
  4. package/esm/0_errors.d.ts +6 -0
  5. package/esm/0_errors.d.ts.map +1 -1
  6. package/esm/0_errors.js +11 -0
  7. package/esm/1_utilities.d.ts +1 -2
  8. package/esm/1_utilities.d.ts.map +1 -1
  9. package/esm/1_utilities.js +1 -2
  10. package/esm/2_tl.d.ts +0 -1
  11. package/esm/2_tl.d.ts.map +1 -1
  12. package/esm/2_tl.js +0 -1
  13. package/esm/client/0_params.d.ts +4 -0
  14. package/esm/client/0_params.d.ts.map +1 -1
  15. package/esm/client/0_password.d.ts.map +1 -1
  16. package/esm/client/0_password.js +8 -8
  17. package/esm/client/0_storage_operations.d.ts.map +1 -1
  18. package/esm/client/0_storage_operations.js +2 -2
  19. package/esm/client/1_client_plain.js +14 -14
  20. package/esm/client/1_types.d.ts +4 -4
  21. package/esm/client/1_types.d.ts.map +1 -1
  22. package/esm/client/2_update_manager.d.ts +2 -1
  23. package/esm/client/2_update_manager.d.ts.map +1 -1
  24. package/esm/client/2_update_manager.js +11 -7
  25. package/esm/client/3_message_manager.d.ts.map +1 -1
  26. package/esm/client/3_message_manager.js +4 -9
  27. package/esm/client/4_callback_query_manager.d.ts.map +1 -1
  28. package/esm/client/4_callback_query_manager.js +2 -1
  29. package/esm/client/4_inline_query_manager.js +2 -2
  30. package/esm/client/5_client.d.ts +4 -4
  31. package/esm/client/5_client.d.ts.map +1 -1
  32. package/esm/client/5_client.js +5 -5
  33. package/esm/connection/1_connection_tcp.node.d.ts +1 -1
  34. package/esm/connection/1_connection_tcp.node.d.ts.map +1 -1
  35. package/esm/connection/1_connection_tcp.node.js +4 -1
  36. package/esm/connection/1_connection_web_socket.d.ts.map +1 -1
  37. package/esm/connection/1_connection_web_socket.js +3 -6
  38. package/{script/deps/jsr.io/@std/assert/1.0.12 → esm/deps/jsr.io/@std/assert/1.0.16}/is_error.d.ts.map +1 -1
  39. package/esm/deps/jsr.io/@std/assert/{1.0.12 → 1.0.16}/not_equals.d.ts.map +1 -1
  40. package/esm/deps/jsr.io/@std/assert/{1.0.12 → 1.0.16}/throws.d.ts.map +1 -1
  41. package/esm/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.d.ts.map +1 -1
  42. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  43. package/esm/session/2_session_encrypted.js +10 -9
  44. package/esm/session/2_session_plain.js +4 -4
  45. package/esm/tl/0_utilities.d.ts +1 -0
  46. package/esm/tl/0_utilities.d.ts.map +1 -1
  47. package/esm/tl/0_utilities.js +3 -0
  48. package/esm/tl/1_tl_reader.d.ts +6 -8
  49. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  50. package/esm/tl/1_tl_reader.js +39 -30
  51. package/esm/tl/1_tl_writer.d.ts +5 -5
  52. package/esm/tl/1_tl_writer.d.ts.map +1 -1
  53. package/esm/tl/1_tl_writer.js +49 -35
  54. package/esm/transport/0_obfuscation.d.ts.map +1 -1
  55. package/esm/transport/0_obfuscation.js +2 -2
  56. package/esm/transport/1_transport_abridged.js +3 -3
  57. package/esm/transport/1_transport_intermediate.js +2 -2
  58. package/esm/types/0_link_preview_media_size.d.ts +19 -0
  59. package/esm/types/0_link_preview_media_size.d.ts.map +1 -1
  60. package/esm/types/0_link_preview_media_size.js +19 -0
  61. package/esm/types/1_inline_keyboard_button.js +1 -1
  62. package/esm/types/7_saved_chat.d.ts.map +1 -1
  63. package/esm/types/7_saved_chat.js +1 -1
  64. package/esm/utilities/0_int.d.ts +52 -0
  65. package/esm/utilities/0_int.d.ts.map +1 -0
  66. package/esm/utilities/0_int.js +141 -0
  67. package/esm/utilities/0_int_test.d.ts.map +1 -0
  68. package/esm/utilities/1_auth.d.ts.map +1 -1
  69. package/esm/utilities/1_auth.js +3 -4
  70. package/esm/utilities/1_base64.js +1 -1
  71. package/esm/utilities/1_crypto.d.ts.map +1 -1
  72. package/esm/utilities/1_crypto.js +2 -3
  73. package/esm/utilities/1_math.js +1 -1
  74. package/package.json +1 -1
  75. package/script/0_deps.d.ts +1 -2
  76. package/script/0_deps.d.ts.map +1 -1
  77. package/script/0_deps.js +2 -4
  78. package/script/0_errors.d.ts +6 -0
  79. package/script/0_errors.d.ts.map +1 -1
  80. package/script/0_errors.js +13 -1
  81. package/script/1_utilities.d.ts +1 -2
  82. package/script/1_utilities.d.ts.map +1 -1
  83. package/script/1_utilities.js +1 -2
  84. package/script/2_tl.d.ts +0 -1
  85. package/script/2_tl.d.ts.map +1 -1
  86. package/script/2_tl.js +1 -3
  87. package/script/client/0_params.d.ts +4 -0
  88. package/script/client/0_params.d.ts.map +1 -1
  89. package/script/client/0_password.d.ts.map +1 -1
  90. package/script/client/0_password.js +7 -7
  91. package/script/client/0_storage_operations.d.ts.map +1 -1
  92. package/script/client/0_storage_operations.js +1 -1
  93. package/script/client/1_client_plain.js +13 -13
  94. package/script/client/1_types.d.ts +4 -4
  95. package/script/client/1_types.d.ts.map +1 -1
  96. package/script/client/2_update_manager.d.ts +2 -1
  97. package/script/client/2_update_manager.d.ts.map +1 -1
  98. package/script/client/2_update_manager.js +11 -7
  99. package/script/client/3_message_manager.d.ts.map +1 -1
  100. package/script/client/3_message_manager.js +4 -9
  101. package/script/client/4_callback_query_manager.d.ts.map +1 -1
  102. package/script/client/4_callback_query_manager.js +2 -1
  103. package/script/client/4_inline_query_manager.js +1 -1
  104. package/script/client/5_client.d.ts +4 -4
  105. package/script/client/5_client.d.ts.map +1 -1
  106. package/script/client/5_client.js +5 -5
  107. package/script/connection/1_connection_tcp.node.d.ts +1 -1
  108. package/script/connection/1_connection_tcp.node.d.ts.map +1 -1
  109. package/script/connection/1_connection_tcp.node.js +4 -1
  110. package/script/connection/1_connection_web_socket.d.ts.map +1 -1
  111. package/script/connection/1_connection_web_socket.js +3 -6
  112. package/{esm/deps/jsr.io/@std/assert/1.0.12 → script/deps/jsr.io/@std/assert/1.0.16}/is_error.d.ts.map +1 -1
  113. package/script/deps/jsr.io/@std/assert/{1.0.12 → 1.0.16}/not_equals.d.ts.map +1 -1
  114. package/script/deps/jsr.io/@std/assert/{1.0.12 → 1.0.16}/throws.d.ts.map +1 -1
  115. package/script/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.d.ts.map +1 -1
  116. package/script/session/2_session_encrypted.d.ts.map +1 -1
  117. package/script/session/2_session_encrypted.js +9 -8
  118. package/script/session/2_session_plain.js +3 -3
  119. package/script/tl/0_utilities.d.ts +1 -0
  120. package/script/tl/0_utilities.d.ts.map +1 -1
  121. package/script/tl/0_utilities.js +4 -0
  122. package/script/tl/1_tl_reader.d.ts +6 -8
  123. package/script/tl/1_tl_reader.d.ts.map +1 -1
  124. package/script/tl/1_tl_reader.js +38 -30
  125. package/script/tl/1_tl_writer.d.ts +5 -5
  126. package/script/tl/1_tl_writer.d.ts.map +1 -1
  127. package/script/tl/1_tl_writer.js +49 -35
  128. package/script/transport/0_obfuscation.d.ts.map +1 -1
  129. package/script/transport/0_obfuscation.js +1 -1
  130. package/script/transport/1_transport_abridged.js +2 -2
  131. package/script/transport/1_transport_intermediate.js +1 -1
  132. package/script/types/0_link_preview_media_size.d.ts +19 -0
  133. package/script/types/0_link_preview_media_size.d.ts.map +1 -1
  134. package/script/types/0_link_preview_media_size.js +19 -0
  135. package/script/types/1_inline_keyboard_button.js +1 -1
  136. package/script/types/7_saved_chat.d.ts.map +1 -1
  137. package/script/types/7_saved_chat.js +3 -3
  138. package/script/utilities/0_int.d.ts +52 -0
  139. package/script/utilities/0_int.d.ts.map +1 -0
  140. package/script/utilities/{0_bigint.js → 0_int.js} +66 -15
  141. package/script/utilities/0_int_test.d.ts.map +1 -0
  142. package/script/utilities/1_auth.d.ts.map +1 -1
  143. package/script/utilities/1_auth.js +4 -5
  144. package/script/utilities/1_base64.js +2 -2
  145. package/script/utilities/1_crypto.d.ts.map +1 -1
  146. package/script/utilities/1_crypto.js +2 -3
  147. package/script/utilities/1_math.js +4 -4
  148. package/esm/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts.map +0 -1
  149. package/esm/deps/jsr.io/@std/assert/1.0.12/equal.d.ts.map +0 -1
  150. package/esm/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts.map +0 -1
  151. package/esm/deps/jsr.io/@std/assert/1.0.13/assertion_error.d.ts +0 -26
  152. package/esm/deps/jsr.io/@std/assert/1.0.13/assertion_error.d.ts.map +0 -1
  153. package/esm/deps/jsr.io/@std/assert/1.0.13/assertion_error.js +0 -30
  154. package/esm/deps/jsr.io/@std/assert/1.0.13/unreachable.d.ts +0 -15
  155. package/esm/deps/jsr.io/@std/assert/1.0.13/unreachable.d.ts.map +0 -1
  156. package/esm/deps/jsr.io/@std/assert/1.0.13/unreachable.js +0 -20
  157. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
  158. package/esm/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -52
  159. package/esm/tl/0_tl_error.d.ts +0 -23
  160. package/esm/tl/0_tl_error.d.ts.map +0 -1
  161. package/esm/tl/0_tl_error.js +0 -22
  162. package/esm/utilities/0_bigint.d.ts +0 -10
  163. package/esm/utilities/0_bigint.d.ts.map +0 -1
  164. package/esm/utilities/0_bigint.js +0 -91
  165. package/esm/utilities/0_bigint_test.d.ts.map +0 -1
  166. package/esm/utilities/0_buffer.d.ts +0 -21
  167. package/esm/utilities/0_buffer.d.ts.map +0 -1
  168. package/esm/utilities/0_buffer.js +0 -51
  169. package/esm/utilities/0_buffer_test.d.ts.map +0 -1
  170. package/script/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts.map +0 -1
  171. package/script/deps/jsr.io/@std/assert/1.0.12/equal.d.ts.map +0 -1
  172. package/script/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts.map +0 -1
  173. package/script/deps/jsr.io/@std/assert/1.0.13/assertion_error.d.ts +0 -26
  174. package/script/deps/jsr.io/@std/assert/1.0.13/assertion_error.d.ts.map +0 -1
  175. package/script/deps/jsr.io/@std/assert/1.0.13/assertion_error.js +0 -34
  176. package/script/deps/jsr.io/@std/assert/1.0.13/unreachable.d.ts +0 -15
  177. package/script/deps/jsr.io/@std/assert/1.0.13/unreachable.d.ts.map +0 -1
  178. package/script/deps/jsr.io/@std/assert/1.0.13/unreachable.js +0 -23
  179. package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.d.ts +0 -23
  180. package/script/deps/jsr.io/@std/assert/1.0.16/instance_of.js +0 -55
  181. package/script/tl/0_tl_error.d.ts +0 -23
  182. package/script/tl/0_tl_error.d.ts.map +0 -1
  183. package/script/tl/0_tl_error.js +0 -26
  184. package/script/utilities/0_bigint.d.ts +0 -10
  185. package/script/utilities/0_bigint.d.ts.map +0 -1
  186. package/script/utilities/0_bigint_test.d.ts.map +0 -1
  187. package/script/utilities/0_buffer.d.ts +0 -21
  188. package/script/utilities/0_buffer.d.ts.map +0 -1
  189. package/script/utilities/0_buffer.js +0 -54
  190. package/script/utilities/0_buffer_test.d.ts.map +0 -1
  191. /package/esm/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.d.ts +0 -0
  192. /package/esm/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.js +0 -0
  193. /package/script/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.d.ts +0 -0
  194. /package/script/deps/jsr.io/@std/streams/{1.0.12 → 1.0.14}/to_array_buffer.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"throws.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.12/throws.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;AACX;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAClD,EAAE,EAAE,MAAM,OAAO,EAEjB,UAAU,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAC9C,WAAW,CAAC,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,CAAC,CAAC"}
1
+ {"version":3,"file":"throws.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.16/throws.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,MAAM,OAAO,EACjB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;AACX;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAClD,EAAE,EAAE,MAAM,OAAO,EAEjB,UAAU,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAC9C,WAAW,CAAC,EAAE,MAAM,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"to_array_buffer.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/streams/1.0.12/to_array_buffer.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CACjC,cAAc,EAAE,cAAc,CAAC,UAAU,CAAC,GACzC,OAAO,CAAC,WAAW,CAAC,CAetB"}
1
+ {"version":3,"file":"to_array_buffer.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/streams/1.0.14/to_array_buffer.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AACH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AC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAwX3D"}
@@ -58,7 +58,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
58
58
  }
59
59
  async setAuthKey(key) {
60
60
  const hash = await (0, _1_utilities_js_1.sha1)(key);
61
- this.#authKeyId = (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false);
61
+ this.#authKeyId = (0, _1_utilities_js_1.intFromBytes)(hash.slice(-8));
62
62
  this.#authKey = key;
63
63
  }
64
64
  get authKey() {
@@ -66,7 +66,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
66
66
  }
67
67
  async connect() {
68
68
  if (!this.connected) {
69
- this.#rejectAllPending(new _0_errors_js_1.ConnectionError("Not connected."));
69
+ this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was closed."));
70
70
  }
71
71
  await super.connect();
72
72
  if (!SessionEncrypted.#TGCRYPTO_INITED) {
@@ -84,11 +84,11 @@ class SessionEncrypted extends _1_session_js_1.Session {
84
84
  this.#id = (0, _1_utilities_js_1.getRandomId)();
85
85
  this.#pingLoop.abort();
86
86
  this.#awakeSendLoop?.();
87
- this.#rejectAllPending(new _0_errors_js_1.ConnectionError("Not connected."));
87
+ this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was disconnected."));
88
88
  }
89
89
  #assertNotDisconnected() {
90
90
  if (this.disconnected) {
91
- throw new _0_errors_js_1.ConnectionError("Not connected.");
91
+ throw new _0_errors_js_1.ConnectionError("The connection was disconnected.");
92
92
  }
93
93
  }
94
94
  async #invalidateSession(reason) {
@@ -97,7 +97,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
97
97
  this.state.reset();
98
98
  this.disconnect();
99
99
  await this.connect();
100
- this.#rejectAllPending(new _0_session_error_js_1.SessionError("Session invalidated."));
100
+ this.#rejectAllPending(new _0_session_error_js_1.SessionError("The session was invalidated."));
101
101
  }
102
102
  #rejectAllPending(reason) {
103
103
  for (const id of this.#sentMessages) {
@@ -160,7 +160,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
160
160
  this.#assertNotDisconnected();
161
161
  const buffer = await this.transport.transport.receive();
162
162
  if (buffer.length === 4) {
163
- const int = (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, true);
163
+ const int = (0, _1_utilities_js_1.intFromBytes)(buffer);
164
164
  throw new _0_errors_js_1.TransportError(Number(int));
165
165
  }
166
166
  try {
@@ -169,6 +169,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
169
169
  return decrypted;
170
170
  }
171
171
  catch (err) {
172
+ this.#L.error("decryption error:", err);
172
173
  await this.#invalidateSession("decryption error");
173
174
  throw err;
174
175
  }
@@ -193,9 +194,9 @@ class SessionEncrypted extends _1_session_js_1.Session {
193
194
  }
194
195
  async #decryptMessage(buffer) {
195
196
  const reader = new _2_tl_js_1.TLReader(buffer);
196
- (0, _0_deps_js_1.assertEquals)(reader.readInt64(false), this.#authKeyId);
197
+ (0, _0_deps_js_1.assertEquals)(reader.readInt64(), this.#authKeyId);
197
198
  const messageKey_ = reader.readInt128();
198
- const messageKey = (0, _1_utilities_js_1.bufferFromBigInt)(messageKey_, 16, true, true);
199
+ const messageKey = (0, _1_utilities_js_1.intToBytes)(messageKey_, 16);
199
200
  const a = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.subarray(8, 44)]));
200
201
  const b = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([this.#authKey.subarray(48, 84), messageKey]));
201
202
  const aesKey = (0, _0_deps_js_1.concat)([a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32)]);
@@ -28,7 +28,7 @@ const _1_session_js_1 = require("./1_session.js");
28
28
  class SessionPlain extends _1_session_js_1.Session {
29
29
  async send(data) {
30
30
  if (!this.connected) {
31
- throw new _0_errors_js_1.ConnectionError("Not connected.");
31
+ throw new _0_errors_js_1.ConnectionError("The connection is not open.");
32
32
  }
33
33
  const messageId = this.state.nextMessageId();
34
34
  const writer = new _1_tl_writer_js_1.TLWriter();
@@ -42,11 +42,11 @@ class SessionPlain extends _1_session_js_1.Session {
42
42
  }
43
43
  async receive() {
44
44
  if (!this.connected) {
45
- throw new _0_errors_js_1.ConnectionError("Not connected.");
45
+ throw new _0_errors_js_1.ConnectionError("The connection is not open.");
46
46
  }
47
47
  const buffer = await this.transport.transport.receive();
48
48
  if (buffer.length === 4) {
49
- const int = (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, true);
49
+ const int = (0, _1_utilities_js_1.intFromBytes)(buffer);
50
50
  throw new _0_errors_js_1.TransportError(Number(int));
51
51
  }
52
52
  const reader = new _1_tl_reader_js_1.TLReader(buffer);
@@ -30,4 +30,5 @@ export declare const X = "X";
30
30
  export declare const VECTOR = 481674261;
31
31
  export declare const BOOL_TRUE = 2574415285;
32
32
  export declare const BOOL_FALSE = 3162085175;
33
+ export declare function constructorIdToHex(constructorId: number): string;
33
34
  //# sourceMappingURL=0_utilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"0_utilities.d.ts","sourceRoot":"","sources":["../../src/tl/0_utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AACD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AACD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAY3F;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAElD;AAGD,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,GAAG,CAkB3C;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK7D;AAID,eAAO,MAAM,CAAC,MAAM,CAAC;AACrB,eAAO,MAAM,MAAM,YAAa,CAAC;AACjC,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,eAAO,MAAM,UAAU,aAAa,CAAC"}
1
+ {"version":3,"file":"0_utilities.d.ts","sourceRoot":"","sources":["../../src/tl/0_utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AACD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AACD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAY3F;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAElD;AAGD,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,GAAG,CAkB3C;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK7D;AAID,eAAO,MAAM,CAAC,MAAM,CAAC;AACrB,eAAO,MAAM,MAAM,YAAa,CAAC;AACjC,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,eAAO,MAAM,UAAU,aAAa,CAAC;AAErC,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhE"}
@@ -26,6 +26,7 @@ exports.analyzeOptionalParam = analyzeOptionalParam;
26
26
  exports.repr = repr;
27
27
  exports.toJSON = toJSON;
28
28
  exports.getVectorItemType = getVectorItemType;
29
+ exports.constructorIdToHex = constructorIdToHex;
29
30
  const _0_deps_js_1 = require("../0_deps.js");
30
31
  function isOptionalParam(ntype) {
31
32
  return ntype.includes("?");
@@ -83,3 +84,6 @@ exports.X = "X";
83
84
  exports.VECTOR = 0x1CB5C415;
84
85
  exports.BOOL_TRUE = 0x997275b5;
85
86
  exports.BOOL_FALSE = 0xbc799737;
87
+ function constructorIdToHex(constructorId) {
88
+ return constructorId.toString(16);
89
+ }
@@ -18,22 +18,20 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  import type { Schema } from "./0_types.js";
21
- export declare class TLError extends Error {
22
- }
23
21
  export declare class TLReader {
24
22
  #private;
25
23
  protected _buffer: Uint8Array;
26
24
  constructor(_buffer: Uint8Array);
27
25
  get buffer(): Uint8Array;
28
- read(count: number): Uint8Array<ArrayBuffer>;
26
+ read(byteCount: number): Uint8Array<ArrayBuffer>;
29
27
  unread(count: number): void;
30
- readInt24(signed?: boolean): number;
31
- readInt32(signed?: boolean): number;
28
+ readInt24(isSigned?: boolean): number;
29
+ readInt32(isSigned?: boolean): number;
32
30
  unreadInt32(): void;
33
- readInt64(signed?: boolean): bigint;
31
+ readInt64(isSigned?: boolean): bigint;
34
32
  readDouble(): number;
35
- readInt128(signed?: boolean): bigint;
36
- readInt256(signed?: boolean): bigint;
33
+ readInt128(isSigned?: boolean): bigint;
34
+ readInt256(isSigned?: boolean): bigint;
37
35
  readBytes(): Uint8Array<ArrayBuffer>;
38
36
  readString(): string;
39
37
  readType(name: string, schema: Schema): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"1_tl_reader.d.ts","sourceRoot":"","sources":["../../src/tl/1_tl_reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAoB,MAAM,EAAE,MAAM,cAAc,CAAC;AAG7D,qBAAa,OAAQ,SAAQ,KAAK;CAEjC;AAED,qBAAa,QAAQ;;IACP,SAAS,CAAC,OAAO,EAAE,UAAU;gBAAnB,OAAO,EAAE,UAAU;IAGzC,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,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CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CA6H3D"}
@@ -20,61 +20,60 @@
20
20
  */
21
21
  // deno-lint-ignore-file no-explicit-any
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.TLReader = exports.TLError = void 0;
23
+ exports.TLReader = void 0;
24
24
  const _1_utilities_js_1 = require("../1_utilities.js");
25
+ const _0_errors_js_1 = require("../0_errors.js");
25
26
  const _0_utilities_js_1 = require("./0_utilities.js");
26
- class TLError extends Error {
27
- }
28
- exports.TLError = TLError;
29
27
  class TLReader {
30
28
  _buffer;
29
+ #path = new Array();
31
30
  constructor(_buffer) {
32
31
  this._buffer = _buffer;
33
32
  }
34
33
  get buffer() {
35
34
  return this._buffer;
36
35
  }
37
- read(count) {
38
- if (this._buffer.length < count) {
39
- throw new TLError("No data remaining");
36
+ read(byteCount) {
37
+ if (this._buffer.byteLength < byteCount) {
38
+ throw new _0_errors_js_1.TLError("No data remaining", this.#path);
40
39
  }
41
- const buffer = this._buffer.slice(0, count);
42
- this._buffer = this._buffer.subarray(count);
40
+ const buffer = this._buffer.slice(0, byteCount);
41
+ this._buffer = this._buffer.subarray(byteCount);
43
42
  return buffer;
44
43
  }
45
44
  unread(count) {
46
45
  const newOffest = this._buffer.byteOffset - count;
47
46
  if (newOffest < 0) {
48
- throw new TLError("No data has been read");
47
+ throw new _0_errors_js_1.TLError("No data has been read", this.#path);
49
48
  }
50
49
  this._buffer = new Uint8Array(this._buffer.buffer, newOffest);
51
50
  }
52
- readInt24(signed = true) {
51
+ readInt24(isSigned = true) {
53
52
  const buffer = this.read(24 / 8);
54
- return Number((0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed));
53
+ return Number((0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned }));
55
54
  }
56
- readInt32(signed = true) {
55
+ readInt32(isSigned = true) {
57
56
  const buffer = this.read(32 / 8);
58
- return Number((0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed));
57
+ return Number((0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned }));
59
58
  }
60
59
  unreadInt32() {
61
60
  this.unread(32 / 8);
62
61
  }
63
- readInt64(signed = true) {
62
+ readInt64(isSigned = true) {
64
63
  const buffer = this.read(64 / 8);
65
- return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
64
+ return (0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned });
66
65
  }
67
66
  readDouble() {
68
67
  const buffer = this.read(8);
69
68
  return new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).getFloat64(0, true);
70
69
  }
71
- readInt128(signed = true) {
70
+ readInt128(isSigned = true) {
72
71
  const buffer = this.read(128 / 8);
73
- return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
72
+ return (0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned });
74
73
  }
75
- readInt256(signed = true) {
74
+ readInt256(isSigned = true) {
76
75
  const buffer = this.read(256 / 8);
77
- return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
76
+ return (0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned });
78
77
  }
79
78
  readBytes() {
80
79
  let L = this.read(1)[0];
@@ -108,7 +107,7 @@ class TLReader {
108
107
  if (name === _0_utilities_js_1.X) {
109
108
  const typeName = schema.identifierToName[id];
110
109
  if (!typeName) {
111
- throw new TLError(`Unknown constructor: ${id.toString(16)}`);
110
+ throw new _0_errors_js_1.TLError(`Unknown constructor ID: ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
112
111
  }
113
112
  this.unreadInt32();
114
113
  return await this.readType(typeName, schema);
@@ -124,7 +123,7 @@ class TLReader {
124
123
  if (deserializedEnum !== undefined) {
125
124
  return deserializedEnum;
126
125
  }
127
- throw new TLError(`Unknown type: ${name} ID ${id}`);
126
+ throw new _0_errors_js_1.TLError(`Unknown type: ${name}#${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
128
127
  }
129
128
  async #deserializeEnum(type, id, schema) {
130
129
  const name = schema.identifierToName[id];
@@ -139,23 +138,32 @@ class TLReader {
139
138
  }
140
139
  async #deserializeType(type, desc, id, schema) {
141
140
  if (desc[0] !== id) {
142
- throw new TLError(`Expected constructor ${desc[0].toString(16)} but got ${id}`);
141
+ throw new _0_errors_js_1.TLError(`Expected constructor with ID ${(0, _0_utilities_js_1.constructorIdToHex)(desc[0])} but received ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
143
142
  }
143
+ let isFirstPathElementExisting = false;
144
144
  const type_ = { _: type };
145
145
  const flagFields = {};
146
- for (const [name, type] of desc[1]) {
147
- if ((0, _0_utilities_js_1.isOptionalParam)(type)) {
148
- const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(type);
146
+ for (const [name, fieldType] of desc[1]) {
147
+ if ((0, _0_utilities_js_1.isOptionalParam)(fieldType)) {
148
+ const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(fieldType);
149
149
  const bits = flagFields[flagField];
150
150
  if ((bits & (1 << bitIndex)) === 0) {
151
151
  continue;
152
152
  }
153
153
  }
154
- if (type === "#") {
154
+ if (fieldType === "#") {
155
155
  flagFields[name] = this.readInt32();
156
156
  continue;
157
157
  }
158
- const value = await this.readType(type, schema);
158
+ const pathElement = `[${type}.]${name}`;
159
+ if (isFirstPathElementExisting) {
160
+ this.#path[this.#path.length - 1] = pathElement;
161
+ }
162
+ else {
163
+ this.#path.push(pathElement);
164
+ isFirstPathElementExisting = true;
165
+ }
166
+ const value = await this.readType(fieldType, schema);
159
167
  if (typeof value !== "boolean" || value) {
160
168
  type_[name] = value;
161
169
  }
@@ -165,7 +173,7 @@ class TLReader {
165
173
  async #deserializeVector(type, schema) {
166
174
  const itemType = (0, _0_utilities_js_1.getVectorItemType)(type);
167
175
  if (!itemType) {
168
- throw new TLError(`Expected Vector but received ${type}`);
176
+ throw new _0_errors_js_1.TLError(`Expected Vector but received ${type}`, this.#path);
169
177
  }
170
178
  const size = this.readInt32();
171
179
  const array = new Array();
@@ -199,7 +207,7 @@ class TLReader {
199
207
  return false;
200
208
  }
201
209
  else {
202
- throw new TLError(`Expected boolTrue or boolFalse but got ${id}`);
210
+ throw new _0_errors_js_1.TLError(`Expected boolTrue or boolFalse but received ${(0, _0_utilities_js_1.constructorIdToHex)(id)}`, this.#path);
203
211
  }
204
212
  }
205
213
  case "string":
@@ -24,12 +24,12 @@ export declare class TLWriter {
24
24
  constructor();
25
25
  get buffer(): Uint8Array<ArrayBuffer>;
26
26
  write(buffer: Uint8Array): typeof this;
27
- writeInt24(int: number, signed?: boolean): typeof this;
28
- writeInt32(int: number, signed?: boolean): typeof this;
29
- writeInt64(int: bigint, signed?: boolean): typeof this;
27
+ writeInt24(int: number, isSigned?: boolean): typeof this;
28
+ writeInt32(int: number, isSigned?: boolean): typeof this;
29
+ writeInt64(int: bigint, isSigned?: boolean): typeof this;
30
30
  writeDouble(double: number): typeof this;
31
- writeInt128(int: bigint, signed?: boolean): typeof this;
32
- writeInt256(int: bigint, signed?: boolean): typeof this;
31
+ writeInt128(int: bigint, isSigned?: boolean): typeof this;
32
+ writeInt256(int: bigint, isSigned?: boolean): typeof this;
33
33
  writeBytes(bytes: Uint8Array): typeof this;
34
34
  writeString(string: string): typeof this;
35
35
  writeObject(value: any, schema: Schema): typeof this;
@@ -1 +1 @@
1
- {"version":3,"file":"1_tl_writer.d.ts","sourceRoot":"","sources":["../../src/tl/1_tl_writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,qBAAa,QAAQ;;IACnB,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAoB;;IAK9D,IAAI,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,CAEpC;IAED,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,O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,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,IAAI;IAOxC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,IAAI;IAKtD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,IAAI;IAKtD,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,IAAI;IAkB1C,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,IAAI;IAKxC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,IAAI;CAyLrD"}
@@ -22,12 +22,13 @@
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.TLWriter = void 0;
24
24
  const _0_deps_js_1 = require("../0_deps.js");
25
- const _0_tl_error_js_1 = require("./0_tl_error.js");
25
+ const _0_errors_js_1 = require("../0_errors.js");
26
26
  const _0_utilities_js_1 = require("./0_utilities.js");
27
- const _0_buffer_js_1 = require("../utilities/0_buffer.js");
27
+ const _0_int_js_1 = require("../utilities/0_int.js");
28
28
  const _1_utilities_js_1 = require("../1_utilities.js");
29
29
  class TLWriter {
30
30
  _buffer = new Uint8Array();
31
+ #path = new Array();
31
32
  constructor() {
32
33
  }
33
34
  get buffer() {
@@ -37,16 +38,16 @@ class TLWriter {
37
38
  this._buffer = (0, _0_deps_js_1.concat)([this._buffer, buffer]);
38
39
  return this;
39
40
  }
40
- writeInt24(int, signed = true) {
41
- this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 24 / 8, true, signed));
41
+ writeInt24(int, isSigned = true) {
42
+ this.write((0, _0_int_js_1.intToBytes)(int, 24 / 8, { isSigned, path: this.#path }));
42
43
  return this;
43
44
  }
44
- writeInt32(int, signed = true) {
45
- this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 32 / 8, true, signed));
45
+ writeInt32(int, isSigned = true) {
46
+ this.write((0, _0_int_js_1.intToBytes)(int, 32 / 8, { isSigned, path: this.#path }));
46
47
  return this;
47
48
  }
48
- writeInt64(int, signed = true) {
49
- this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 64 / 8, true, signed));
49
+ writeInt64(int, isSigned = true) {
50
+ this.write((0, _0_int_js_1.intToBytes)(int, 64 / 8, { isSigned, path: this.#path }));
50
51
  return this;
51
52
  }
52
53
  writeDouble(double) {
@@ -55,12 +56,12 @@ class TLWriter {
55
56
  this.write(buffer);
56
57
  return this;
57
58
  }
58
- writeInt128(int, signed = true) {
59
- this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 128 / 8, true, signed));
59
+ writeInt128(int, isSigned = true) {
60
+ this.write((0, _0_int_js_1.intToBytes)(int, 128 / 8, { isSigned, path: this.#path }));
60
61
  return this;
61
62
  }
62
- writeInt256(int, signed = true) {
63
- this.write((0, _0_buffer_js_1.bufferFromBigInt)(int, 256 / 8, true, signed));
63
+ writeInt256(int, isSigned = true) {
64
+ this.write((0, _0_int_js_1.intToBytes)(int, 256 / 8, { isSigned, path: this.#path }));
64
65
  return this;
65
66
  }
66
67
  writeBytes(bytes) {
@@ -86,31 +87,31 @@ class TLWriter {
86
87
  return this;
87
88
  }
88
89
  writeObject(value, schema) {
89
- this.#serialize(value._, value, "", schema);
90
+ this.#serialize(value._, value, schema);
90
91
  return this;
91
92
  }
92
- #serialize(type, value, debugInfo, schema) {
93
- if (this.#serializePrimitive(type, value, debugInfo)) {
93
+ #serialize(type, value, schema) {
94
+ if (this.#serializePrimitive(type, value)) {
94
95
  return;
95
96
  }
96
- if (this.#serializeVector(type, value, debugInfo, schema)) {
97
+ if (this.#serializeVector(type, value, schema)) {
97
98
  return;
98
99
  }
99
100
  const maybeDefinition = schema.definitions[value._];
100
101
  if (!maybeDefinition) {
101
- throw new _0_tl_error_js_1.TLError(`Unknown type: ${value._}`);
102
+ throw new _0_errors_js_1.TLError(`Unknown constructor: ${value._}`, this.#path);
102
103
  }
103
104
  if (type !== "!X" && !this.#isTypeValid(type, value, schema)) {
104
- throw new _0_tl_error_js_1.TLError(`Expected ${type} but got ${value._}`);
105
+ throw new _0_errors_js_1.TLError(`Expected ${type} but instead got ${value._}`, this.#path);
105
106
  }
106
107
  const type__ = value;
107
108
  const [id, parameters_] = maybeDefinition;
108
109
  this.writeInt32(id, false);
109
- for (let [i, [name, type]] of parameters_.entries()) {
110
+ let isFirstPathElementExisting = false;
111
+ for (let [name, type] of parameters_.values()) {
110
112
  if ((0, _0_utilities_js_1.isOptionalParam)(type) && type__[name] === undefined) {
111
113
  continue;
112
114
  }
113
- const debugInfo = ` [0x${id.toString(16).toUpperCase()}::${i}]`;
114
115
  if (type === "#") {
115
116
  let flags = 0;
116
117
  const flagField_ = name;
@@ -127,32 +128,40 @@ class TLWriter {
127
128
  this.writeInt32(flags);
128
129
  continue;
129
130
  }
131
+ const pathElement = `[${value._}.]${name}`;
132
+ if (isFirstPathElementExisting) {
133
+ this.#path[this.#path.length - 1] = pathElement;
134
+ }
135
+ else {
136
+ this.#path.push(pathElement);
137
+ isFirstPathElementExisting = true;
138
+ }
130
139
  if (type__[name] === undefined && !(0, _0_utilities_js_1.isOptionalParam)(type)) {
131
- throw new Error(`Missing required parameter: ${name}`);
140
+ throw new _0_errors_js_1.TLError("Missing required field", this.#path);
132
141
  }
133
142
  if ((0, _0_utilities_js_1.isOptionalParam)(type)) {
134
143
  type = (0, _0_utilities_js_1.getOptionalParamInnerType)(type);
135
144
  }
136
- this.#serialize(type, type__[name], debugInfo, schema);
145
+ this.#serialize(type, type__[name], schema);
137
146
  }
138
147
  return;
139
148
  }
140
- #serializeVector(type, value, debugInfo, schema) {
149
+ #serializeVector(type, value, schema) {
141
150
  const itemType = (0, _0_utilities_js_1.getVectorItemType)(type);
142
151
  if (!itemType) {
143
152
  return false;
144
153
  }
145
154
  if (!Array.isArray(value)) {
146
- throw new TypeError(`Expected array but received ${(0, _0_utilities_js_1.repr)(value)}${debugInfo}`);
155
+ throw new _0_errors_js_1.TLError(`Expected an array but received ${(0, _0_utilities_js_1.repr)(value)}`, this.#path);
147
156
  }
148
157
  this.writeInt32(_0_utilities_js_1.VECTOR, false);
149
158
  this.writeInt32(value.length);
150
159
  for (const item of value) {
151
- this.#serialize(itemType, item, debugInfo, schema);
160
+ this.#serialize(itemType, item, schema);
152
161
  }
153
162
  return true;
154
163
  }
155
- #serializePrimitive(type, value, debugInfo) {
164
+ #serializePrimitive(type, value) {
156
165
  const valueRepr = (0, _0_utilities_js_1.repr)(value);
157
166
  switch (type) {
158
167
  case "bytes":
@@ -160,7 +169,7 @@ class TLWriter {
160
169
  this.writeBytes(value);
161
170
  }
162
171
  else {
163
- throw new _0_tl_error_js_1.TLError(`Expected Uint8Array but received ${valueRepr}${debugInfo}`);
172
+ throw new _0_errors_js_1.TLError(`Expected Uint8Array but received ${valueRepr}`, this.#path);
164
173
  }
165
174
  return true;
166
175
  case "int128":
@@ -168,7 +177,7 @@ class TLWriter {
168
177
  this.writeInt128(value);
169
178
  }
170
179
  else {
171
- throw new _0_tl_error_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
180
+ throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
172
181
  }
173
182
  return true;
174
183
  case "int256":
@@ -176,7 +185,7 @@ class TLWriter {
176
185
  this.writeInt256(value);
177
186
  }
178
187
  else {
179
- throw new _0_tl_error_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
188
+ throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
180
189
  }
181
190
  return true;
182
191
  case "long":
@@ -184,7 +193,7 @@ class TLWriter {
184
193
  this.writeInt64(value);
185
194
  }
186
195
  else {
187
- throw new _0_tl_error_js_1.TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
196
+ throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
188
197
  }
189
198
  return true;
190
199
  case "Bool":
@@ -197,7 +206,7 @@ class TLWriter {
197
206
  }
198
207
  }
199
208
  else {
200
- throw new _0_tl_error_js_1.TLError(`Expected boolean but received ${valueRepr}${debugInfo}`);
209
+ throw new _0_errors_js_1.TLError(`Expected boolean but received ${valueRepr}`, this.#path);
201
210
  }
202
211
  return true;
203
212
  case "int":
@@ -207,10 +216,15 @@ class TLWriter {
207
216
  }
208
217
  //
209
218
  if (typeof value === "number") {
210
- this.writeInt32(value);
219
+ if (value % 1 === 0) {
220
+ this.writeInt32(value);
221
+ }
222
+ else {
223
+ throw new _0_errors_js_1.TLError("Expected an integer value but received a floating point", this.#path);
224
+ }
211
225
  }
212
226
  else {
213
- throw new _0_tl_error_js_1.TLError(`Expected number but received ${valueRepr}${debugInfo}`);
227
+ throw new _0_errors_js_1.TLError(`Expected number but received ${valueRepr}`, this.#path);
214
228
  }
215
229
  return true;
216
230
  case "double":
@@ -223,7 +237,7 @@ class TLWriter {
223
237
  this.writeDouble(value);
224
238
  }
225
239
  else {
226
- throw new _0_tl_error_js_1.TLError(`Expected number but received ${valueRepr}${debugInfo}`);
240
+ throw new _0_errors_js_1.TLError(`Expected number but received ${valueRepr}`, this.#path);
227
241
  }
228
242
  return true;
229
243
  case "string":
@@ -242,7 +256,7 @@ class TLWriter {
242
256
  return true;
243
257
  case "true":
244
258
  if (value !== true) {
245
- throw new _0_tl_error_js_1.TLError(`Expected true but received ${valueRepr}${debugInfo}`);
259
+ throw new _0_errors_js_1.TLError(`Expected \`true\` but received ${valueRepr}`, this.#path);
246
260
  }
247
261
  return true;
248
262
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAoB,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;;;GA0CtF"}
1
+ {"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,GAAG,EAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;;;GA0CtF"}
@@ -59,7 +59,7 @@ const _1_utilities_js_1 = require("../1_utilities.js");
59
59
  async function getObfuscationParameters(protocol, connection) {
60
60
  let init;
61
61
  while (true) {
62
- init = (0, _0_deps_js_1.concat)([dntShim.crypto.getRandomValues(new Uint8Array(56)), (0, _1_utilities_js_1.bufferFromBigInt)(protocol, 4, false), dntShim.crypto.getRandomValues(new Uint8Array(4))]);
62
+ init = (0, _0_deps_js_1.concat)([dntShim.crypto.getRandomValues(new Uint8Array(56)), (0, _1_utilities_js_1.intToBytes)(protocol, 4, { byteOrder: "big", isSigned: false }), dntShim.crypto.getRandomValues(new Uint8Array(4))]);
63
63
  if (init[0] === 0xEF) {
64
64
  continue;
65
65
  }
@@ -53,7 +53,7 @@ class TransportAbridged extends _0_transport_js_1.Transport {
53
53
  let buffer = new Uint8Array(3);
54
54
  await this.#connection.read(buffer);
55
55
  buffer = await this.decrypt(buffer);
56
- length = Number((0, _1_utilities_js_1.bigIntFromBuffer)(buffer));
56
+ length = Number((0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned: false }));
57
57
  }
58
58
  }
59
59
  length *= 4;
@@ -64,7 +64,7 @@ class TransportAbridged extends _0_transport_js_1.Transport {
64
64
  async send(buffer) {
65
65
  const bufferLength = buffer.length / 4;
66
66
  const header = new Uint8Array([bufferLength >= 0x7F ? 0x7F : bufferLength]);
67
- const length = bufferLength >= 0x7F ? (0, _1_utilities_js_1.bufferFromBigInt)(bufferLength, 3) : new Uint8Array();
67
+ const length = bufferLength >= 0x7F ? (0, _1_utilities_js_1.intToBytes)(bufferLength, 3, { isSigned: false }) : new Uint8Array();
68
68
  const data = (0, _0_deps_js_1.concat)([header, length, buffer]);
69
69
  await this.#connection.write(await this.encrypt(data));
70
70
  }
@@ -54,7 +54,7 @@ class TransportIntermediate extends _0_transport_js_1.Transport {
54
54
  return await this.decrypt(buffer);
55
55
  }
56
56
  async send(buffer) {
57
- const length = (0, _1_utilities_js_1.bufferFromBigInt)(buffer.length, 4);
57
+ const length = (0, _1_utilities_js_1.intToBytes)(buffer.length, 4);
58
58
  const data = (0, _0_deps_js_1.concat)([length, buffer]);
59
59
  await this.#connection.write(await this.encrypt(data));
60
60
  }