@mtkruto/node 0.152.0 → 0.154.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 (117) hide show
  1. package/esm/4_constants.d.ts +1 -0
  2. package/esm/4_constants.d.ts.map +1 -1
  3. package/esm/4_constants.js +1 -0
  4. package/esm/client/0_client_abstract.d.ts +1 -1
  5. package/esm/client/0_client_abstract.d.ts.map +1 -1
  6. package/esm/client/0_client_abstract.js +2 -2
  7. package/esm/client/0_password.js +1 -1
  8. package/esm/client/0_utilities.d.ts +1 -1
  9. package/esm/client/0_utilities.d.ts.map +1 -1
  10. package/esm/client/0_utilities.js +4 -4
  11. package/esm/client/1_client_plain.d.ts +1 -1
  12. package/esm/client/1_client_plain.d.ts.map +1 -1
  13. package/esm/client/1_client_plain.js +27 -15
  14. package/esm/client/2_client_encrypted.d.ts +6 -3
  15. package/esm/client/2_client_encrypted.d.ts.map +1 -1
  16. package/esm/client/2_client_encrypted.js +157 -50
  17. package/esm/client/2_file_manager.js +7 -7
  18. package/esm/client/2_network_statistics_manager.d.ts +2 -2
  19. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  20. package/esm/client/2_network_statistics_manager.js +13 -12
  21. package/esm/client/2_update_manager.d.ts.map +1 -1
  22. package/esm/client/2_update_manager.js +6 -1
  23. package/esm/client/6_client.d.ts +2 -0
  24. package/esm/client/6_client.d.ts.map +1 -1
  25. package/esm/client/6_client.js +14 -11
  26. package/esm/client/6_client_dispatcher.js +2 -2
  27. package/esm/connection/0_get_tls_header.js +5 -5
  28. package/esm/connection/1_connection_socks5.node.js +3 -3
  29. package/esm/connection/1_connection_tcp.node.js +3 -3
  30. package/esm/connection/1_connection_tls.node.js +3 -3
  31. package/esm/connection/1_connection_web_socket.js +4 -4
  32. package/esm/session/0_session_state.d.ts +1 -0
  33. package/esm/session/0_session_state.d.ts.map +1 -1
  34. package/esm/session/0_session_state.js +8 -4
  35. package/esm/session/1_session.d.ts +4 -3
  36. package/esm/session/1_session.d.ts.map +1 -1
  37. package/esm/session/1_session.js +8 -5
  38. package/esm/session/2_session_encrypted.d.ts +11 -6
  39. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  40. package/esm/session/2_session_encrypted.js +22 -14
  41. package/esm/session/2_session_plain.js +2 -2
  42. package/esm/tl/1_tl_writer.js +5 -5
  43. package/esm/tl/2_message.js +1 -1
  44. package/esm/transport/1_transport_abridged.js +1 -1
  45. package/esm/transport/1_transport_intermediate.js +1 -1
  46. package/esm/transport/1_transport_provider.d.ts +2 -2
  47. package/esm/transport/1_transport_provider.d.ts.map +1 -1
  48. package/esm/transport/1_transport_provider.js +5 -5
  49. package/esm/transport/2_transport_provider_mtproxy.js +2 -2
  50. package/esm/transport/2_transport_provider_socks5.js +2 -2
  51. package/esm/transport/2_transport_provider_tcp.js +2 -2
  52. package/esm/transport/2_transport_provider_web_socket.js +3 -3
  53. package/esm/types/1_network_statistics.d.ts +1 -1
  54. package/esm/types/1_network_statistics.d.ts.map +1 -1
  55. package/esm/types/_file_id.js +1 -1
  56. package/esm/utilities/0_int.js +1 -1
  57. package/esm/utilities/1_auth.js +4 -4
  58. package/esm/utilities/1_crypto.js +7 -7
  59. package/package.json +1 -1
  60. package/script/4_constants.d.ts +1 -0
  61. package/script/4_constants.d.ts.map +1 -1
  62. package/script/4_constants.js +2 -1
  63. package/script/client/0_client_abstract.d.ts +1 -1
  64. package/script/client/0_client_abstract.d.ts.map +1 -1
  65. package/script/client/0_client_abstract.js +2 -2
  66. package/script/client/0_password.js +1 -1
  67. package/script/client/0_utilities.d.ts +1 -1
  68. package/script/client/0_utilities.d.ts.map +1 -1
  69. package/script/client/0_utilities.js +5 -5
  70. package/script/client/1_client_plain.d.ts +1 -1
  71. package/script/client/1_client_plain.d.ts.map +1 -1
  72. package/script/client/1_client_plain.js +26 -14
  73. package/script/client/2_client_encrypted.d.ts +6 -3
  74. package/script/client/2_client_encrypted.d.ts.map +1 -1
  75. package/script/client/2_client_encrypted.js +157 -50
  76. package/script/client/2_file_manager.js +7 -7
  77. package/script/client/2_network_statistics_manager.d.ts +2 -2
  78. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  79. package/script/client/2_network_statistics_manager.js +13 -12
  80. package/script/client/2_update_manager.d.ts.map +1 -1
  81. package/script/client/2_update_manager.js +6 -1
  82. package/script/client/6_client.d.ts +2 -0
  83. package/script/client/6_client.d.ts.map +1 -1
  84. package/script/client/6_client.js +14 -11
  85. package/script/client/6_client_dispatcher.js +2 -2
  86. package/script/connection/0_get_tls_header.js +5 -5
  87. package/script/connection/1_connection_socks5.node.js +3 -3
  88. package/script/connection/1_connection_tcp.node.js +3 -3
  89. package/script/connection/1_connection_tls.node.js +3 -3
  90. package/script/connection/1_connection_web_socket.js +4 -4
  91. package/script/session/0_session_state.d.ts +1 -0
  92. package/script/session/0_session_state.d.ts.map +1 -1
  93. package/script/session/0_session_state.js +8 -4
  94. package/script/session/1_session.d.ts +4 -3
  95. package/script/session/1_session.d.ts.map +1 -1
  96. package/script/session/1_session.js +8 -5
  97. package/script/session/2_session_encrypted.d.ts +11 -6
  98. package/script/session/2_session_encrypted.d.ts.map +1 -1
  99. package/script/session/2_session_encrypted.js +22 -14
  100. package/script/session/2_session_plain.js +2 -2
  101. package/script/tl/1_tl_writer.js +5 -5
  102. package/script/tl/2_message.js +1 -1
  103. package/script/transport/1_transport_abridged.js +1 -1
  104. package/script/transport/1_transport_intermediate.js +1 -1
  105. package/script/transport/1_transport_provider.d.ts +2 -2
  106. package/script/transport/1_transport_provider.d.ts.map +1 -1
  107. package/script/transport/1_transport_provider.js +5 -5
  108. package/script/transport/2_transport_provider_mtproxy.js +2 -2
  109. package/script/transport/2_transport_provider_socks5.js +2 -2
  110. package/script/transport/2_transport_provider_tcp.js +2 -2
  111. package/script/transport/2_transport_provider_web_socket.js +3 -3
  112. package/script/types/1_network_statistics.d.ts +1 -1
  113. package/script/types/1_network_statistics.d.ts.map +1 -1
  114. package/script/types/_file_id.js +1 -1
  115. package/script/utilities/0_int.js +1 -1
  116. package/script/utilities/1_auth.js +4 -4
  117. package/script/utilities/1_crypto.js +7 -7
