@mtkruto/node 0.0.906 → 0.0.920

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 (115) hide show
  1. package/esm/{types/utilities → client}/0_html.d.ts +1 -1
  2. package/esm/{types/utilities → client}/0_html.js +2 -2
  3. package/esm/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  4. package/esm/client/{utilities/0_message.js → 0_message.js} +10 -10
  5. package/esm/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  6. package/esm/client/{utilities/0_password.js → 0_password.js} +5 -5
  7. package/{script/client/client_abstract.d.ts → esm/client/1_client_abstract.d.ts} +6 -5
  8. package/esm/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  9. package/esm/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  10. package/esm/client/{client_plain.js → 2_client_plain.js} +2 -2
  11. package/esm/client/{client.d.ts → 3_client.d.ts} +7 -5
  12. package/esm/client/{client.js → 3_client.js} +145 -83
  13. package/{script/connection/connection_web_socket.d.ts → esm/connection/1_connection_web_socket.d.ts} +1 -1
  14. package/esm/constants.d.ts +2 -2
  15. package/esm/constants.js +1 -1
  16. package/esm/deps.d.ts +1 -2
  17. package/esm/deps.js +0 -1
  18. package/esm/mod.d.ts +13 -13
  19. package/esm/mod.js +13 -13
  20. package/esm/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  21. package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts} +1 -1
  22. package/esm/storage/{storage_local_storage.js → 1_storage_local_storage.js} +1 -1
  23. package/{script/storage/storage_memory.d.ts → esm/storage/1_storage_memory.d.ts} +1 -1
  24. package/esm/storage/{storage_memory.js → 1_storage_memory.js} +1 -1
  25. package/esm/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  26. package/esm/storage/{storage_session_storage.js → 1_storage_session_storage.js} +1 -1
  27. package/esm/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  28. package/esm/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  29. package/esm/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  30. package/esm/transport/{transport_abridged.js → 1_transport_abridged.js} +2 -2
  31. package/esm/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  32. package/esm/transport/{transport_intermediate.js → 1_transport_intermediate.js} +2 -2
  33. package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts} +2 -2
  34. package/esm/transport/{transport_provider.js → 2_transport_provider.js} +2 -2
  35. package/esm/types/!0_file_id.d.ts +77 -0
  36. package/esm/types/!0_file_id.js +325 -0
  37. package/esm/types/0_chat_photo.d.ts +7 -14
  38. package/esm/types/0_chat_photo.js +32 -17
  39. package/esm/types/1_chat.js +4 -4
  40. package/esm/types/1_user.js +2 -2
  41. package/esm/types/3_message.js +9 -0
  42. package/esm/utilities/0_base64.d.ts +2 -0
  43. package/esm/utilities/0_base64.js +9 -0
  44. package/esm/utilities/0_rle.d.ts +2 -0
  45. package/esm/utilities/0_rle.js +49 -0
  46. package/package.json +1 -1
  47. package/script/{types/utilities → client}/0_html.d.ts +1 -1
  48. package/script/{types/utilities → client}/0_html.js +2 -2
  49. package/script/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  50. package/script/client/{utilities/0_message.js → 0_message.js} +10 -10
  51. package/script/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  52. package/script/client/{utilities/0_password.js → 0_password.js} +5 -5
  53. package/script/client/0_password_test.d.ts +1 -0
  54. package/{esm/client/client_abstract.d.ts → script/client/1_client_abstract.d.ts} +6 -5
  55. package/script/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  56. package/script/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  57. package/script/client/{client_plain.js → 2_client_plain.js} +3 -3
  58. package/script/client/{client.d.ts → 3_client.d.ts} +7 -5
  59. package/script/client/{client.js → 3_client.js} +146 -84
  60. package/{esm/connection/connection_web_socket.d.ts → script/connection/1_connection_web_socket.d.ts} +1 -1
  61. package/script/constants.d.ts +2 -2
  62. package/script/constants.js +1 -1
  63. package/script/deps.d.ts +1 -2
  64. package/script/deps.js +1 -3
  65. package/script/mod.d.ts +13 -13
  66. package/script/mod.js +13 -13
  67. package/script/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  68. package/{esm/storage/storage_local_storage.d.ts → script/storage/1_storage_local_storage.d.ts} +1 -1
  69. package/script/storage/{storage_local_storage.js → 1_storage_local_storage.js} +2 -2
  70. package/{esm/storage/storage_memory.d.ts → script/storage/1_storage_memory.d.ts} +1 -1
  71. package/script/storage/{storage_memory.js → 1_storage_memory.js} +2 -2
  72. package/script/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  73. package/script/storage/{storage_session_storage.js → 1_storage_session_storage.js} +2 -2
  74. package/script/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  75. package/script/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  76. package/script/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  77. package/script/transport/{transport_abridged.js → 1_transport_abridged.js} +3 -3
  78. package/script/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  79. package/script/transport/{transport_intermediate.js → 1_transport_intermediate.js} +3 -3
  80. package/{esm/transport/transport_provider.d.ts → script/transport/2_transport_provider.d.ts} +2 -2
  81. package/script/transport/{transport_provider.js → 2_transport_provider.js} +4 -4
  82. package/script/types/!0_file_id.d.ts +77 -0
  83. package/script/types/!0_file_id.js +329 -0
  84. package/script/types/0_chat_photo.d.ts +7 -14
  85. package/script/types/0_chat_photo.js +33 -18
  86. package/script/types/1_chat.js +4 -4
  87. package/script/types/1_user.js +2 -2
  88. package/script/types/3_message.js +9 -0
  89. package/script/utilities/0_base64.d.ts +2 -0
  90. package/script/utilities/0_base64.js +14 -0
  91. package/script/utilities/0_rle.d.ts +2 -0
  92. package/script/utilities/0_rle.js +54 -0
  93. package/script/utilities/0_rle_test.d.ts +1 -0
  94. package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  95. package/esm/deps/deno.land/x/q@v0.0.1/mod.js +0 -71
  96. package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  97. package/script/deps/deno.land/x/q@v0.0.1/mod.js +0 -75
  98. /package/esm/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
  99. /package/esm/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  100. /package/esm/connection/{connection.js → 0_connection.js} +0 -0
  101. /package/esm/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  102. /package/esm/storage/{storage.js → 0_storage.js} +0 -0
  103. /package/esm/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  104. /package/esm/transport/{transport.js → 0_transport.js} +0 -0
  105. /package/esm/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  106. /package/esm/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
  107. /package/{script/client/utilities/0_password_test.d.ts → esm/utilities/0_rle_test.d.ts} +0 -0
  108. /package/script/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  109. /package/script/connection/{connection.js → 0_connection.js} +0 -0
  110. /package/script/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  111. /package/script/storage/{storage.js → 0_storage.js} +0 -0
  112. /package/script/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  113. /package/script/transport/{transport.js → 0_transport.js} +0 -0
  114. /package/script/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  115. /package/script/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
