@mtkruto/node 0.152.0 → 0.153.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 (85) hide show
  1. package/esm/client/0_client_abstract.d.ts +1 -1
  2. package/esm/client/0_client_abstract.d.ts.map +1 -1
  3. package/esm/client/0_client_abstract.js +2 -2
  4. package/esm/client/0_password.js +1 -1
  5. package/esm/client/0_utilities.d.ts +1 -1
  6. package/esm/client/0_utilities.d.ts.map +1 -1
  7. package/esm/client/0_utilities.js +4 -4
  8. package/esm/client/1_client_plain.js +2 -2
  9. package/esm/client/2_client_encrypted.js +3 -3
  10. package/esm/client/2_file_manager.js +7 -7
  11. package/esm/client/2_network_statistics_manager.d.ts +2 -2
  12. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  13. package/esm/client/2_network_statistics_manager.js +10 -10
  14. package/esm/client/6_client.js +10 -10
  15. package/esm/client/6_client_dispatcher.js +2 -2
  16. package/esm/connection/0_get_tls_header.js +5 -5
  17. package/esm/connection/1_connection_socks5.node.js +3 -3
  18. package/esm/connection/1_connection_tcp.node.js +3 -3
  19. package/esm/connection/1_connection_tls.node.js +3 -3
  20. package/esm/connection/1_connection_web_socket.js +4 -4
  21. package/esm/session/1_session.d.ts +3 -3
  22. package/esm/session/1_session.d.ts.map +1 -1
  23. package/esm/session/1_session.js +5 -5
  24. package/esm/session/2_session_encrypted.js +4 -4
  25. package/esm/session/2_session_plain.js +2 -2
  26. package/esm/tl/1_tl_writer.js +5 -5
  27. package/esm/tl/2_message.js +1 -1
  28. package/esm/transport/1_transport_abridged.js +1 -1
  29. package/esm/transport/1_transport_intermediate.js +1 -1
  30. package/esm/transport/1_transport_provider.d.ts +2 -2
  31. package/esm/transport/1_transport_provider.d.ts.map +1 -1
  32. package/esm/transport/1_transport_provider.js +5 -5
  33. package/esm/transport/2_transport_provider_mtproxy.js +2 -2
  34. package/esm/transport/2_transport_provider_socks5.js +2 -2
  35. package/esm/transport/2_transport_provider_tcp.js +2 -2
  36. package/esm/transport/2_transport_provider_web_socket.js +3 -3
  37. package/esm/types/1_network_statistics.d.ts +1 -1
  38. package/esm/types/1_network_statistics.d.ts.map +1 -1
  39. package/esm/types/_file_id.js +1 -1
  40. package/esm/utilities/0_int.js +1 -1
  41. package/esm/utilities/1_auth.js +4 -4
  42. package/esm/utilities/1_crypto.js +7 -7
  43. package/package.json +1 -1
  44. package/script/client/0_client_abstract.d.ts +1 -1
  45. package/script/client/0_client_abstract.d.ts.map +1 -1
  46. package/script/client/0_client_abstract.js +2 -2
  47. package/script/client/0_password.js +1 -1
  48. package/script/client/0_utilities.d.ts +1 -1
  49. package/script/client/0_utilities.d.ts.map +1 -1
  50. package/script/client/0_utilities.js +5 -5
  51. package/script/client/1_client_plain.js +2 -2
  52. package/script/client/2_client_encrypted.js +2 -2
  53. package/script/client/2_file_manager.js +7 -7
  54. package/script/client/2_network_statistics_manager.d.ts +2 -2
  55. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  56. package/script/client/2_network_statistics_manager.js +10 -10
  57. package/script/client/6_client.js +10 -10
  58. package/script/client/6_client_dispatcher.js +2 -2
  59. package/script/connection/0_get_tls_header.js +5 -5
  60. package/script/connection/1_connection_socks5.node.js +3 -3
  61. package/script/connection/1_connection_tcp.node.js +3 -3
  62. package/script/connection/1_connection_tls.node.js +3 -3
  63. package/script/connection/1_connection_web_socket.js +4 -4
  64. package/script/session/1_session.d.ts +3 -3
  65. package/script/session/1_session.d.ts.map +1 -1
  66. package/script/session/1_session.js +5 -5
  67. package/script/session/2_session_encrypted.js +4 -4
  68. package/script/session/2_session_plain.js +2 -2
  69. package/script/tl/1_tl_writer.js +5 -5
  70. package/script/tl/2_message.js +1 -1
  71. package/script/transport/1_transport_abridged.js +1 -1
  72. package/script/transport/1_transport_intermediate.js +1 -1
  73. package/script/transport/1_transport_provider.d.ts +2 -2
  74. package/script/transport/1_transport_provider.d.ts.map +1 -1
  75. package/script/transport/1_transport_provider.js +5 -5
  76. package/script/transport/2_transport_provider_mtproxy.js +2 -2
  77. package/script/transport/2_transport_provider_socks5.js +2 -2
  78. package/script/transport/2_transport_provider_tcp.js +2 -2
  79. package/script/transport/2_transport_provider_web_socket.js +3 -3
  80. package/script/types/1_network_statistics.d.ts +1 -1
  81. package/script/types/1_network_statistics.d.ts.map +1 -1
  82. package/script/types/_file_id.js +1 -1
  83. package/script/utilities/0_int.js +1 -1
  84. package/script/utilities/1_auth.js +4 -4
  85. package/script/utilities/1_crypto.js +7 -7
