@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
@@ -18,59 +18,59 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  // deno-lint-ignore-file no-explicit-any
21
- import { bigIntFromBuffer, decodeText } from "../1_utilities.js";
22
- import { analyzeOptionalParam, BOOL_FALSE, BOOL_TRUE, getOptionalParamInnerType, getVectorItemType, isOptionalParam, VECTOR, X } from "./0_utilities.js";
23
- export class TLError extends Error {
24
- }
21
+ import { decodeText, intFromBytes } from "../1_utilities.js";
22
+ import { TLError } from "../0_errors.js";
23
+ import { analyzeOptionalParam, BOOL_FALSE, BOOL_TRUE, constructorIdToHex, getOptionalParamInnerType, getVectorItemType, isOptionalParam, VECTOR, X } from "./0_utilities.js";
25
24
  export class TLReader {
26
25
  _buffer;
26
+ #path = new Array();
27
27
  constructor(_buffer) {
28
28
  this._buffer = _buffer;
29
29
  }
30
30
  get buffer() {
31
31
  return this._buffer;
32
32
  }
33
- read(count) {
34
- if (this._buffer.length < count) {
35
- throw new TLError("No data remaining");
33
+ read(byteCount) {
34
+ if (this._buffer.byteLength < byteCount) {
35
+ throw new TLError("No data remaining", this.#path);
36
36
  }
37
- const buffer = this._buffer.slice(0, count);
38
- this._buffer = this._buffer.subarray(count);
37
+ const buffer = this._buffer.slice(0, byteCount);
38
+ this._buffer = this._buffer.subarray(byteCount);
39
39
  return buffer;
40
40
  }
41
41
  unread(count) {
42
42
  const newOffest = this._buffer.byteOffset - count;
43
43
  if (newOffest < 0) {
44
- throw new TLError("No data has been read");
44
+ throw new TLError("No data has been read", this.#path);
45
45
  }
46
46
  this._buffer = new Uint8Array(this._buffer.buffer, newOffest);
47
47
  }
48
- readInt24(signed = true) {
48
+ readInt24(isSigned = true) {
49
49
  const buffer = this.read(24 / 8);
50
- return Number(bigIntFromBuffer(buffer, true, signed));
50
+ return Number(intFromBytes(buffer, { isSigned }));
51
51
  }
52
- readInt32(signed = true) {
52
+ readInt32(isSigned = true) {
53
53
  const buffer = this.read(32 / 8);
54
- return Number(bigIntFromBuffer(buffer, true, signed));
54
+ return Number(intFromBytes(buffer, { isSigned }));
55
55
  }
56
56
  unreadInt32() {
57
57
  this.unread(32 / 8);
58
58
  }
59
- readInt64(signed = true) {
59
+ readInt64(isSigned = true) {
60
60
  const buffer = this.read(64 / 8);
61
- return bigIntFromBuffer(buffer, true, signed);
61
+ return intFromBytes(buffer, { isSigned });
62
62
  }
63
63
  readDouble() {
64
64
  const buffer = this.read(8);
65
65
  return new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).getFloat64(0, true);
66
66
  }
67
- readInt128(signed = true) {
67
+ readInt128(isSigned = true) {
68
68
  const buffer = this.read(128 / 8);
69
- return bigIntFromBuffer(buffer, true, signed);
69
+ return intFromBytes(buffer, { isSigned });
70
70
  }
71
- readInt256(signed = true) {
71
+ readInt256(isSigned = true) {
72
72
  const buffer = this.read(256 / 8);
73
- return bigIntFromBuffer(buffer, true, signed);
73
+ return intFromBytes(buffer, { isSigned });
74
74
  }
75
75
  readBytes() {
76
76
  let L = this.read(1)[0];
@@ -104,7 +104,7 @@ export class TLReader {
104
104
  if (name === X) {
105
105
  const typeName = schema.identifierToName[id];
106
106
  if (!typeName) {
107
- throw new TLError(`Unknown constructor: ${id.toString(16)}`);
107
+ throw new TLError(`Unknown constructor ID: ${constructorIdToHex(id)}`, this.#path);
108
108
  }
109
109
  this.unreadInt32();
110
110
  return await this.readType(typeName, schema);
@@ -120,7 +120,7 @@ export class TLReader {
120
120
  if (deserializedEnum !== undefined) {
121
121
  return deserializedEnum;
122
122
  }
123
- throw new TLError(`Unknown type: ${name} ID ${id}`);
123
+ throw new TLError(`Unknown type: ${name}#${constructorIdToHex(id)}`, this.#path);
124
124
  }
125
125
  async #deserializeEnum(type, id, schema) {
126
126
  const name = schema.identifierToName[id];
@@ -135,23 +135,32 @@ export class TLReader {
135
135
  }
136
136
  async #deserializeType(type, desc, id, schema) {
137
137
  if (desc[0] !== id) {
138
- throw new TLError(`Expected constructor ${desc[0].toString(16)} but got ${id}`);
138
+ throw new TLError(`Expected constructor with ID ${constructorIdToHex(desc[0])} but received ${constructorIdToHex(id)}`, this.#path);
139
139
  }
140
+ let isFirstPathElementExisting = false;
140
141
  const type_ = { _: type };
141
142
  const flagFields = {};
142
- for (const [name, type] of desc[1]) {
143
- if (isOptionalParam(type)) {
144
- const { flagField, bitIndex } = analyzeOptionalParam(type);
143
+ for (const [name, fieldType] of desc[1]) {
144
+ if (isOptionalParam(fieldType)) {
145
+ const { flagField, bitIndex } = analyzeOptionalParam(fieldType);
145
146
  const bits = flagFields[flagField];
146
147
  if ((bits & (1 << bitIndex)) === 0) {
147
148
  continue;
148
149
  }
149
150
  }
150
- if (type === "#") {
151
+ if (fieldType === "#") {
151
152
  flagFields[name] = this.readInt32();
152
153
  continue;
153
154
  }
154
- const value = await this.readType(type, schema);
155
+ const pathElement = `[${type}.]${name}`;
156
+ if (isFirstPathElementExisting) {
157
+ this.#path[this.#path.length - 1] = pathElement;
158
+ }
159
+ else {
160
+ this.#path.push(pathElement);
161
+ isFirstPathElementExisting = true;
162
+ }
163
+ const value = await this.readType(fieldType, schema);
155
164
  if (typeof value !== "boolean" || value) {
156
165
  type_[name] = value;
157
166
  }
@@ -161,7 +170,7 @@ export class TLReader {
161
170
  async #deserializeVector(type, schema) {
162
171
  const itemType = getVectorItemType(type);
163
172
  if (!itemType) {
164
- throw new TLError(`Expected Vector but received ${type}`);
173
+ throw new TLError(`Expected Vector but received ${type}`, this.#path);
165
174
  }
166
175
  const size = this.readInt32();
167
176
  const array = new Array();
@@ -195,7 +204,7 @@ export class TLReader {
195
204
  return false;
196
205
  }
197
206
  else {
198
- throw new TLError(`Expected boolTrue or boolFalse but got ${id}`);
207
+ throw new TLError(`Expected boolTrue or boolFalse but received ${constructorIdToHex(id)}`, this.#path);
199
208
  }
200
209
  }
201
210
  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,OAAO,IAAI;IAKtC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,IAAI;IAKnD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,IAAI;IAKnD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,IAAI;IAKnD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,IAAI;IAOxC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,IAAI;IAKpD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,OAAO,IAAI;IAKpD,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;CAkLrD"}
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;;IAM9D,IAAI,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,CAEpC;IAED,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,IAAI;IAKtC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,IAAI;IAKrD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,IAAI;IAKrD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,IAAI;IAKrD,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"}
@@ -19,12 +19,13 @@
19
19
  */
20
20
  // deno-lint-ignore-file no-explicit-any
21
21
  import { concat } from "../0_deps.js";
22
- import { TLError } from "./0_tl_error.js";
22
+ import { TLError } from "../0_errors.js";
23
23
  import { analyzeOptionalParam, BOOL_FALSE, BOOL_TRUE, getOptionalParamInnerType, getVectorItemType, isOptionalParam, repr, VECTOR } from "./0_utilities.js";
24
- import { bufferFromBigInt } from "../utilities/0_buffer.js";
24
+ import { intToBytes } from "../utilities/0_int.js";
25
25
  import { encodeText } from "../1_utilities.js";
26
26
  export class TLWriter {
27
27
  _buffer = new Uint8Array();
28
+ #path = new Array();
28
29
  constructor() {
29
30
  }
30
31
  get buffer() {
@@ -34,16 +35,16 @@ export class TLWriter {
34
35
  this._buffer = concat([this._buffer, buffer]);
35
36
  return this;
36
37
  }
37
- writeInt24(int, signed = true) {
38
- this.write(bufferFromBigInt(int, 24 / 8, true, signed));
38
+ writeInt24(int, isSigned = true) {
39
+ this.write(intToBytes(int, 24 / 8, { isSigned, path: this.#path }));
39
40
  return this;
40
41
  }
41
- writeInt32(int, signed = true) {
42
- this.write(bufferFromBigInt(int, 32 / 8, true, signed));
42
+ writeInt32(int, isSigned = true) {
43
+ this.write(intToBytes(int, 32 / 8, { isSigned, path: this.#path }));
43
44
  return this;
44
45
  }
45
- writeInt64(int, signed = true) {
46
- this.write(bufferFromBigInt(int, 64 / 8, true, signed));
46
+ writeInt64(int, isSigned = true) {
47
+ this.write(intToBytes(int, 64 / 8, { isSigned, path: this.#path }));
47
48
  return this;
48
49
  }
49
50
  writeDouble(double) {
@@ -52,12 +53,12 @@ export class TLWriter {
52
53
  this.write(buffer);
53
54
  return this;
54
55
  }
55
- writeInt128(int, signed = true) {
56
- this.write(bufferFromBigInt(int, 128 / 8, true, signed));
56
+ writeInt128(int, isSigned = true) {
57
+ this.write(intToBytes(int, 128 / 8, { isSigned, path: this.#path }));
57
58
  return this;
58
59
  }
59
- writeInt256(int, signed = true) {
60
- this.write(bufferFromBigInt(int, 256 / 8, true, signed));
60
+ writeInt256(int, isSigned = true) {
61
+ this.write(intToBytes(int, 256 / 8, { isSigned, path: this.#path }));
61
62
  return this;
62
63
  }
63
64
  writeBytes(bytes) {
@@ -83,31 +84,31 @@ export class TLWriter {
83
84
  return this;
84
85
  }
85
86
  writeObject(value, schema) {
86
- this.#serialize(value._, value, "", schema);
87
+ this.#serialize(value._, value, schema);
87
88
  return this;
88
89
  }
89
- #serialize(type, value, debugInfo, schema) {
90
- if (this.#serializePrimitive(type, value, debugInfo)) {
90
+ #serialize(type, value, schema) {
91
+ if (this.#serializePrimitive(type, value)) {
91
92
  return;
92
93
  }
93
- if (this.#serializeVector(type, value, debugInfo, schema)) {
94
+ if (this.#serializeVector(type, value, schema)) {
94
95
  return;
95
96
  }
96
97
  const maybeDefinition = schema.definitions[value._];
97
98
  if (!maybeDefinition) {
98
- throw new TLError(`Unknown type: ${value._}`);
99
+ throw new TLError(`Unknown constructor: ${value._}`, this.#path);
99
100
  }
100
101
  if (type !== "!X" && !this.#isTypeValid(type, value, schema)) {
101
- throw new TLError(`Expected ${type} but got ${value._}`);
102
+ throw new TLError(`Expected ${type} but instead got ${value._}`, this.#path);
102
103
  }
103
104
  const type__ = value;
104
105
  const [id, parameters_] = maybeDefinition;
105
106
  this.writeInt32(id, false);
106
- for (let [i, [name, type]] of parameters_.entries()) {
107
+ let isFirstPathElementExisting = false;
108
+ for (let [name, type] of parameters_.values()) {
107
109
  if (isOptionalParam(type) && type__[name] === undefined) {
108
110
  continue;
109
111
  }
110
- const debugInfo = ` [0x${id.toString(16).toUpperCase()}::${i}]`;
111
112
  if (type === "#") {
112
113
  let flags = 0;
113
114
  const flagField_ = name;
@@ -124,32 +125,40 @@ export class TLWriter {
124
125
  this.writeInt32(flags);
125
126
  continue;
126
127
  }
128
+ const pathElement = `[${value._}.]${name}`;
129
+ if (isFirstPathElementExisting) {
130
+ this.#path[this.#path.length - 1] = pathElement;
131
+ }
132
+ else {
133
+ this.#path.push(pathElement);
134
+ isFirstPathElementExisting = true;
135
+ }
127
136
  if (type__[name] === undefined && !isOptionalParam(type)) {
128
- throw new Error(`Missing required parameter: ${name}`);
137
+ throw new TLError("Missing required field", this.#path);
129
138
  }
130
139
  if (isOptionalParam(type)) {
131
140
  type = getOptionalParamInnerType(type);
132
141
  }
133
- this.#serialize(type, type__[name], debugInfo, schema);
142
+ this.#serialize(type, type__[name], schema);
134
143
  }
135
144
  return;
136
145
  }
137
- #serializeVector(type, value, debugInfo, schema) {
146
+ #serializeVector(type, value, schema) {
138
147
  const itemType = getVectorItemType(type);
139
148
  if (!itemType) {
140
149
  return false;
141
150
  }
142
151
  if (!Array.isArray(value)) {
143
- throw new TypeError(`Expected array but received ${repr(value)}${debugInfo}`);
152
+ throw new TLError(`Expected an array but received ${repr(value)}`, this.#path);
144
153
  }
145
154
  this.writeInt32(VECTOR, false);
146
155
  this.writeInt32(value.length);
147
156
  for (const item of value) {
148
- this.#serialize(itemType, item, debugInfo, schema);
157
+ this.#serialize(itemType, item, schema);
149
158
  }
150
159
  return true;
151
160
  }
152
- #serializePrimitive(type, value, debugInfo) {
161
+ #serializePrimitive(type, value) {
153
162
  const valueRepr = repr(value);
154
163
  switch (type) {
155
164
  case "bytes":
@@ -157,7 +166,7 @@ export class TLWriter {
157
166
  this.writeBytes(value);
158
167
  }
159
168
  else {
160
- throw new TLError(`Expected Uint8Array but received ${valueRepr}${debugInfo}`);
169
+ throw new TLError(`Expected Uint8Array but received ${valueRepr}`, this.#path);
161
170
  }
162
171
  return true;
163
172
  case "int128":
@@ -165,7 +174,7 @@ export class TLWriter {
165
174
  this.writeInt128(value);
166
175
  }
167
176
  else {
168
- throw new TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
177
+ throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
169
178
  }
170
179
  return true;
171
180
  case "int256":
@@ -173,7 +182,7 @@ export class TLWriter {
173
182
  this.writeInt256(value);
174
183
  }
175
184
  else {
176
- throw new TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
185
+ throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
177
186
  }
178
187
  return true;
179
188
  case "long":
@@ -181,7 +190,7 @@ export class TLWriter {
181
190
  this.writeInt64(value);
182
191
  }
183
192
  else {
184
- throw new TLError(`Expected bigint but received ${valueRepr}${debugInfo}`);
193
+ throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
185
194
  }
186
195
  return true;
187
196
  case "Bool":
@@ -194,7 +203,7 @@ export class TLWriter {
194
203
  }
195
204
  }
196
205
  else {
197
- throw new TLError(`Expected boolean but received ${valueRepr}${debugInfo}`);
206
+ throw new TLError(`Expected boolean but received ${valueRepr}`, this.#path);
198
207
  }
199
208
  return true;
200
209
  case "int":
@@ -204,10 +213,15 @@ export class TLWriter {
204
213
  }
205
214
  //
206
215
  if (typeof value === "number") {
207
- this.writeInt32(value);
216
+ if (value % 1 === 0) {
217
+ this.writeInt32(value);
218
+ }
219
+ else {
220
+ throw new TLError("Expected an integer value but received a floating point", this.#path);
221
+ }
208
222
  }
209
223
  else {
210
- throw new TLError(`Expected number but received ${valueRepr}${debugInfo}`);
224
+ throw new TLError(`Expected number but received ${valueRepr}`, this.#path);
211
225
  }
212
226
  return true;
213
227
  case "double":
@@ -220,7 +234,7 @@ export class TLWriter {
220
234
  this.writeDouble(value);
221
235
  }
222
236
  else {
223
- throw new TLError(`Expected number but received ${valueRepr}${debugInfo}`);
237
+ throw new TLError(`Expected number but received ${valueRepr}`, this.#path);
224
238
  }
225
239
  return true;
226
240
  case "string":
@@ -239,7 +253,7 @@ export class TLWriter {
239
253
  return true;
240
254
  case "true":
241
255
  if (value !== true) {
242
- throw new TLError(`Expected true but received ${valueRepr}${debugInfo}`);
256
+ throw new TLError(`Expected \`true\` but received ${valueRepr}`, this.#path);
243
257
  }
244
258
  return true;
245
259
  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"}
@@ -19,11 +19,11 @@
19
19
  */
20
20
  import * as dntShim from "../_dnt.shims.js";
21
21
  import { concat } from "../0_deps.js";
22
- import { bufferFromBigInt, CTR } from "../1_utilities.js";
22
+ import { CTR, intToBytes } from "../1_utilities.js";
23
23
  export async function getObfuscationParameters(protocol, connection) {
24
24
  let init;
25
25
  while (true) {
26
- init = concat([dntShim.crypto.getRandomValues(new Uint8Array(56)), bufferFromBigInt(protocol, 4, false), dntShim.crypto.getRandomValues(new Uint8Array(4))]);
26
+ init = concat([dntShim.crypto.getRandomValues(new Uint8Array(56)), intToBytes(protocol, 4, { byteOrder: "big", isSigned: false }), dntShim.crypto.getRandomValues(new Uint8Array(4))]);
27
27
  if (init[0] === 0xEF) {
28
28
  continue;
29
29
  }
@@ -18,7 +18,7 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  import { concat } from "../0_deps.js";
21
- import { bigIntFromBuffer, bufferFromBigInt } from "../1_utilities.js";
21
+ import { intFromBytes, intToBytes } from "../1_utilities.js";
22
22
  import { getObfuscationParameters } from "./0_obfuscation.js";
23
23
  import { Transport } from "./0_transport.js";
24
24
  export class TransportAbridged extends Transport {
@@ -50,7 +50,7 @@ export class TransportAbridged extends Transport {
50
50
  let buffer = new Uint8Array(3);
51
51
  await this.#connection.read(buffer);
52
52
  buffer = await this.decrypt(buffer);
53
- length = Number(bigIntFromBuffer(buffer));
53
+ length = Number(intFromBytes(buffer, { isSigned: false }));
54
54
  }
55
55
  }
56
56
  length *= 4;
@@ -61,7 +61,7 @@ export class TransportAbridged extends Transport {
61
61
  async send(buffer) {
62
62
  const bufferLength = buffer.length / 4;
63
63
  const header = new Uint8Array([bufferLength >= 0x7F ? 0x7F : bufferLength]);
64
- const length = bufferLength >= 0x7F ? bufferFromBigInt(bufferLength, 3) : new Uint8Array();
64
+ const length = bufferLength >= 0x7F ? intToBytes(bufferLength, 3, { isSigned: false }) : new Uint8Array();
65
65
  const data = concat([header, length, buffer]);
66
66
  await this.#connection.write(await this.encrypt(data));
67
67
  }
@@ -18,7 +18,7 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  import { concat } from "../0_deps.js";
21
- import { bufferFromBigInt } from "../1_utilities.js";
21
+ import { intToBytes } from "../1_utilities.js";
22
22
  import { getObfuscationParameters } from "./0_obfuscation.js";
23
23
  import { Transport } from "./0_transport.js";
24
24
  export class TransportIntermediate extends Transport {
@@ -51,7 +51,7 @@ export class TransportIntermediate extends Transport {
51
51
  return await this.decrypt(buffer);
52
52
  }
53
53
  async send(buffer) {
54
- const length = bufferFromBigInt(buffer.length, 4);
54
+ const length = intToBytes(buffer.length, 4);
55
55
  const data = concat([length, buffer]);
56
56
  await this.#connection.write(await this.encrypt(data));
57
57
  }
@@ -1,2 +1,21 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
1
20
  export type LinkPreviewMediaSize = "small" | "large";
2
21
  //# sourceMappingURL=0_link_preview_media_size.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"0_link_preview_media_size.d.ts","sourceRoot":"","sources":["../../src/types/0_link_preview_media_size.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"0_link_preview_media_size.d.ts","sourceRoot":"","sources":["../../src/types/0_link_preview_media_size.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,OAAO,CAAC"}
@@ -1 +1,20 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2025 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
1
20
  export {};
@@ -89,7 +89,7 @@ export async function inlineKeyboardButtonToTlObject(button, usernameResolver) {
89
89
  const peerTypes = new Array();
90
90
  const { allowUsers, allowBots, allowGroups, allowChannels } = button.switchInlineQueryChosenChats;
91
91
  if (!allowUsers && !allowBots && !allowGroups && !allowChannels) {
92
- throw new InputError("switchInlineQueryChosenChats: At least one chat type must be allowed");
92
+ throw new InputError("switchInlineQueryChosenChats: At least one chat type must be allowed.");
93
93
  }
94
94
  if (allowUsers) {
95
95
  peerTypes.push({ _: "inlineQueryPeerTypeBotPM" });
@@ -1 +1 @@
1
- {"version":3,"file":"7_saved_chat.d.ts","sourceRoot":"","sources":["../../src/types/7_saved_chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,KAAK,KAAK,EAAkB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpF,mCAAmC;AACnC,MAAM,WAAW,SAAS;IACxB,gBAAgB;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,qBAAqB,GAAG,GAAG,CAAC,0BAA0B,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB7O"}
1
+ {"version":3,"file":"7_saved_chat.d.ts","sourceRoot":"","sources":["../../src/types/7_saved_chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,KAAK,KAAK,EAAkB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpF,mCAAmC;AACnC,MAAM,WAAW,SAAS;IACxB,gBAAgB;IAChB,IAAI,EAAE,KAAK,CAAC;IACZ,qCAAqC;IACrC,WAAW,EAAE,OAAO,CAAC;IACrB,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,qBAAqB,GAAG,GAAG,CAAC,0BAA0B,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,CAkB7O"}
@@ -17,10 +17,10 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
+ import { unreachable } from "../0_deps.js";
20
21
  import { peerToChatId } from "../tl/2_telegram.js";
21
22
  import { constructChatP } from "./1_chat_p.js";
22
23
  import { constructMessage } from "./6_message.js";
23
- import { unreachable } from "../deps/jsr.io/@std/assert/1.0.13/unreachable.js";
24
24
  export async function constructSavedChat(dialog, result, getPeer, getMessage, getStickerSetName) {
25
25
  const message = result.messages.find((v) => v.id === dialog.top_message);
26
26
  if (message === undefined) {
@@ -0,0 +1,52 @@
1
+ export type ByteOrder = "little" | "big";
2
+ export declare function modExp(a: bigint, b: bigint, n: bigint): bigint;
3
+ export declare function mod(n: bigint, m: bigint): bigint;
4
+ export declare function mod(n: number, m: number): number;
5
+ /**
6
+ * Additional parameters for { @link intFromBytes }.
7
+ */
8
+ export interface IntFromBytesParams {
9
+ /** The byte order of the representation. Defaults to `little`. */
10
+ byteOrder?: ByteOrder;
11
+ /** Whether the integer is a signed one. Defaults to `true`. */
12
+ isSigned?: boolean;
13
+ }
14
+ /**
15
+ * Creates an integer from its byte representation.
16
+ *
17
+ * @param bytes The byte representation of the integer.
18
+ * @param params Additional parameters.
19
+ */
20
+ export declare function intFromBytes(bytes: Uint8Array, { byteOrder, isSigned }?: IntFromBytesParams): bigint;
21
+ /**
22
+ * Generates a random integer of an arbitrary size.
23
+ *
24
+ * @param isSigned Whether to allow signed integers. Defaults to `true`.
25
+ */
26
+ export declare function getRandomInt(byteLength: number, isSigned?: boolean): bigint;
27
+ /**
28
+ * Generates a random ID. Useful when interacting with the Telegram API.
29
+ *
30
+ * @param isNumber Whether the ID should be of the type number instead of a bigint.
31
+ */
32
+ export declare function getRandomId(isNumber: true): number;
33
+ export declare function getRandomId(): bigint;
34
+ export declare function gcd(a: bigint, b: bigint): bigint;
35
+ /** Additional parameters for { @link intToBuffer }. */
36
+ export interface BufferFromBigintParams {
37
+ /** The byte order to use for the representation. Defaults to `little`. */
38
+ byteOrder?: ByteOrder;
39
+ /** Whether the integer is a signed one. Defaults to `true`. */
40
+ isSigned?: boolean;
41
+ /** The path to the integer in the TL schema. Unspecified by default. */
42
+ path?: string[];
43
+ }
44
+ /**
45
+ * Converts an integer to its byte representation.
46
+ *
47
+ * @param int The integer to convert.
48
+ * @param byteCount The expected size of the integer in bytes.
49
+ * @param params Additional parameters.
50
+ */
51
+ export declare function intToBytes(int: bigint | number, byteCount: number, { byteOrder, isSigned, path, }?: BufferFromBigintParams): Uint8Array<ArrayBuffer>;
52
+ //# sourceMappingURL=0_int.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0_int.d.ts","sourceRoot":"","sources":["../../src/utilities/0_int.ts"],"names":[],"mappings":"AAwBA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzC,wBAAgB,MAAM,CACpB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,UAgBV;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AAClD,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AAOlD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,kEAAkE;IAClE,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,SAAoB,EAAE,QAAe,EAAE,GAAE,kBAAuB,UAcjH;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,UAAO,UAI/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;AACpD,wBAAgB,WAAW,IAAI,MAAM,CAAC;AAStC,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAwBvC;AAID,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAClE,SAAoB,EACpB,QAAe,EACf,IAAS,GACV,GAAE,sBAA2B,GAAG,UAAU,CAAC,WAAW,CAAC,CAoCvD"}