@@ -36,18 +36,19 @@ const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
36
36
  const _5_rpc_result_js_1 = require("../tl/5_rpc_result.js");
37
37
  const _6_message_js_1 = require("../tl/6_message.js"); // MTProto API message
38
38
  const _7_message_container_js_1 = require("../tl/7_message_container.js");
39
- const client_abstract_js_1 = require("./client_abstract.js");
40
- const client_plain_js_1 = require("./client_plain.js");
41
- const storage_memory_js_1 = require("../storage/storage_memory.js");
42
- const _0_html_js_1 = require("../types/utilities/0_html.js");
39
+ const _1_storage_memory_js_1 = require("../storage/1_storage_memory.js");
40
+ const _0_file_id_js_1 = require("../types/!0_file_id.js");
43
41
  const _0_message_entity_js_1 = require("../types/0_message_entity.js");
44
42
  const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
45
43
  const _0_force_reply_js_1 = require("../types/0_force_reply.js");
46
44
  const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
47
45
  const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
48
46
  const _3_message_js_1 = require("../types/3_message.js"); // high-level wrapper for Telegram API's message
49
- const _0_message_js_1 = require("./utilities/0_message.js");
50
- const _0_password_js_1 = require("./utilities/0_password.js");
47
+ const _0_message_js_1 = require("./0_message.js");
48
+ const _0_html_js_1 = require("./0_html.js");
49
+ const _0_password_js_1 = require("./0_password.js");
50
+ const _1_client_abstract_js_1 = require("./1_client_abstract.js");
51
+ const _2_client_plain_js_1 = require("./2_client_plain.js");
51
52
  const d = (0, deps_js_1.debug)("Client");