@@ -103,7 +103,7 @@ class FileManager {
103
103
  _a.validateChunkSize(chunkSize, _a.#UPLOAD_MAX_CHUNK_SIZE);
104
104
  const mustTrackProgress = params?.progressId !== undefined;
105
105
  const fileId = params?.progressId !== undefined ? BigInt(params.progressId) : (0, _1_utilities_js_1.getRandomId)();
106
- const isBig = contents instanceof Uint8Array ? contents.length > _a.#BIG_FILE_THRESHOLD : true;
106
+ const isBig = contents instanceof Uint8Array ? contents.byteLength > _a.#BIG_FILE_THRESHOLD : true;
107
107
  const whatIsUploaded = contents instanceof Uint8Array ? (isBig ? "big file" : "file") + " of size " + size : "stream";
108
108
  this.#Lupload.debug("uploading " + whatIsUploaded + " with chunk size of " + chunkSize + " and pool size of " + poolSize + " and file ID of " + fileId);
109
109
  let result;
@@ -140,7 +140,7 @@ class FileManager {
140
140
  }
141
141
  promises.push(this.#uploadPart(fileId, part.totalParts, !part.isSmall, part.part, part.bytes, signal).then(() => {
142
142
  if (mustTrackProgress) {
143
- uploaded += part.bytes.length;
143
+ uploaded += part.bytes.byteLength;
144
144
  this.#c.handleUpdate({
145
145
  type: "uploadProgress",
146
146
  uploadProgress: {
@@ -183,7 +183,7 @@ class FileManager {
183
183
  const start = part * chunkSize;
184
184
  const end = start + chunkSize;
185
185
  const bytes = buffer.subarray(start, end);
186
- if (!bytes.length) {
186
+ if (!bytes.byteLength) {
187
187
  break main;
188
188
  }
189
189
  if (!started) {
@@ -198,13 +198,13 @@ class FileManager {
198
198
  }
199
199
  promises.push(this.#uploadPart(fileId, partCount, isBig, part++, bytes, signal).then(() => {
200
200
  if (mustTrackProgress) {
201
- uploaded += bytes.length;
201
+ uploaded += bytes.byteLength;
202
202
  this.#c.handleUpdate({
203
203
  type: "uploadProgress",
204
204
  uploadProgress: {
205
205
  id: String(fileId),
206
206
  uploaded,
207
- total: buffer.length,
207
+ total: buffer.byteLength,
208
208
  isUploaded: false,
209
209
  },
210
210
  });
@@ -400,7 +400,7 @@ class FileManager {
400
400
  signal?.throwIfAborted();
401
401
  }
402
402
  ++part;
403
- if (file.bytes.length < limit) {
403
+ if (file.bytes.byteLength < limit) {
404
404
  if (id !== null) {
405
405
  await this.#c.storage.setFilePartCount(id, part + 1, chunkSize);
406
406
  signal?.throwIfAborted();
@@ -408,7 +408,7 @@ class FileManager {
408
408
  break;
409
409
  }
410
410
  else {
411
- offset += BigInt(file.bytes.length);
411
+ offset += BigInt(file.bytes.byteLength);
412
412
  }
413
413
  }
414
414
  else {
@@ -26,12 +26,12 @@ export declare class NetworkStatisticsManager {
26
26
  sent: number;
27
27
  received: number;
28
28
  };
29
- cdn: {
29
+ media: {
30
30
  sent: number;
31
31
  received: number;
32
32
  };
33
33
  }>;
34
- getTransportReadWriteCallback(isCcdn: boolean): {
34
+ getTransportReadWriteCallback(isMedia: boolean): {
35
35
  read: (count: number) => void;
36
36
  write: (count: number) => void;
37
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"2_network_statistics_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_network_statistics_manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEtC,qBAAa,wBAAwB;;gBAIvB,CAAC,EAAE,CAAC;IAKV,oBAAoB;;;;;;;;;;IAmB1B,6BAA6B,CAAC,MAAM,EAAE,OAAO;sBAE3B,MAAM;uBAKL,MAAM;;CA2B1B"}
1
+ {"version":3,"file":"2_network_statistics_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_network_statistics_manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEtC,qBAAa,wBAAwB;;gBAIvB,CAAC,EAAE,CAAC;IAKV,oBAAoB;;;;;;;;;;IAmB1B,6BAA6B,CAAC,OAAO,EAAE,OAAO;sBAE5B,MAAM;uBAKL,MAAM;;CA2B1B"}
@@ -29,32 +29,32 @@ class NetworkStatisticsManager {
29
29
  this.#L = (0, _1_logger_js_1.getLogger)("NetworkStatisticsManager");
30
30
  }
31
31
  async getNetworkStatistics() {
32
- const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
32
+ const [messagesRead, messagesWrite, mediaRead, mediaWrite] = await Promise.all([
33
33
  this.#c.storage.get(["netstat_messages_read"]),
34
34
  this.#c.storage.get(["netstat_messages_write"]),
35
- this.#c.storage.get(["netstat_cdn_read"]),
36
- this.#c.storage.get(["netstat_cdn_write"]),
35
+ this.#c.storage.get(["netstat_media_read"]),
36
+ this.#c.storage.get(["netstat_media_write"]),
37
37
  ]);
38
38
  const messages = {
39
39
  sent: Number(messagesWrite || 0),
40
40
  received: Number(messagesRead || 0),
41
41
  };
42
- const cdn = {
43
- sent: Number(cdnWrite || 0),
44
- received: Number(cdnRead || 0),
42
+ const media = {
43
+ sent: Number(mediaWrite || 0),
44
+ received: Number(mediaRead || 0),
45
45
  };
46
- return { messages, cdn };
46
+ return { messages, media };
47
47
  }
48
48
  #pendingWrites = {};
49
- getTransportReadWriteCallback(isCcdn) {
49
+ getTransportReadWriteCallback(isMedia) {
50
50
  return {
51
51
  read: (count) => {
52
- const key = isCcdn ? "netstat_cdn_read" : "netstat_messages_read";
52
+ const key = isMedia ? "netstat_media_read" : "netstat_messages_read";
53
53
  this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
54
54
  this.#write();
55
55
  },
56
56
  write: (count) => {
57
- const key = isCcdn ? "netstat_cdn_write" : "netstat_messages_write";
57
+ const key = isMedia ? "netstat_media_write" : "netstat_messages_write";
58
58
  this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
59
59
  this.#write();
60
60
  },
@@ -305,7 +305,7 @@ class Client extends _5_composer_js_1.Composer {
305
305
  };
306
306
  client.onConnectionStateChange = this.#onConnectionStateChange.bind(this);
307
307
  }
308
- #newClient(dc, main, isCdn) {
308
+ #newClient(dc, main, isMedia) {
309
309
  const client = new _2_client_encrypted_js_1.ClientEncrypted(dc, this.#apiId, {
310
310
  appVersion: this.appVersion,
311
311
  deviceModel: this.deviceModel,
@@ -314,11 +314,11 @@ class Client extends _5_composer_js_1.Composer {
314
314
  systemLangCode: this.systemLangCode,
315
315
  systemVersion: this.systemVersion,
316
316
  transportProvider: this.#transportProvider,
317
- isCdn: isCdn,
318
- disableUpdates: !main || isCdn,
317
+ isMedia,
318
+ disableUpdates: !main || isMedia,
319
319
  publicKeys: this.#publicKeys,
320
320
  });
321
- client.connectionCallback = this.#networkStatisticsManager.getTransportReadWriteCallback(isCdn);
321
+ client.connectionCallback = this.#networkStatisticsManager.getTransportReadWriteCallback(isMedia);
322
322
  return client;
323
323
  }
324
324
  #disconnectAllClients() {
@@ -420,7 +420,7 @@ class Client extends _5_composer_js_1.Composer {
420
420
  }
421
421
  async [exports.handleMigrationError](err) {
422
422
  let newDc = String(err.dc);
423
- if (Math.abs((0, _3_transport_js_1.getDcId)(this.#client.dc, this.#client.isCdn)) >= 10_000) {
423
+ if (Math.abs((0, _3_transport_js_1.getDcId)(this.#client.dc, this.#client.isMedia)) >= 10_000) {
424
424
  newDc += "-test";
425
425
  }
426
426
  this.disconnect();
@@ -720,7 +720,7 @@ class Client extends _5_composer_js_1.Composer {
720
720
  }
721
721
  }
722
722
  const client = pool.nextClient();
723
- if (client.authKey.length) {
723
+ if (client.authKey.byteLength) {
724
724
  return client;
725
725
  }
726
726
  await this.#setupClient(client);
@@ -740,14 +740,14 @@ class Client extends _5_composer_js_1.Composer {
740
740
  }
741
741
  }
742
742
  const client = pool.nextClient();
743
- if (client.authKey.length) {
743
+ if (client.authKey.byteLength) {
744
744
  return client;
745
745
  }
746
746
  await this.#setupClient(client);
747
747
  return client;
748
748
  }
749
749
  async #setupClient(client) {
750
- const storage = client.dc === this.#client.dc ? this.storage : new _0_storage_operations_js_1.StorageOperations(this.storage.provider.branch(client.dc + (client.isCdn ? "_cdn" : "")));
750
+ const storage = client.dc === this.#client.dc ? this.storage : new _0_storage_operations_js_1.StorageOperations(this.storage.provider.branch(client.dc + (client.isMedia ? "_media" : "")));
751
751
  await storage.initialize();
752
752
  const auth = storage.auth.mustGet();
753
753
  const serverSalt = await storage.getServerSalt();
@@ -770,7 +770,7 @@ class Client extends _5_composer_js_1.Composer {
770
770
  }
771
771
  }
772
772
  async #importAuthorization(client) {
773
- if (this.#client.dc === client.dc && this.#client.isCdn === client.isCdn) {
773
+ if (this.#client.dc === client.dc && this.#client.isMedia === client.isMedia) {
774
774
  const auth = this.storage.auth.mustGet();
775
775
  const serverSalt = await this.storage.getServerSalt();
776
776
  if (auth.authKey !== null) {
@@ -781,7 +781,7 @@ class Client extends _5_composer_js_1.Composer {
781
781
  }
782
782
  return;
783
783
  }
784
- const exportedAuthorization = await this.#client.invoke({ _: "auth.exportAuthorization", dc_id: (0, _3_transport_js_1.getDcId)(client.dc, client.isCdn) });
784
+ const exportedAuthorization = await this.#client.invoke({ _: "auth.exportAuthorization", dc_id: (0, _3_transport_js_1.getDcId)(client.dc, client.isMedia) });
785
785
  await client.invoke({ ...exportedAuthorization, _: "auth.importAuthorization" });
786
786
  }
787
787
  async #invoke(function_, params) {
@@ -1636,11 +1636,11 @@ class ClientDispatcher extends _5_composer_js_1.Composer {
1636
1636
  while (true) {
1637
1637
  const chunk = await this.downloadChunk(fileId, { chunkSize, offset });
1638
1638
  yield chunk;
1639
- if (chunk.length < chunkSize) {
1639
+ if (chunk.byteLength < chunkSize) {
1640
1640
  break;
1641
1641
  }
1642
1642
  else {
1643
- offset += chunk.length;
1643
+ offset += chunk.byteLength;
1644
1644
  }
1645
1645
  }
1646
1646
  }
@@ -80,10 +80,10 @@ const ops = [
80
80
  ];
81
81
  function getGrease() {
82
82
  const res = dntShim.crypto.getRandomValues(new Uint8Array(7));
83
- for (let i = 0; i < res.length; ++i) {
83
+ for (let i = 0; i < res.byteLength; ++i) {
84
84
  res[i] = (res[i] & 0xF0) + 0x0A;
85
85
  }
86
- for (let i = 1; i < res.length; i += 2) {
86
+ for (let i = 1; i < res.byteLength; i += 2) {
87
87
  if (res[i] === res[i - 1]) {
88
88
  res[i] ^= 0x10;
89
89
  }
@@ -157,7 +157,7 @@ function serializeOps(ops, domain) {
157
157
  break;
158
158
  }
159
159
  case "beginScope":
160
- scopes.push(buffer.length);
160
+ scopes.push(buffer.byteLength);
161
161
  buffer = (0, _0_deps_js_1.concat)([buffer, new Uint8Array([0, 0])]);
162
162
  break;
163
163
  case "endScope": {
@@ -165,13 +165,13 @@ function serializeOps(ops, domain) {
165
165
  if (beginOffset === undefined) {
166
166
  throw new TypeError("Invalid endScope");
167
167
  }
168
- const endOffset = buffer.length;
168
+ const endOffset = buffer.byteLength;
169
169
  const size = endOffset - beginOffset - 2;
170
170
  new DataView(buffer.buffer).setUint16(beginOffset, size);
171
171
  break;
172
172
  }
173
173
  case "padding": {
174
- const size = 513 - buffer.length;
174
+ const size = 513 - buffer.byteLength;
175
175
  if (size > 0) {
176
176
  serializeOp({ type: "string", data: new Uint8Array([0x00, 0x15]) });
177
177
  serializeOp({ type: "beginScope" });
@@ -175,10 +175,10 @@ class ConnectionSocks5 {
175
175
  const unlock = await this.#rMutex.lock();
176
176
  try {
177
177
  this.#assertConnected();
178
- if (this.#buffer.length < p.length) {
179
- await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
178
+ if (this.#buffer.length < p.byteLength) {
179
+ await new Promise((resolve, reject) => this.#nextResolve = [p.byteLength, { resolve, reject }]);
180
180
  }
181
- p.set(this.#buffer.splice(0, p.length));
181
+ p.set(this.#buffer.splice(0, p.byteLength));
182
182
  }
183
183
  finally {
184
184
  unlock();
@@ -90,10 +90,10 @@ class ConnectionTCP {
90
90
  const unlock = await this.#rMutex.lock();
91
91
  try {
92
92
  this.#assertConnected();
93
- if (this.#buffer.length < p.length) {
94
- await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
93
+ if (this.#buffer.length < p.byteLength) {
94
+ await new Promise((resolve, reject) => this.#nextResolve = [p.byteLength, { resolve, reject }]);
95
95
  }
96
- p.set(this.#buffer.splice(0, p.length));
96
+ p.set(this.#buffer.splice(0, p.byteLength));
97
97
  }
98
98
  finally {
99
99
  unlock();
@@ -150,10 +150,10 @@ class ConnectionTLS {
150
150
  await this.#write(data);
151
151
  }
152
152
  async #read(p) {
153
- if (this.#buffer.length < p.length) {
154
- await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
153
+ if (this.#buffer.length < p.byteLength) {
154
+ await new Promise((resolve, reject) => this.#nextResolve = [p.byteLength, { resolve, reject }]);
155
155
  }
156
- p.set(this.#buffer.splice(0, p.length));
156
+ p.set(this.#buffer.splice(0, p.byteLength));
157
157
  }
158
158
  async #write(p) {
159
159
  await new Promise((resolve, reject) => {
@@ -132,12 +132,12 @@ class ConnectionWebSocket {
132
132
  const unlock = await this.#rMutex.lock();
133
133
  try {
134
134
  this.#assertConnected();
135
- if (this.#buffer.length < p.length) {
136
- await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
135
+ if (this.#buffer.length < p.byteLength) {
136
+ await new Promise((resolve, reject) => this.#nextResolve = [p.byteLength, { resolve, reject }]);
137
137
  }
138
- const slice = this.#buffer.slice(0, p.length);
138
+ const slice = this.#buffer.slice(0, p.byteLength);
139
139
  p.set(slice);
140
- this.#buffer = this.#buffer.slice(slice.length);
140
+ this.#buffer = this.#buffer.slice(slice.byteLength);
141
141
  }
142
142
  finally {
143
143
  unlock();
@@ -4,8 +4,8 @@ import { SessionState } from "./0_session_state.js";
4
4
  export interface SessionParams {
5
5
  /** The transport provider to use. Defaults to `transportProviderWebsocket` in browsers and `transportProviderTcp` in other runtimes. */
6
6
  transportProvider?: TransportProvider;
7
- /** Whether the connection is with a CDN server. Defaults to false. */
8
- isCdn?: boolean;
7
+ /** Whether the connection is with a media server. Defaults to false. */
8
+ isMedia?: boolean;
9
9
  }
10
10
  export declare abstract class Session {
11
11
  #private;
@@ -15,7 +15,7 @@ export declare abstract class Session {
15
15
  set onConnectionStateChange(onConnectionStateChange: Connection["stateChangeHandler"]);
16
16
  set connectionCallback(connectionCallback: ConnectionCallback | undefined);
17
17
  get dc(): DC;
18
- get isCdn(): boolean;
18
+ get isMedia(): boolean;
19
19
  set serverSalt(serverSalt: bigint);
20
20
  get serverSalt(): bigint;
21
21
  get isConnected(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,MAAM,WAAW,aAAa;IAC5B,wIAAwI;IACxI,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,8BAAsB,OAAO;;IAG3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAsB;IACnD,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;gBAMvC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAc1C,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB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I,OAAO,CAErB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IA6BD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,OAAO;cAeG,kBAAkB;IAIlC,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,UAAU;IAOV,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CACjD"}
@@ -64,7 +64,7 @@ let id = 0;
64
64
  const defaultTransportProvider = typeof dntShim.Deno === "undefined" ? _3_transport_js_1.transportProviderWebSocket : _3_transport_js_1.transportProviderTcp;
65
65
  class Session {
66
66
  #dc;
67
- #isCdn;
67
+ #isMedia;
68
68
  state = new _0_session_state_js_1.SessionState();
69
69
  transport;
70
70
  #lastConnect;
@@ -73,9 +73,9 @@ class Session {
73
73
  #onConnectionStateChange;
74
74
  constructor(dc, params) {
75
75
  this.#dc = dc;
76
- this.#isCdn = params?.isCdn ?? false;
76
+ this.#isMedia = params?.isMedia ?? false;
77
77
  const transportProvider = params?.transportProvider ?? defaultTransportProvider();
78
- this.transport = transportProvider({ dc: this.#dc, isCdn: this.#isCdn });
78
+ this.transport = transportProvider({ dc: this.#dc, isMedia: this.#isMedia });
79
79
  this.transport.connection.stateChangeHandler = (connected) => {
80
80
  setTimeout(() => {
81
81
  (0, _1_utilities_js_1.drop)(this.#stateChangeHandler(connected));
@@ -92,8 +92,8 @@ class Session {
92
92
  get dc() {
93
93
  return this.#dc;
94
94
  }
95
- get isCdn() {
96
- return this.#isCdn;
95
+ get isMedia() {
96
+ return this.#isMedia;
97
97
  }
98
98
  set serverSalt(serverSalt) {
99
99
  this.state.serverSalt = serverSalt;
@@ -159,7 +159,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
159
159
  async #receive() {
160
160
  this.#assertNotDisconnected();
161
161
  const buffer = await this.transport.transport.receive();
162
- if (buffer.length === 4) {
162
+ if (buffer.byteLength === 4) {
163
163
  const int = (0, _1_utilities_js_1.intFromBytes)(buffer);
164
164
  throw new _0_errors_js_1.TransportError(Number(int));
165
165
  }
@@ -197,8 +197,8 @@ class SessionEncrypted extends _1_session_js_1.Session {
197
197
  (0, _0_deps_js_1.assertEquals)(reader.readInt64(), this.#authKeyId);
198
198
  const messageKey_ = reader.readInt128();
199
199
  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)));
200
+ if (reader.buffer.byteLength % 16 !== 0) {
201
+ reader = new _2_tl_js_1.TLReader(reader.buffer.subarray(0, -(reader.buffer.byteLength % 16)));
202
202
  }
203
203
  const a = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.subarray(8, 44)]));
204
204
  const b = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([this.#authKey.subarray(48, 84), messageKey]));
@@ -324,7 +324,7 @@ class SessionEncrypted extends _1_session_js_1.Session {
324
324
  }
325
325
  //// RECEIVE LOOP HANDLERS ////
326
326
  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]));
327
+ this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.byteLength, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
328
328
  const logger = this.#LreceiveLoop.branch(msgId + "");
329
329
  let reader = new _2_tl_js_1.TLReader(body);
330
330
  let id = reader.readInt32(false);
@@ -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,E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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
  }