@@ -61,9 +61,15 @@ class SessionEncrypted extends _1_session_js_1.Session {
61
61
  this.#authKeyId = (0, _1_utilities_js_1.intFromBytes)(hash.slice(-8));
62
62
  this.#authKey = key;
63
63
  }
64
+ get id() {
65
+ return this.#id;
66
+ }
64
67
  get authKey() {
65
68
  return this.#authKey;
66
69
  }
70
+ get authKeyId() {
71
+ return this.#authKeyId;
72
+ }
67
73
  async connect() {
68
74
  if (!this.isConnected) {
69
75
  this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was closed."));
@@ -82,6 +88,8 @@ class SessionEncrypted extends _1_session_js_1.Session {
82
88
  super.disconnect();
83
89
  this.state.reset();
84
90
  this.#id = (0, _1_utilities_js_1.getRandomId)();
91
+ this.#receiveLoop.abort();
92
+ this.#sendLoop.abort();
85
93
  this.#pingLoop.abort();
86
94
  this.#awakeSendLoop?.();
87
95
  this.#rejectAllPending(new _0_errors_js_1.ConnectionError("The connection was disconnected."));
@@ -140,11 +148,11 @@ class SessionEncrypted extends _1_session_js_1.Session {
140
148
  return;
141
149
  }
142
150
  // message was not sent by us
143
- this.handlers.onMessageFailed?.(id, reason);
151
+ (0, _1_utilities_js_1.drop)(this.handlers.onMessageFailed?.(id, reason));
144
152
  }
145
153
  #setServerSalt(newServerSalt) {
146
154
  this.state.serverSalt = newServerSalt;
147
- this.handlers.onNewServerSalt?.(newServerSalt);
155
+ (0, _1_utilities_js_1.drop)(this.handlers.onNewServerSalt?.(newServerSalt));
148
156
  }
149
157
  async send(body) {
150
158
  if (!this.isDisconnected && !this.isConnected) {
@@ -159,7 +167,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
159
167
  async #receive() {
160
168
  this.#assertNotDisconnected();
161
169
  const buffer = await this.transport.transport.receive();
162
- if (buffer.length === 4) {
170
+ if (buffer.byteLength === 4) {
163
171
  const int = (0, _1_utilities_js_1.intFromBytes)(buffer);
164
172
  throw new _0_errors_js_1.TransportError(Number(int));
165
173
  }
@@ -197,8 +205,8 @@ class SessionEncrypted extends _1_session_js_1.Session {
197
205
  (0, _0_deps_js_1.assertEquals)(reader.readInt64(), this.#authKeyId);
198
206
  const messageKey_ = reader.readInt128();
199
207
  const messageKey = (0, _1_utilities_js_1.intToBytes)(messageKey_, 16);
200
- if (reader.buffer.length % 16 !== 0) {
201
- reader = new _2_tl_js_1.TLReader(reader.buffer.subarray(0, -(reader.buffer.length % 16)));
208
+ if (reader.buffer.byteLength % 16 !== 0) {
209
+ reader = new _2_tl_js_1.TLReader(reader.buffer.subarray(0, -(reader.buffer.byteLength % 16)));
202
210
  }
203
211
  const a = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.subarray(8, 44)]));
204
212
  const b = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([this.#authKey.subarray(48, 84), messageKey]));
@@ -304,11 +312,11 @@ class SessionEncrypted extends _1_session_js_1.Session {
304
312
  if (!this.isConnected) {
305
313
  this.#LreceiveLoop.debug("aborting as not connected");
306
314
  loop.abort();
307
- return;
308
315
  }
309
- else {
310
- return;
316
+ else if (err instanceof _0_errors_js_1.TransportError) {
317
+ await this.handlers.onTransportError?.(err);
311
318
  }
319
+ return;
312
320
  }
313
321
  try {
314
322
  if (message.body instanceof Uint8Array) {
@@ -324,7 +332,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
324
332
  }
325
333
  //// RECEIVE LOOP HANDLERS ////
326
334
  async #onMessage(msgId, body, containerId) {
327
- this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.length, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
335
+ this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.byteLength, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
328
336
  const logger = this.#LreceiveLoop.branch(msgId + "");
329
337
  let reader = new _2_tl_js_1.TLReader(body);
330
338
  let id = reader.readInt32(false);
@@ -334,13 +342,13 @@ class SessionEncrypted extends _1_session_js_1.Session {
334
342
  id = reader.readInt32(false);
335
343
  }
336
344
  if (id === RPC_RESULT) {
337
- this.#onRpcResult(msgId, reader.buffer, logger);
345
+ await this.#onRpcResult(msgId, reader.buffer, logger);
338
346
  return;
339
347
  }
340
348
  if (!_2_tl_js_1.Mtproto.schema.identifierToName[id]) {
341
349
  logger.debug("identified body as a non-MTProto constructor");
342
350
  reader.unreadInt32();
343
- this.handlers.onUpdate?.(reader.buffer);
351
+ await this.handlers.onUpdate?.(reader.buffer);
344
352
  return;
345
353
  }
346
354
  let type;
@@ -393,10 +401,10 @@ class SessionEncrypted extends _1_session_js_1.Session {
393
401
  if (id === RPC_ERROR) {
394
402
  logger.debug("received rpc_error from message", msgId);
395
403
  const error = await _2_tl_js_1.Mtproto.deserializeType("rpc_error", reader);
396
- this.handlers.onRpcError?.(reqMsgId, error);
404
+ await this.handlers.onRpcError?.(reqMsgId, error);
397
405
  }
398
406
  else {
399
- this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
407
+ await this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
400
408
  }
401
409
  }
402
410
  #onMsgDetailedInfo(msgDetailedInfo, logger) {
@@ -448,7 +456,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
448
456
  }
449
457
  else {
450
458
  // pong is not ours
451
- this.handlers.onPong?.(pong);
459
+ (0, _1_utilities_js_1.drop)(this.handlers.onPong?.(pong));
452
460
  }
453
461
  }
454
462
  #onNewSessionCreated(msgId, newSessionCreated) {
@@ -34,7 +34,7 @@ class SessionPlain extends _1_session_js_1.Session {
34
34
  const writer = new _1_tl_writer_js_1.TLWriter();
35
35
  writer.writeInt64(0n); // auth key ID
36
36
  writer.writeInt64(messageId);
37
- writer.writeInt32(data.length);
37
+ writer.writeInt32(data.byteLength);
38
38
  writer.write(data);
39
39
  const payload = writer.buffer;
40
40
  await this.transport.transport.send(payload);
@@ -45,7 +45,7 @@ class SessionPlain extends _1_session_js_1.Session {
45
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
- if (buffer.length === 4) {
48
+ if (buffer.byteLength === 4) {
49
49
  const int = (0, _1_utilities_js_1.intFromBytes)(buffer);
50
50
  throw new _0_errors_js_1.TransportError(Number(int));
51
51
  }
@@ -66,14 +66,14 @@ class TLWriter {
66
66
  }
67
67
  writeBytes(bytes) {
68
68
  let padding;
69
- if (bytes.length > 253) {
69
+ if (bytes.byteLength > 253) {
70
70
  this.write(new Uint8Array([254]));
71
- this.writeInt24(bytes.length);
72
- padding = bytes.length % 4;
71
+ this.writeInt24(bytes.byteLength);
72
+ padding = bytes.byteLength % 4;
73
73
  }
74
74
  else {
75
- this.write(new Uint8Array([bytes.length]));
76
- padding = (bytes.length + 1) % 4;
75
+ this.write(new Uint8Array([bytes.byteLength]));
76
+ padding = (bytes.byteLength + 1) % 4;
77
77
  }
78
78
  this.write(bytes);
79
79
  if (padding > 0) {
@@ -37,7 +37,7 @@ async function serializeMessage(message) {
37
37
  const writer = new _1_tl_writer_js_1.TLWriter()
38
38
  .writeInt64(message.msg_id)
39
39
  .writeInt32(message.seqno)
40
- .writeInt32(body.length)
40
+ .writeInt32(body.byteLength)
41
41
  .write(body);
42
42
  return writer.buffer;
43
43
  }
@@ -62,7 +62,7 @@ class TransportAbridged extends _0_transport_js_1.Transport {
62
62
  return await this.decrypt(buffer);
63
63
  }
64
64
  async send(buffer) {
65
- const bufferLength = buffer.length / 4;
65
+ const bufferLength = buffer.byteLength / 4;
66
66
  const header = new Uint8Array([bufferLength >= 0x7F ? 0x7F : bufferLength]);
67
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]);
@@ -98,7 +98,7 @@ class TransportIntermediate extends _0_transport_js_1.Transport {
98
98
  const padding = dntShim.crypto.getRandomValues(new Uint8Array(Math.abs((0, _1_utilities_js_1.getRandomId)(true) % 16)));
99
99
  buffer = (0, _0_deps_js_1.concat)([buffer, padding]);
100
100
  }
101
- const length = (0, _1_utilities_js_1.intToBytes)(buffer.length, 4);
101
+ const length = (0, _1_utilities_js_1.intToBytes)(buffer.byteLength, 4);
102
102
  const data = (0, _0_deps_js_1.concat)([length, buffer]);
103
103
  await this.#connection.write(await this.encrypt(data));
104
104
  }
@@ -23,13 +23,13 @@ export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
23
23
  export declare function getDcIps(dc: DC, version: "ipv4" | "ipv6"): [string, ...string[]];
24
24
  export interface TransportProviderParams {
25
25
  dc: DC;
26
- isCdn: boolean;
26
+ isMedia: boolean;
27
27
  }
28
28
  export type TransportProvider = (params: TransportProviderParams) => {
29
29
  connection: Connection;
30
30
  transport: Transport;
31
31
  dcId: number;
32
32
  };
33
- export declare function getDcId(dc: DC, isCdn: boolean): number;
33
+ export declare function getDcId(dc: DC, isMedia: boolean): number;
34
34
  export declare function getDc(dcId: number): DC;
35
35
  //# sourceMappingURL=1_transport_provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"1_transport_provider.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAiDhF;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,EAAE,CAAC;IACP,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,uBAAuB,KAAK;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpI,wBAAgB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAOtC"}
1
+ {"version":3,"file":"1_transport_provider.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAiDhF;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,EAAE,CAAC;IACP,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,uBAAuB,KAAK;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpI,wBAAgB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAOtC"}
@@ -73,14 +73,14 @@ function getDcIps(dc, version) {
73
73
  (0, _0_deps_js_1.unreachable)();
74
74
  }
75
75
  }
76
- function getDcId(dc, isCdn) {
77
- return Number(dc[0]) + (dc.endsWith("-test") ? 10_000 : 0) * (isCdn ? -1 : 1);
76
+ function getDcId(dc, isMedia) {
77
+ return Number(dc[0]) + (dc.endsWith("-test") ? 10_000 : 0) * (isMedia ? -1 : 1);
78
78
  }
79
79
  function getDc(dcId) {
80
80
  dcId = Math.abs(dcId);
81
- const test = dcId >= 10_000;
82
- if (dcId >= 10_000) {
81
+ const isTest = dcId >= 10_000;
82
+ if (isTest) {
83
83
  dcId -= 10_000;
84
84
  }
85
- return `${dcId}${test ? "-test" : ""}`;
85
+ return `${dcId}${isTest ? "-test" : ""}`;
86
86
  }
@@ -45,8 +45,8 @@ function transportProviderMtproxy(urlOrHostname, port, secret) {
45
45
  throw new TypeError("Proxy secret must be at least 16 bytes.");
46
46
  }
47
47
  }
48
- return ({ dc, isCdn }) => {
49
- const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
48
+ return ({ dc, isMedia }) => {
49
+ const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isMedia);
50
50
  const connection = secret.byteLength <= 17 ? new _1_connection_tcp_node_js_1.ConnectionTCP(hostname, port) : new _1_connection_tls_node_js_1.ConnectionTLS(hostname, port, secret);
51
51
  const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isPadded: true, isObfuscated: true, secret, dcId });
52
52
  return { connection, transport, dcId };
@@ -39,8 +39,8 @@ function transportProviderSocks5(urlOrHostname, port, params) {
39
39
  port = parseInt(port_);
40
40
  params = { ...(params ?? {}), username, password };
41
41
  }
42
- return ({ dc, isCdn }) => {
43
- const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
42
+ return ({ dc, isMedia }) => {
43
+ const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isMedia);
44
44
  const connection = new _1_connection_socks5_node_js_1.ConnectionSocks5((0, _1_transport_provider_js_1.getDcIps)(dc, (0, _0_deps_js_1.isIPv6)(hostname) ? "ipv6" : "ipv4")[0], 80, hostname, port, params);
45
45
  const transport = new _1_transport_abridged_js_1.TransportAbridged(connection, false);
46
46
  return { connection, transport, dcId };
@@ -24,9 +24,9 @@ const _1_connection_tcp_node_js_1 = require("../connection/1_connection_tcp.node
24
24
  const _1_transport_abridged_js_1 = require("./1_transport_abridged.js");
25
25
  const _1_transport_provider_js_1 = require("./1_transport_provider.js");
26
26
  function transportProviderTcp(params) {
27
- return ({ dc, isCdn: cdn }) => {
27
+ return ({ dc, isMedia }) => {
28
28
  const connection = new _1_connection_tcp_node_js_1.ConnectionTCP((0, _1_transport_provider_js_1.getDcIps)(dc, params?.ipv6 ? "ipv6" : "ipv4")[0], 80);
29
29
  const transport = new _1_transport_abridged_js_1.TransportAbridged(connection, params?.obfuscated);
30
- return { connection, transport, dcId: (0, _1_transport_provider_js_1.getDcId)(dc, cdn) };
30
+ return { connection, transport, dcId: (0, _1_transport_provider_js_1.getDcId)(dc, isMedia) };
31
31
  };
32
32
  }
@@ -34,12 +34,12 @@ const dcToNameMap = {
34
34
  "5": "flora",
35
35
  };
36
36
  const transportProviderWebSocket = (params) => {
37
- return ({ dc, isCdn }) => {
37
+ return ({ dc, isMedia }) => {
38
38
  params ??= {};
39
39
  params.wss ??= typeof location !== "undefined" && location.protocol === "http:" && location.hostname !== "localhost" ? false : true;
40
- const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${isCdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
40
+ const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${isMedia ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
41
41
  const connection = new _2_connection_js_1.ConnectionWebSocket(url);
42
- const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
42
+ const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isMedia);
43
43
  const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isObfuscated: true, dcId });
44
44
  return { connection, transport, dcId };
45
45
  };
@@ -21,6 +21,6 @@ import type { NetworkStatisticsEntry } from "./0_network_statistics_entry.js";
21
21
  /** A client's network statistics. */
22
22
  export interface NetworkStatistics {
23
23
  messages: NetworkStatisticsEntry;
24
- cdn: NetworkStatisticsEntry;
24
+ media: NetworkStatisticsEntry;
25
25
  }
26
26
  //# sourceMappingURL=1_network_statistics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"1_network_statistics.d.ts","sourceRoot":"","sources":["../../src/types/1_network_statistics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,GAAG,EAAE,sBAAsB,CAAC;CAC7B"}
1
+ {"version":3,"file":"1_network_statistics.d.ts","sourceRoot":"","sources":["../../src/types/1_network_statistics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,EAAE,sBAAsB,CAAC;CAC/B"}
@@ -261,7 +261,7 @@ function hasFileReference(fileType) {
261
261
  }
262
262
  function deserializeFileId(fileId) {
263
263
  const reader = new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)((0, _1_utilities_js_1.base64DecodeUrlSafe)(fileId)));
264
- if (reader.buffer[reader.buffer.length - 1] !== PERSISTENT_ID_VERSION) {
264
+ if (reader.buffer[reader.buffer.byteLength - 1] !== PERSISTENT_ID_VERSION) {
265
265
  throw new _0_errors_js_1.InputError("Unsupported file ID format");
266
266
  }
267
267
  const originalType = reader.readInt32();
@@ -89,7 +89,7 @@ function mod(n, m) {
89
89
  * @param params Additional parameters.
90
90
  */
91
91
  function intFromBytes(bytes, { byteOrder = "little", isSigned = true } = {}) {
92
- const bytesLength = bytes.length;
92
+ const bytesLength = bytes.byteLength;
93
93
  if (byteOrder === "little") {
94
94
  bytes = bytes.toReversed();
95
95
  }
@@ -58,14 +58,14 @@ const _0_deps_js_1 = require("../0_deps.js");
58
58
  const _0_hash_js_1 = require("./0_hash.js");
59
59
  const _0_int_js_1 = require("./0_int.js");
60
60
  async function rsaPad(data, [serverKey, exponent]) {
61
- (0, _0_deps_js_1.assert)(data.length <= 144);
61
+ (0, _0_deps_js_1.assert)(data.byteLength <= 144);
62
62
  let keyAesEncryptedInt;
63
63
  let tries = 0;
64
64
  do {
65
65
  if (++tries === 10) {
66
66
  throw new Error("Out of tries");
67
67
  }
68
- const dataWithPadding = (0, _0_deps_js_1.concat)([data, new Uint8Array(192 - data.length)]);
68
+ const dataWithPadding = (0, _0_deps_js_1.concat)([data, new Uint8Array(192 - data.byteLength)]);
69
69
  const dataPadReversed = new Uint8Array(dataWithPadding).reverse();
70
70
  const tempKey = dntShim.crypto.getRandomValues(new Uint8Array(32));
71
71
  const dataWithHash = (0, _0_deps_js_1.concat)([dataPadReversed, await (0, _0_hash_js_1.sha256)((0, _0_deps_js_1.concat)([tempKey, dataWithPadding]))]);
@@ -73,11 +73,11 @@ async function rsaPad(data, [serverKey, exponent]) {
73
73
  const aesEncryptedSha256 = await (0, _0_hash_js_1.sha256)(aesEncrypted);
74
74
  const tempKeyXor = tempKey.map((v, i) => v ^ aesEncryptedSha256[i]);
75
75
  const keyAesEncrypted = (0, _0_deps_js_1.concat)([tempKeyXor, aesEncrypted]);
76
- (0, _0_deps_js_1.assertEquals)(keyAesEncrypted.length, 256);
76
+ (0, _0_deps_js_1.assertEquals)(keyAesEncrypted.byteLength, 256);
77
77
  keyAesEncryptedInt = (0, _0_int_js_1.intFromBytes)(keyAesEncrypted, { byteOrder: "big", isSigned: false });
78
78
  } while (keyAesEncryptedInt >= serverKey);
79
79
  const encryptedDataInt = (0, _0_int_js_1.modExp)(keyAesEncryptedInt, exponent, serverKey);
80
80
  const encryptedData = (0, _0_int_js_1.intToBytes)(encryptedDataInt, 256, { byteOrder: "big", isSigned: false });
81
- (0, _0_deps_js_1.assertEquals)(encryptedData.length, 256);
81
+ (0, _0_deps_js_1.assertEquals)(encryptedData.byteLength, 256);
82
82
  return encryptedData;
83
83
  }
@@ -81,11 +81,11 @@ class CTR {
81
81
  async #call(data) {
82
82
  let header;
83
83
  if (this.#bytesUntilNextBlock) {
84
- const headerLength = Math.min(data.length, this.#iv.length - this.#bytesUntilNextBlock);
84
+ const headerLength = Math.min(data.byteLength, this.#iv.byteLength - this.#bytesUntilNextBlock);
85
85
  const encrypted = await this.#encrypt((0, _0_deps_js_1.concat)([new Uint8Array(this.#bytesUntilNextBlock), data.subarray(0, headerLength)]));
86
86
  header = encrypted.subarray(this.#bytesUntilNextBlock);
87
87
  data = data.subarray(headerLength);
88
- if (encrypted.length === this.#iv.length) {
88
+ if (encrypted.byteLength === this.#iv.byteLength) {
89
89
  this.#increaseIv(1);
90
90
  this.#bytesUntilNextBlock = 0;
91
91
  }
@@ -93,26 +93,26 @@ class CTR {
93
93
  this.#bytesUntilNextBlock += headerLength;
94
94
  }
95
95
  }
96
- if (!data.length && header) {
96
+ if (!data.byteLength && header) {
97
97
  return header;
98
98
  }
99
99
  const encrypted = await this.#encrypt(data);
100
- this.#bytesUntilNextBlock = encrypted.length % this.#iv.length;
101
- this.#increaseIv((encrypted.length - this.#bytesUntilNextBlock) / this.#iv.length);
100
+ this.#bytesUntilNextBlock = encrypted.byteLength % this.#iv.byteLength;
101
+ this.#increaseIv((encrypted.byteLength - this.#bytesUntilNextBlock) / this.#iv.byteLength);
102
102
  return header ? (0, _0_deps_js_1.concat)([header, encrypted]) : encrypted;
103
103
  }
104
104
  async #encrypt(data) {
105
105
  return new Uint8Array(await dntShim.crypto.subtle.encrypt({
106
106
  name: "AES-CTR",
107
107
  counter: new Uint8Array(this.#iv),
108
- length: this.#iv.length * 8,
108
+ length: this.#iv.byteLength * 8,
109
109
  }, this.#key, data));
110
110
  }
111
111
  #increaseIv(amount) {
112
112
  if (amount < 1) {
113
113
  return;
114
114
  }
115
- this.#iv = (0, _0_int_js_1.intToBytes)((0, _0_int_js_1.intFromBytes)(this.#iv, { byteOrder: "big", isSigned: false }) + BigInt(amount), this.#iv.length, { byteOrder: "big", isSigned: false });
115
+ this.#iv = (0, _0_int_js_1.intToBytes)((0, _0_int_js_1.intFromBytes)(this.#iv, { byteOrder: "big", isSigned: false }) + BigInt(amount), this.#iv.byteLength, { byteOrder: "big", isSigned: false });
116
116
  }
117
117
  }
118
118
  exports.CTR = CTR;