52
53
  const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
53
54
  const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
@@ -61,7 +62,7 @@ var ParseMode;
61
62
  ParseMode["None"] = "none";
62
63
  ParseMode["HTML"] = "html";
63
64
  })(ParseMode = exports.ParseMode || (exports.ParseMode = {}));
64
- class Client extends client_abstract_js_1.ClientAbstract {
65
+ class Client extends _1_client_abstract_js_1.ClientAbstract {
65
66
  /**
66
67
  * Constructs the client.
67
68
  *
@@ -70,8 +71,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
70
71
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
71
72
  * @param params Other parameters.
72
73
  */
73
- constructor(storage = new storage_memory_js_1.StorageMemory(), apiId = 0, apiHash = "", params) {
74
- super(params?.transportProvider);
74
+ constructor(storage = new _1_storage_memory_js_1.StorageMemory(), apiId = 0, apiHash = "", params, cdn = false) {
75
+ super(params?.transportProvider, cdn);
75
76
  Object.defineProperty(this, "storage", {
76
77
  enumerable: true,
77
78
  configurable: true,
@@ -180,68 +181,13 @@ class Client extends client_abstract_js_1.ClientAbstract {
180
181
  writable: true,
181
182
  value: false
182
183
  });
183
- Object.defineProperty(this, "messageProcessQueue", {
184
+ Object.defineProperty(this, "updateApplicationMutex", {
184
185
  enumerable: true,
185
186
  configurable: true,
186
187
  writable: true,
187
- value: (0, deps_js_1.queue)(async (message) => {
188
- let body = message.body;
189
- if (body instanceof types.GZIPPacked) {
190
- body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
191
- }
192
- dRecv("received %s", body.constructor.name);
193
- if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
194
- await this.processUpdates(body);
195
- }
196
- else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
197
- let result = message.body.result;
198
- if (result instanceof types.GZIPPacked) {
199
- result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
200
- }
201
- if (result instanceof types.RPCError) {
202
- dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
203
- }
204
- else {
205
- dRecv("RPCResult: %s", result.constructor.name);
206
- }
207
- if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
208
- await this.processUpdates(result);
209
- }
210
- else {
211
- await this.processResult(result);
212
- }
213
- const promise = this.promises.get(message.body.messageId);
214
- if (promise) {
215
- if (result instanceof types.RPCError) {
216
- promise.reject(result);
217
- }
218
- else {
219
- promise.resolve(result);
220
- }
221
- this.promises.delete(message.body.messageId);
222
- }
223
- }
224
- else if (message.body instanceof types.Pong) {
225
- const promise = this.promises.get(message.body.msgId);
226
- if (promise) {
227
- promise.resolve(message.body);
228
- this.promises.delete(message.body.msgId);
229
- }
230
- }
231
- else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
232
- if (message.body instanceof types.BadServerSalt) {
233
- this.state.salt = message.body.newServerSalt;
234
- }
235
- const promise = this.promises.get(message.body.badMsgId);
236
- if (promise) {
237
- promise.resolve(message.body);
238
- this.promises.delete(message.body.badMsgId);
239
- }
240
- }
241
- this.toAcknowledge.add(message.id);
242
- }, 2)
188
+ value: new deps_js_1.Mutex()
243
189
  });
244
- Object.defineProperty(this, "updateApplicationMutex", {
190
+ Object.defineProperty(this, "updateProcessLock", {
245
191
  enumerable: true,
246
192
  configurable: true,
247
193
  writable: true,
@@ -296,7 +242,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
296
242
  }
297
243
  const authKey = await this.storage.getAuthKey();
298
244
  if (authKey == null) {
299
- const plain = new client_plain_js_1.ClientPlain(this.transportProvider);
245
+ const plain = new _2_client_plain_js_1.ClientPlain(this.transportProvider);
300
246
  const dc = await this.storage.getDc();
301
247
  if (dc != null) {
302
248
  plain.setDc(dc);
@@ -544,7 +490,64 @@ class Client extends client_abstract_js_1.ClientAbstract {
544
490
  }
545
491
  const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
546
492
  for (const message of messages) {
547
- this.messageProcessQueue.push(message);
493
+ let body = message.body;
494
+ if (body instanceof types.GZIPPacked) {
495
+ body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
496
+ }
497
+ dRecv("received %s", body.constructor.name);
498
+ if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
499
+ this.processUpdates(body);
500
+ }
501
+ else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
502
+ let result = message.body.result;
503
+ if (result instanceof types.GZIPPacked) {
504
+ result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
505
+ }
506
+ if (result instanceof types.RPCError) {
507
+ dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
508
+ }
509
+ else {
510
+ dRecv("RPCResult: %s", result.constructor.name);
511
+ }
512
+ const messageId = message.body.messageId;
513
+ const resolvePromise = () => {
514
+ const promise = this.promises.get(messageId);
515
+ if (promise) {
516
+ if (result instanceof types.RPCError) {
517
+ promise.reject(result);
518
+ }
519
+ else {
520
+ promise.resolve(result);
521
+ }
522
+ this.promises.delete(messageId);
523
+ }
524
+ };
525
+ if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
526
+ this.processUpdates(result).then(resolvePromise);
527
+ }
528
+ else {
529
+ await this.processResult(result);
530
+ resolvePromise();
531
+ }
532
+ }
533
+ else if (message.body instanceof types.Pong) {
534
+ const promise = this.promises.get(message.body.msgId);
535
+ if (promise) {
536
+ promise.resolve(message.body);
537
+ this.promises.delete(message.body.msgId);
538
+ }
539
+ }
540
+ else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
541
+ if (message.body instanceof types.BadServerSalt) {
542
+ this.state.salt = message.body.newServerSalt;
543
+ }
544
+ const promise = this.promises.get(message.body.badMsgId);
545
+ if (promise) {
546
+ promise.resolve(message.body);
547
+ this.promises.delete(message.body.badMsgId);
548
+ }
549
+ }
550
+ this.toAcknowledge.add(message.id);
548
551
  }
549
552
  }
550
553
  }
@@ -637,18 +640,20 @@ class Client extends client_abstract_js_1.ClientAbstract {
637
640
  (update instanceof types.UpdateShortMessage) ||
638
641
  (update instanceof types.UpdateShortChatMessage) ||
639
642
  (update instanceof types.UpdateShortSentMessage)) {
640
- const localState = await this.getLocalState();
641
- if (localState.pts + update.ptsCount > update.pts) {
642
- // the update is already applied
643
- return;
644
- }
645
- else if (localState.pts + update.ptsCount < update.pts) {
646
- // there is an update gap that needs to be filled
647
- throw UPDATE_GAP;
643
+ if (update.pts != 0 && update.ptsCount != 0) {
644
+ const localState = await this.getLocalState();
645
+ if (localState.pts + update.ptsCount > update.pts) {
646
+ // the update is already applied
647
+ return;
648
+ }
649
+ else if (localState.pts + update.ptsCount < update.pts) {
650
+ // there is an update gap that needs to be filled
651
+ throw UPDATE_GAP;
652
+ }
653
+ localState.pts = update.pts;
654
+ d("applied update with pts %d", update.pts);
655
+ await this.storage.setState(localState);
648
656
  }
649
- localState.pts = update.pts;
650
- d("applied update with pts %d", update.pts);
651
- await this.storage.setState(localState);
652
657
  }
653
658
  else if (usePts &&
654
659
  ((update instanceof types.UpdateNewChannelMessage) ||
@@ -748,7 +753,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
748
753
  }
749
754
  }
750
755
  }
751
- async processUpdates(updates) {
756
+ async processUpdates(updates, release) {
757
+ release ??= await this.updateProcessLock.acquire();
752
758
  try {
753
759
  if (updates instanceof types.TypeUpdates) {
754
760
  if (updates instanceof types.Updates) {
@@ -756,7 +762,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
756
762
  await this.processUsers(updates.users);
757
763
  await this.setUpdateStateDate(updates.date);
758
764
  for (const update of updates.updates) {
759
- await this.processUpdates(update);
765
+ await this.processUpdates(update, release);
760
766
  }
761
767
  }
762
768
  else if (updates instanceof types.UpdateShortMessage ||
@@ -773,7 +779,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
773
779
  await this.processChats(updates.chats);
774
780
  await this.processUsers(updates.users);
775
781
  for (const update of updates.updates) {
776
- await this.processUpdates(update);
782
+ await this.processUpdates(update, release);
777
783
  }
778
784
  }
779
785
  }
@@ -802,6 +808,9 @@ class Client extends client_abstract_js_1.ClientAbstract {
802
808
  catch (err) {
803
809
  d("error processing updates: %O", err);
804
810
  }
811
+ finally {
812
+ release();
813
+ }
805
814
  }
806
815
  async setUpdateStateDate(date) {
807
816
  const release = await this.updateApplicationMutex.acquire();
@@ -833,7 +842,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
833
842
  try {
834
843
  let state = await this.getLocalState();
835
844
  while (true) {
836
- const difference = await this.invoke(new functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts }));
845
+ const difference = await this.invoke(new functions.UpdatesGetDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
837
846
  if (difference instanceof types.UpdatesDifference || difference instanceof types.UpdatesDifferenceSlice) {
838
847
  await this.processChats(difference.chats);
839
848
  await this.processUsers(difference.users);
@@ -844,6 +853,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
844
853
  await this.applyUpdateNoGap(update);
845
854
  }
846
855
  if (difference instanceof types.UpdatesDifference) {
856
+ await this.storage.setState(difference.state[_1_tl_object_js_1.as](types.UpdatesState));
847
857
  dGap("recovered from update gap");
848
858
  break;
849
859
  }
@@ -1137,5 +1147,57 @@ class Client extends client_abstract_js_1.ClientAbstract {
1137
1147
  const messages = await this.getMessages(chatId, [messageId]);
1138
1148
  return messages[0] ?? null;
1139
1149
  }
1150
+ async *downloadInner(location, dcId) {
1151
+ let client = null;
1152
+ if (dcId != undefined && dcId != this.dcId) {
1153
+ const exportedAuth = await this.invoke(new functions.AuthExportAuthorization({ dcId }));
1154
+ client = new Client(new _1_storage_memory_js_1.StorageMemory(), this.apiId, this.apiHash, {
1155
+ transportProvider: this.transportProvider,
1156
+ appVersion: this.appVersion,
1157
+ deviceModel: this.deviceModel,
1158
+ langCode: this.langCode,
1159
+ langPack: this.langPack,
1160
+ systemLangCode: this.systemLangCode,
1161
+ systemVersion: this.systemVersion,
1162
+ }, true);
1163
+ let dc = String(dcId);
1164
+ if (this.dcId < 0) {
1165
+ dc += "-test";
1166
+ }
1167
+ await client.setDc(dc);
1168
+ await client.connect();
1169
+ await client.authorize(exportedAuth);
1170
+ }
1171
+ const limit = 1024 * 1024;
1172
+ let offset = 0n;
1173
+ while (true) {
1174
+ const file = await (client ?? this).invoke(new functions.UploadGetFile({ location, offset, limit }));
1175
+ if (file instanceof types.UploadFile) {
1176
+ yield file.bytes;
1177
+ if (file.bytes.length < limit) {
1178
+ break;
1179
+ }
1180
+ else {
1181
+ offset += BigInt(file.bytes.length);
1182
+ }
1183
+ }
1184
+ else {
1185
+ (0, _0_control_js_1.UNREACHABLE)();
1186
+ }
1187
+ }
1188
+ }
1189
+ async download(fileId_) {
1190
+ const fileId = _0_file_id_js_1.FileID.decode(fileId_);
1191
+ switch (fileId.fileType) {
1192
+ case _0_file_id_js_1.FileType.ChatPhoto: {
1193
+ const big = fileId.params.thumbnailSource == _0_file_id_js_1.ThumbnailSource.ChatPhotoBig;
1194
+ const peer = await this.getInputPeer(fileId.params.chatId);
1195
+ const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photoId: fileId.params.mediaId });
1196
+ return this.downloadInner(location);
1197
+ }
1198
+ default:
1199
+ (0, _0_control_js_1.UNREACHABLE)();
1200
+ }
1201
+ }
1140
1202
  }
1141
1203
  exports.Client = Client;
@@ -1,4 +1,4 @@
1
- import { Connection } from "./connection.js";
1
+ import { Connection } from "./0_connection.js";
2
2
  export declare class ConnectionWebSocket implements Connection {
3
3
  private webSocket;
4
4
  private rMutex;
@@ -1,10 +1,10 @@
1
- import { DC } from "./transport/transport_provider.js";
1
+ import { DC } from "./transport/2_transport_provider.js";
2
2
  export declare const ackThreshold = 10;
3
3
  export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.906";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.920";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.906";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.920";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
package/script/deps.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  export * from "./deps/deno.land/std@0.190.0/testing/asserts.js";
2
2
  export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.1.3/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js";
4
- export { Mutex } from "async-mutex";
4
+ export { Mutex, type MutexInterface } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
6
  import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
7
7
  export declare const debug: typeof debug_;
8
- export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
9
8
  export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
package/script/deps.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.base64Encode = exports.base64Decode = exports.queue = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256Encrypt = exports.ctr256Decrypt = void 0;
17
+ exports.base64Encode = exports.base64Decode = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256Encrypt = exports.ctr256Decrypt = void 0;
18
18
  __exportStar(require("./deps/deno.land/std@0.190.0/testing/asserts.js"), exports);
19
19
  var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.1.3/mod.js");
20
20
  Object.defineProperty(exports, "ctr256Decrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Decrypt; } });
@@ -33,8 +33,6 @@ Object.defineProperty(exports, "Parser", { enumerable: true, get: function () {
33
33
  const mod_js_3 = require("./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js");
34
34
  const debug = (v) => (0, mod_js_3.debug)(`mtkruto/${v}`);
35
35
  exports.debug = debug;
36
- var mod_js_4 = require("./deps/deno.land/x/q@v0.0.1/mod.js");
37
- Object.defineProperty(exports, "queue", { enumerable: true, get: function () { return mod_js_4.queue; } });
38
36
  var base64_js_1 = require("./deps/deno.land/std@0.190.0/encoding/base64.js");
39
37
  Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64_js_1.decode; } });
40
38
  Object.defineProperty(exports, "base64Encode", { enumerable: true, get: function () { return base64_js_1.encode; } });
package/script/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getRandomId } from "./utilities/0_bigint.js";
2
- import { checkPassword } from "./client/utilities/0_password.js";
2
+ import { checkPassword } from "./client/0_password.js";
3
3
  export declare const utils: {
4
4
  checkPassword: typeof checkPassword;
5
5
  getRandomId: typeof getRandomId;
@@ -10,16 +10,16 @@ export * as functions from "./tl/3_functions.js";
10
10
  export * from "./tl/5_rpc_result.js";
11
11
  export * from "./tl/6_message.js";
12
12
  export * from "./tl/7_message_container.js";
13
- export * from "./client/client_plain.js";
14
- export * from "./client/client.js";
15
- export * from "./storage/storage.js";
16
- export * from "./storage/storage_memory.js";
17
- export * from "./storage/storage_local_storage.js";
18
- export * from "./storage/storage_session_storage.js";
19
- export * from "./transport/transport_abridged.js";
20
- export * from "./transport/transport_intermediate.js";
21
- export * from "./transport/transport.js";
22
- export * from "./transport/transport_provider.js";
23
- export * from "./connection/connection.js";
24
- export * from "./connection/connection_web_socket.js";
13
+ export * from "./client/2_client_plain.js";
14
+ export * from "./client/3_client.js";
15
+ export * from "./storage/0_storage.js";
16
+ export * from "./storage/1_storage_memory.js";
17
+ export * from "./storage/1_storage_local_storage.js";
18
+ export * from "./storage/1_storage_session_storage.js";
19
+ export * from "./transport/1_transport_abridged.js";
20
+ export * from "./transport/1_transport_intermediate.js";
21
+ export * from "./transport/0_transport.js";
22
+ export * from "./transport/2_transport_provider.js";
23
+ export * from "./connection/0_connection.js";
24
+ export * from "./connection/1_connection_web_socket.js";
25
25
  export { DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "./constants.js";
package/script/mod.js CHANGED
@@ -28,7 +28,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.LAYER = exports.DEFAULT_SYSTEM_VERSION = exports.DEFAULT_SYSTEM_LANG_CODE = exports.DEFAULT_LANG_PACK = exports.DEFAULT_LANG_CODE = exports.DEFAULT_INITIAL_DC = exports.DEFAULT_DEVICE_MODEL = exports.DEFAULT_APP_VERSION = exports.functions = exports.types = exports.as = exports.utils = void 0;
30
30
  const _0_bigint_js_1 = require("./utilities/0_bigint.js");
31
- const _0_password_js_1 = require("./client/utilities/0_password.js");
31
+ const _0_password_js_1 = require("./client/0_password.js");
32
32
  exports.utils = { checkPassword: _0_password_js_1.checkPassword, getRandomId: _0_bigint_js_1.getRandomId };
33
33
  var _1_tl_object_js_1 = require("./tl/1_tl_object.js");
34
34
  Object.defineProperty(exports, "as", { enumerable: true, get: function () { return _1_tl_object_js_1.as; } });
@@ -37,18 +37,18 @@ exports.functions = __importStar(require("./tl/3_functions.js"));
37
37
  __exportStar(require("./tl/5_rpc_result.js"), exports);
38
38
  __exportStar(require("./tl/6_message.js"), exports);
39
39
  __exportStar(require("./tl/7_message_container.js"), exports);
40
- __exportStar(require("./client/client_plain.js"), exports);
41
- __exportStar(require("./client/client.js"), exports);
42
- __exportStar(require("./storage/storage.js"), exports);
43
- __exportStar(require("./storage/storage_memory.js"), exports);
44
- __exportStar(require("./storage/storage_local_storage.js"), exports);
45
- __exportStar(require("./storage/storage_session_storage.js"), exports);
46
- __exportStar(require("./transport/transport_abridged.js"), exports);
47
- __exportStar(require("./transport/transport_intermediate.js"), exports);
48
- __exportStar(require("./transport/transport.js"), exports);
49
- __exportStar(require("./transport/transport_provider.js"), exports);
50
- __exportStar(require("./connection/connection.js"), exports);
51
- __exportStar(require("./connection/connection_web_socket.js"), exports);
40
+ __exportStar(require("./client/2_client_plain.js"), exports);
41
+ __exportStar(require("./client/3_client.js"), exports);
42
+ __exportStar(require("./storage/0_storage.js"), exports);
43
+ __exportStar(require("./storage/1_storage_memory.js"), exports);
44
+ __exportStar(require("./storage/1_storage_local_storage.js"), exports);
45
+ __exportStar(require("./storage/1_storage_session_storage.js"), exports);
46
+ __exportStar(require("./transport/1_transport_abridged.js"), exports);
47
+ __exportStar(require("./transport/1_transport_intermediate.js"), exports);
48
+ __exportStar(require("./transport/0_transport.js"), exports);
49
+ __exportStar(require("./transport/2_transport_provider.js"), exports);
50
+ __exportStar(require("./connection/0_connection.js"), exports);
51
+ __exportStar(require("./connection/1_connection_web_socket.js"), exports);
52
52
  var constants_js_1 = require("./constants.js");
53
53
  Object.defineProperty(exports, "DEFAULT_APP_VERSION", { enumerable: true, get: function () { return constants_js_1.DEFAULT_APP_VERSION; } });
54
54
  Object.defineProperty(exports, "DEFAULT_DEVICE_MODEL", { enumerable: true, get: function () { return constants_js_1.DEFAULT_DEVICE_MODEL; } });
@@ -1,5 +1,5 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { DC } from "../transport/transport_provider.js";
2
+ import { DC } from "../transport/2_transport_provider.js";
3
3
  import * as types from "../tl/2_types.js";
4
4
  export declare abstract class Storage {
5
5
  private _authKeyId;
@@ -1,5 +1,5 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./storage.js";
2
+ import { Storage } from "./0_storage.js";
3
3
  export declare class StorageLocalStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageLocalStorage = void 0;
4
- const storage_js_1 = require("./storage.js");
5
- class StorageLocalStorage extends storage_js_1.Storage {
4
+ const _0_storage_js_1 = require("./0_storage.js");
5
+ class StorageLocalStorage extends _0_storage_js_1.Storage {
6
6
  constructor(prefix) {
7
7
  if (typeof localStorage === "undefined") {
8
8
  throw new Error("Unavailable in current environment");
@@ -1,5 +1,5 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./storage.js";
2
+ import { Storage } from "./0_storage.js";
3
3
  export declare class StorageMemory extends Storage implements Storage {
4
4
  protected map: Map<string, string>;
5
5
  init(): void;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageMemory = void 0;
4
- const storage_js_1 = require("./storage.js");
5
- class StorageMemory extends storage_js_1.Storage {
4
+ const _0_storage_js_1 = require("./0_storage.js");
5
+ class StorageMemory extends _0_storage_js_1.Storage {
6
6
  constructor() {
7
7
  super(...arguments);
8
8
  Object.defineProperty(this, "map", {
@@ -1,5 +1,5 @@
1
1
  import { MaybePromise } from "../utilities/0_types.js";
2
- import { Storage } from "./storage.js";
2
+ import { Storage } from "./0_storage.js";
3
3
  export declare class StorageSessionStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageSessionStorage = void 0;
4
- const storage_js_1 = require("./storage.js");
5
- class StorageSessionStorage extends storage_js_1.Storage {
4
+ const _0_storage_js_1 = require("./0_storage.js");
5
+ class StorageSessionStorage extends _0_storage_js_1.Storage {
6
6
  constructor(prefix) {
7
7
  if (typeof sessionStorage === "undefined") {
8
8
  throw new Error("Unavailable in current environment");
@@ -1,5 +1,5 @@
1
- import { CTR } from "../../utilities/0_crypto.js";
2
- import { Connection } from "../../connection/connection.js";
1
+ import { CTR } from "../utilities/0_crypto.js";
2
+ import { Connection } from "../connection/0_connection.js";
3
3
  export declare function getObfuscationParameters(protocol: number, connection: Connection): Promise<{
4
4
  encryptionCTR: CTR;
5
5
  decryptionCTR: CTR;
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getObfuscationParameters = void 0;
27
- const dntShim = __importStar(require("../../_dnt.shims.js"));
28
- const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
29
- const _0_crypto_js_1 = require("../../utilities/0_crypto.js");
27
+ const dntShim = __importStar(require("../_dnt.shims.js"));
28
+ const _0_buffer_js_1 = require("../utilities/0_buffer.js");
29
+ const _0_crypto_js_1 = require("../utilities/0_crypto.js");
30
30
  async function getObfuscationParameters(protocol, connection) {
31
31
  const dc = 0xFCFF;
32
32
  let init;
@@ -1,5 +1,5 @@
1
- import { Connection } from "../connection/connection.js";
2
- import { Transport } from "./transport.js";
1
+ import { Connection } from "../connection/0_connection.js";
2
+ import { Transport } from "./0_transport.js";
3
3
  export declare class TransportAbridged extends Transport implements Transport {
4
4
  private readonly connection;
5
5
  private readonly obfuscated;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransportAbridged = void 0;
4
4
  const _0_buffer_js_1 = require("../utilities/0_buffer.js");
5
- const _0_obfuscation_js_1 = require("./utilities/0_obfuscation.js");
6
- const transport_js_1 = require("./transport.js");
7
- class TransportAbridged extends transport_js_1.Transport {
5
+ const _0_obfuscation_js_1 = require("./0_obfuscation.js");
6
+ const _0_transport_js_1 = require("./0_transport.js");
7
+ class TransportAbridged extends _0_transport_js_1.Transport {
8
8
  constructor(connection, obfuscated = false) {
9
9
  super();
10
10
  Object.defineProperty(this, "connection", {
@@ -1,5 +1,5 @@
1
- import { Connection } from "../connection/connection.js";
2
- import { Transport } from "./transport.js";
1
+ import { Connection } from "../connection/0_connection.js";
2
+ import { Transport } from "./0_transport.js";
3
3
  export declare class TransportIntermediate extends Transport implements Transport {
4
4
  private readonly connection;
5
5
  private readonly obfuscated;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransportIntermediate = void 0;
4
4
  const _0_buffer_js_1 = require("../utilities/0_buffer.js");
5
- const _0_obfuscation_js_1 = require("./utilities/0_obfuscation.js");
6
- const transport_js_1 = require("./transport.js");
7
- class TransportIntermediate extends transport_js_1.Transport {
5
+ const _0_obfuscation_js_1 = require("./0_obfuscation.js");
6
+ const _0_transport_js_1 = require("./0_transport.js");
7
+ class TransportIntermediate extends _0_transport_js_1.Transport {
8
8
  constructor(connection, obfuscated = false) {
9
9
  super();
10
10
  Object.defineProperty(this, "connection", {
@@ -1,5 +1,5 @@
1
- import { Connection } from "../connection/connection.js";
2
- import { Transport } from "./transport.js";
1
+ import { Connection } from "../connection/0_connection.js";
2
+ import { Transport } from "./0_transport.js";
3
3
  export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
4
4
  export interface TransportProviderParams {
5
5
  dc?: DC;