@mtkruto/node 0.1.201 → 0.1.301

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 (137) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +2 -1
  3. package/esm/1_utilities.d.ts +1 -1
  4. package/esm/1_utilities.js +1 -1
  5. package/esm/4_errors.js +3 -3
  6. package/esm/client/0_markdown.js +5 -5
  7. package/esm/client/0_utilities.d.ts +7 -0
  8. package/esm/client/0_utilities.js +47 -4
  9. package/esm/client/1_account_manager.js +4 -4
  10. package/esm/client/1_client_encrypted.js +4 -4
  11. package/esm/client/1_client_plain.js +3 -3
  12. package/esm/client/1_file_manager.js +6 -5
  13. package/esm/client/1_reaction_manager.js +2 -2
  14. package/esm/client/1_update_manager.js +9 -8
  15. package/esm/client/2_message_manager.js +47 -24
  16. package/esm/client/3_callback_query_manager.js +2 -0
  17. package/esm/client/3_chat_list_manager.js +13 -12
  18. package/esm/client/3_inline_query_manager.js +4 -2
  19. package/esm/client/3_story_manager.js +7 -5
  20. package/esm/client/4_client.js +16 -15
  21. package/esm/connection/1_connection_web_socket.js +3 -2
  22. package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.d.ts +0 -1
  23. package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +0 -11
  24. package/esm/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +308 -0
  25. package/esm/mod.d.ts +1 -1
  26. package/esm/mod.js +1 -1
  27. package/esm/storage/0_storage.js +6 -5
  28. package/esm/storage/1_utilities.d.ts +0 -1
  29. package/esm/storage/1_utilities.js +2 -3
  30. package/esm/storage/2_storage_local_storage.js +1 -4
  31. package/esm/storage/2_storage_session_storage.js +1 -4
  32. package/esm/tl/3_utilities.js +5 -4
  33. package/esm/transport/2_transport_provider.js +4 -4
  34. package/esm/types/0_message_entity.js +3 -3
  35. package/esm/types/0_message_search_filter.js +2 -2
  36. package/esm/types/0_reaction.js +2 -2
  37. package/esm/types/1_bot_command_scope.js +3 -3
  38. package/esm/types/1_chat_p.js +3 -2
  39. package/esm/types/1_keyboard_button.js +3 -3
  40. package/esm/types/1_message_reaction.js +2 -2
  41. package/esm/types/1_story_privacy.js +3 -3
  42. package/esm/types/2_chat_member.js +6 -5
  43. package/esm/types/2_chosen_inline_result.js +3 -2
  44. package/esm/types/2_inactive_chat.js +3 -2
  45. package/esm/types/2_inline_keyboard_button.js +3 -3
  46. package/esm/types/2_inline_query.js +3 -3
  47. package/esm/types/2_invite_link.js +3 -2
  48. package/esm/types/2_story_content.js +5 -5
  49. package/esm/types/2_story_interactive_area.js +5 -5
  50. package/esm/types/3_chat_member_updated.js +4 -3
  51. package/esm/types/3_reply_markup.js +4 -3
  52. package/esm/types/3_story.js +3 -2
  53. package/esm/types/4_inline_query_result.js +5 -5
  54. package/esm/types/4_message.js +17 -16
  55. package/esm/types/5_callback_query.js +4 -3
  56. package/esm/types/5_chat.js +8 -7
  57. package/esm/types/_file_id.js +9 -8
  58. package/esm/utilities/0_bigint.d.ts +1 -0
  59. package/esm/utilities/0_bigint.js +25 -0
  60. package/esm/utilities/0_logger.d.ts +8 -0
  61. package/esm/utilities/0_logger.js +9 -5
  62. package/esm/utilities/1_math.d.ts +1 -0
  63. package/esm/utilities/1_math.js +51 -0
  64. package/esm/utilities/1_misc.js +2 -2
  65. package/package.json +1 -1
  66. package/script/0_deps.d.ts +1 -1
  67. package/script/0_deps.js +3 -3
  68. package/script/1_utilities.d.ts +1 -1
  69. package/script/1_utilities.js +1 -1
  70. package/script/4_errors.js +3 -3
  71. package/script/client/0_markdown.js +5 -5
  72. package/script/client/0_utilities.d.ts +7 -0
  73. package/script/client/0_utilities.js +54 -4
  74. package/script/client/1_account_manager.js +4 -4
  75. package/script/client/1_client_encrypted.js +2 -2
  76. package/script/client/1_client_plain.js +2 -2
  77. package/script/client/1_file_manager.js +5 -4
  78. package/script/client/1_reaction_manager.js +2 -2
  79. package/script/client/1_update_manager.js +8 -7
  80. package/script/client/2_message_manager.js +51 -28
  81. package/script/client/3_callback_query_manager.js +2 -0
  82. package/script/client/3_chat_list_manager.js +12 -11
  83. package/script/client/3_inline_query_manager.js +4 -2
  84. package/script/client/3_story_manager.js +4 -2
  85. package/script/client/4_client.js +14 -13
  86. package/script/connection/1_connection_web_socket.js +2 -1
  87. package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.d.ts +0 -1
  88. package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +1 -13
  89. package/script/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +310 -0
  90. package/script/mod.d.ts +1 -1
  91. package/script/mod.js +2 -1
  92. package/script/storage/0_storage.js +5 -4
  93. package/script/storage/1_utilities.d.ts +0 -1
  94. package/script/storage/1_utilities.js +3 -4
  95. package/script/storage/2_storage_local_storage.js +0 -3
  96. package/script/storage/2_storage_session_storage.js +0 -3
  97. package/script/tl/3_utilities.js +4 -3
  98. package/script/transport/2_transport_provider.js +4 -4
  99. package/script/types/0_message_entity.js +3 -3
  100. package/script/types/0_message_search_filter.js +2 -2
  101. package/script/types/0_reaction.js +2 -2
  102. package/script/types/1_bot_command_scope.js +3 -3
  103. package/script/types/1_chat_p.js +2 -1
  104. package/script/types/1_keyboard_button.js +3 -3
  105. package/script/types/1_message_reaction.js +2 -2
  106. package/script/types/1_story_privacy.js +3 -3
  107. package/script/types/2_chat_member.js +5 -4
  108. package/script/types/2_chosen_inline_result.js +2 -1
  109. package/script/types/2_inactive_chat.js +2 -1
  110. package/script/types/2_inline_keyboard_button.js +3 -3
  111. package/script/types/2_inline_query.js +3 -3
  112. package/script/types/2_invite_link.js +2 -1
  113. package/script/types/2_story_content.js +5 -5
  114. package/script/types/2_story_interactive_area.js +5 -5
  115. package/script/types/3_chat_member_updated.js +3 -2
  116. package/script/types/3_reply_markup.js +3 -2
  117. package/script/types/3_story.js +2 -1
  118. package/script/types/4_inline_query_result.js +5 -5
  119. package/script/types/4_message.js +16 -15
  120. package/script/types/5_callback_query.js +3 -2
  121. package/script/types/5_chat.js +7 -6
  122. package/script/types/_file_id.js +8 -7
  123. package/script/utilities/0_bigint.d.ts +1 -0
  124. package/script/utilities/0_bigint.js +27 -1
  125. package/script/utilities/0_logger.d.ts +8 -0
  126. package/script/utilities/0_logger.js +11 -6
  127. package/script/utilities/1_math.d.ts +1 -0
  128. package/script/utilities/1_math.js +55 -0
  129. package/script/utilities/1_misc.js +2 -2
  130. package/esm/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -324
  131. package/esm/utilities/0_control.d.ts +0 -1
  132. package/esm/utilities/0_control.js +0 -3
  133. package/script/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -326
  134. package/script/utilities/0_control.d.ts +0 -1
  135. package/script/utilities/0_control.js +0 -7
  136. /package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
  137. /package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
@@ -1,5 +1,6 @@
1
+ import { unreachable } from "../0_deps.js";
1
2
  import { InputError } from "../0_errors.js";
2
- import { base64DecodeUrlSafe, base64EncodeUrlSafe, rleDecode, rleEncode, UNREACHABLE } from "../1_utilities.js";
3
+ import { base64DecodeUrlSafe, base64EncodeUrlSafe, rleDecode, rleEncode } from "../1_utilities.js";
3
4
  import { TLReader, TLWriter } from "../2_tl.js";
4
5
  const NEXT_VERSION = 53;
5
6
  const PERSISTENT_ID_VERSION = 4;
@@ -122,7 +123,7 @@ function serializePhotoSource(photoSource, writer) {
122
123
  writer.writeInt32(photoSource.version);
123
124
  break;
124
125
  default:
125
- UNREACHABLE();
126
+ unreachable();
126
127
  }
127
128
  }
128
129
  function getPhotoSourceCompareType(source) {
@@ -132,7 +133,7 @@ function getPhotoSourceCompareType(source) {
132
133
  case PhotoSourceType.Thumbnail: {
133
134
  const type = source.thumbnailType;
134
135
  if (!(0 <= type && type <= 127)) {
135
- UNREACHABLE();
136
+ unreachable();
136
137
  }
137
138
  if (type == "a".charCodeAt(0)) {
138
139
  return 0;
@@ -158,7 +159,7 @@ function getPhotoSourceCompareType(source) {
158
159
  default:
159
160
  break;
160
161
  }
161
- UNREACHABLE();
162
+ unreachable();
162
163
  }
163
164
  function writePhotoSourceUniqueId(photoSource, writer) {
164
165
  const compareType = getPhotoSourceCompareType(photoSource);
@@ -169,8 +170,8 @@ function writePhotoSourceUniqueId(photoSource, writer) {
169
170
  if (compareType == 2) {
170
171
  writer.write(new Uint8Array([0x02]));
171
172
  }
172
- writer.writeInt64("volumeId" in photoSource ? photoSource.volumeId : "stickerSetId" in photoSource ? photoSource.stickerSetId : UNREACHABLE());
173
- writer.writeInt32("localId" in photoSource ? photoSource.localId : "version" in photoSource ? photoSource.version : UNREACHABLE());
173
+ writer.writeInt64("volumeId" in photoSource ? photoSource.volumeId : "stickerSetId" in photoSource ? photoSource.stickerSetId : unreachable());
174
+ writer.writeInt32("localId" in photoSource ? photoSource.localId : "version" in photoSource ? photoSource.version : unreachable());
174
175
  }
175
176
  function getFileTypeClass(fileType) {
176
177
  switch (fileType) {
@@ -204,7 +205,7 @@ function getFileTypeClass(fileType) {
204
205
  case FileType.None:
205
206
  case FileType.Size:
206
207
  default:
207
- UNREACHABLE();
208
+ unreachable();
208
209
  }
209
210
  }
210
211
  function isWeb(fileType) {
@@ -279,7 +280,7 @@ export function toUniqueFileId(fileId) {
279
280
  switch (fileId.location.source.type) {
280
281
  case PhotoSourceType.Legacy:
281
282
  case PhotoSourceType.StickerSetThumbnail:
282
- UNREACHABLE();
283
+ unreachable();
283
284
  /* falls through */
284
285
  case PhotoSourceType.FullLegacy:
285
286
  case PhotoSourceType.ChatPhotoSmallLegacy:
@@ -5,3 +5,4 @@ export declare function bigIntFromBuffer(buffer: Uint8Array, little?: boolean, s
5
5
  export declare function getRandomBigInt(byteLength: number, little?: boolean, signed?: boolean): bigint;
6
6
  /** Get a random ID. Useful when calling API functions directly. */
7
7
  export declare function getRandomId(): bigint;
8
+ export declare function gcd(a: bigint, b: bigint): bigint;
@@ -41,3 +41,28 @@ export function getRandomBigInt(byteLength, little, signed) {
41
41
  export function getRandomId() {
42
42
  return getRandomBigInt(8, true, true);
43
43
  }
44
+ export function gcd(a, b) {
45
+ if (a == 0n) {
46
+ return b;
47
+ }
48
+ while ((a & 1n) == 0n) {
49
+ a >>= 1n;
50
+ }
51
+ while (true) {
52
+ if (a > b) {
53
+ a = (a - b) >> 1n;
54
+ while ((a & 1n) == 0n) {
55
+ a >>= 1n;
56
+ }
57
+ }
58
+ else if (b > a) {
59
+ b = (b - a) >> 1n;
60
+ while ((b & 1n) == 0n) {
61
+ b >>= 1n;
62
+ }
63
+ }
64
+ else {
65
+ return a;
66
+ }
67
+ }
68
+ }
@@ -1,4 +1,12 @@
1
1
  export declare function setLogVerbosity(verbosity_: number): void;
2
+ export interface LoggingProvider {
3
+ error(...args: any[]): void;
4
+ warn(...args: any[]): void;
5
+ info(...args: any[]): void;
6
+ debug(...args: any[]): void;
7
+ log(...args: any[]): void;
8
+ }
9
+ export declare function setLoggingProvider(provider_: LoggingProvider): void;
2
10
  export declare const ERROR = 1;
3
11
  export declare const WARNING = 2;
4
12
  export declare const INFO = 3;
@@ -4,6 +4,10 @@ let verbosity = Number("LOG_VERBOSITY" in dntShim.dntGlobalThis ? dntShim.dntGlo
4
4
  export function setLogVerbosity(verbosity_) {
5
5
  verbosity = verbosity_;
6
6
  }
7
+ let provider = console;
8
+ export function setLoggingProvider(provider_) {
9
+ provider = provider_;
10
+ }
7
11
  export const ERROR = 1;
8
12
  export const WARNING = 2;
9
13
  export const INFO = 3;
@@ -70,19 +74,19 @@ export function getLogger(scope) {
70
74
  let fn;
71
75
  switch (verbosity_) {
72
76
  case ERROR:
73
- fn = console.error;
77
+ fn = provider.error;
74
78
  break;
75
79
  case WARNING:
76
- fn = console.warn;
80
+ fn = provider.warn;
77
81
  break;
78
82
  case INFO:
79
- fn = console.info;
83
+ fn = provider.info;
80
84
  break;
81
85
  case DEBUG:
82
- fn = console.debug;
86
+ fn = provider.debug;
83
87
  break;
84
88
  default:
85
- fn = console.log;
89
+ fn = provider.log;
86
90
  }
87
91
  fn(`[${verbosity_} ${scope}]`, ...args);
88
92
  },
@@ -0,0 +1 @@
1
+ export declare function factorize(pq: bigint): [bigint, bigint];
@@ -0,0 +1,51 @@
1
+ import { unreachable } from "../0_deps.js";
2
+ import { gcd, getRandomId, mod } from "./0_bigint.js";
3
+ function getRandomNumberInRange(min, max) {
4
+ return Math.floor(Math.random() * (max - min) + min);
5
+ }
6
+ export function factorize(pq) {
7
+ let a;
8
+ let b;
9
+ let p = 0n;
10
+ let q;
11
+ const one = 1n;
12
+ let found = false;
13
+ for (let i = 0, iter = 0; !found && (i < 3 || iter < 1000); i++) {
14
+ const t = BigInt(getRandomNumberInRange(17, 32)) % (pq - 1n);
15
+ a = getRandomId();
16
+ b = a;
17
+ const lim = 1 << (i + 23);
18
+ for (let j = 1; j < lim; j++) {
19
+ iter++;
20
+ a = mod(a * a, pq);
21
+ a += t;
22
+ if (a >= pq) {
23
+ a = a - pq;
24
+ }
25
+ if (a > b) {
26
+ q = a - b;
27
+ }
28
+ else {
29
+ q = b - a;
30
+ }
31
+ p = gcd(q, pq);
32
+ if (p != one) {
33
+ found = true;
34
+ break;
35
+ }
36
+ if ((j & (j - 1)) == 0) {
37
+ b = a;
38
+ }
39
+ }
40
+ }
41
+ if (found) {
42
+ q = pq / p;
43
+ if (p > q) {
44
+ return [q, p];
45
+ }
46
+ else {
47
+ return [p, q];
48
+ }
49
+ }
50
+ unreachable();
51
+ }
@@ -1,11 +1,11 @@
1
- import { UNREACHABLE } from "./0_control.js";
1
+ import { unreachable } from "../0_deps.js";
2
2
  export function drop(promise) {
3
3
  promise.catch(() => { });
4
4
  }
5
5
  export function mustPrompt(message) {
6
6
  const result = prompt(message);
7
7
  if (result == null) {
8
- throw UNREACHABLE();
8
+ throw unreachable();
9
9
  }
10
10
  else {
11
11
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.201",
3
+ "version": "0.1.301",
4
4
  "description": "MTKruto for Node.js",
5
5
  "author": "Roj <rojvv@icloud.com>",
6
6
  "repository": {
@@ -4,6 +4,6 @@ export { decodeBase64, encodeBase64 } from "./deps/deno.land/std@0.221.0/encodin
4
4
  import { contentType as contentType_ } from "./deps/deno.land/std@0.221.0/media_types/content_type.js";
5
5
  export declare const contentType: typeof contentType_;
6
6
  export declare function extension(mimeType: string): string;
7
- export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.3/mod.js";
7
+ export { ctr256, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.4.0/mod.js";
8
8
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/mod.js";
9
9
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
package/script/0_deps.js CHANGED
@@ -26,7 +26,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Parser = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256 = exports.extension = exports.contentType = exports.encodeBase64 = exports.decodeBase64 = exports.path = void 0;
29
+ exports.Parser = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.ctr256 = exports.extension = exports.contentType = exports.encodeBase64 = exports.decodeBase64 = exports.path = void 0;
30
+ // connection/1_connection_tcp.ts must be updated too when updating std.
30
31
  __exportStar(require("./deps/deno.land/std@0.221.0/assert/mod.js"), exports);
31
32
  exports.path = __importStar(require("./deps/deno.land/std@0.221.0/path/mod.js"));
32
33
  var base64_js_1 = require("./deps/deno.land/std@0.221.0/encoding/base64.js");
@@ -52,9 +53,8 @@ function extension(mimeType) {
52
53
  }
53
54
  }
54
55
  exports.extension = extension;
55
- var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.3.3/mod.js");
56
+ var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.4.0/mod.js");
56
57
  Object.defineProperty(exports, "ctr256", { enumerable: true, get: function () { return mod_js_1.ctr256; } });
57
- Object.defineProperty(exports, "factorize", { enumerable: true, get: function () { return mod_js_1.factorize; } });
58
58
  Object.defineProperty(exports, "ige256Decrypt", { enumerable: true, get: function () { return mod_js_1.ige256Decrypt; } });
59
59
  Object.defineProperty(exports, "ige256Encrypt", { enumerable: true, get: function () { return mod_js_1.ige256Encrypt; } });
60
60
  Object.defineProperty(exports, "initTgCrypto", { enumerable: true, get: function () { return mod_js_1.init; } });
@@ -2,7 +2,6 @@ export * from "./utilities/0_bigint.js";
2
2
  export * from "./utilities/0_buffer.js";
3
3
  export * from "./utilities/0_cache_map.js";
4
4
  export * from "./utilities/0_color.js";
5
- export * from "./utilities/0_control.js";
6
5
  export * from "./utilities/0_crypto.js";
7
6
  export * from "./utilities/0_hash.js";
8
7
  export * from "./utilities/0_logger.js";
@@ -12,5 +11,6 @@ export * from "./utilities/0_rle.js";
12
11
  export * from "./utilities/0_types.js";
13
12
  export * from "./utilities/1_auth.js";
14
13
  export * from "./utilities/1_base64.js";
14
+ export * from "./utilities/1_math.js";
15
15
  export * from "./utilities/1_misc.js";
16
16
  export * from "./utilities/1_queue.js";
@@ -18,7 +18,6 @@ __exportStar(require("./utilities/0_bigint.js"), exports);
18
18
  __exportStar(require("./utilities/0_buffer.js"), exports);
19
19
  __exportStar(require("./utilities/0_cache_map.js"), exports);
20
20
  __exportStar(require("./utilities/0_color.js"), exports);
21
- __exportStar(require("./utilities/0_control.js"), exports);
22
21
  __exportStar(require("./utilities/0_crypto.js"), exports);
23
22
  __exportStar(require("./utilities/0_hash.js"), exports);
24
23
  __exportStar(require("./utilities/0_logger.js"), exports);
@@ -28,5 +27,6 @@ __exportStar(require("./utilities/0_rle.js"), exports);
28
27
  __exportStar(require("./utilities/0_types.js"), exports);
29
28
  __exportStar(require("./utilities/1_auth.js"), exports);
30
29
  __exportStar(require("./utilities/1_base64.js"), exports);
30
+ __exportStar(require("./utilities/1_math.js"), exports);
31
31
  __exportStar(require("./utilities/1_misc.js"), exports);
32
32
  __exportStar(require("./utilities/1_queue.js"), exports);
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.upgradeInstance = exports.StatsMigrate = exports.FileMigrate = exports.PhoneMigrate = exports.UserMigrate = exports.Migrate = exports.FloodWait = void 0;
18
- const _1_utilities_js_1 = require("./1_utilities.js");
18
+ const _0_deps_js_1 = require("./0_deps.js");
19
19
  const _3_errors_js_1 = require("./3_errors.js");
20
20
  __exportStar(require("./3_errors.js"), exports);
21
21
  class FloodWait extends _3_errors_js_1.ErrorWithCall {
@@ -30,7 +30,7 @@ class FloodWait extends _3_errors_js_1.ErrorWithCall {
30
30
  const p = params.error_message.split("_");
31
31
  this.seconds = Number(p[p.length - 1]);
32
32
  if (isNaN(this.seconds)) {
33
- (0, _1_utilities_js_1.UNREACHABLE)();
33
+ (0, _0_deps_js_1.unreachable)();
34
34
  }
35
35
  }
36
36
  }
@@ -47,7 +47,7 @@ class Migrate extends _3_errors_js_1.ErrorWithCall {
47
47
  const p = params.error_message.split("_");
48
48
  this.dc = Number(p[p.length - 1]);
49
49
  if (isNaN(this.dc)) {
50
- (0, _1_utilities_js_1.UNREACHABLE)();
50
+ (0, _0_deps_js_1.unreachable)();
51
51
  }
52
52
  }
53
53
  }
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMarkdown = exports.CODEPOINTS = void 0;
4
4
  /**
5
- * Copyright (c) 2023 Dunkan
6
- * Copyright (c) 2024 Roj
5
+ * Copyright (C) 2023 Dunkan
6
+ * Copyright (C) 2024 Roj
7
7
  */
8
- const _1_utilities_js_1 = require("../1_utilities.js");
8
+ const _0_deps_js_1 = require("../0_deps.js");
9
9
  const _3_types_js_1 = require("../3_types.js");
10
10
  const _0_errors_js_1 = require("../0_errors.js");
11
11
  const enc = new TextEncoder();
@@ -139,7 +139,7 @@ function parseMarkdown(text_) {
139
139
  case "customEmoji":
140
140
  return c === exports.CODEPOINTS["]"];
141
141
  default:
142
- (0, _1_utilities_js_1.UNREACHABLE)();
142
+ (0, _0_deps_js_1.unreachable)();
143
143
  }
144
144
  })();
145
145
  }
@@ -292,7 +292,7 @@ function parseMarkdown(text_) {
292
292
  break;
293
293
  }
294
294
  default:
295
- (0, _1_utilities_js_1.UNREACHABLE)();
295
+ (0, _0_deps_js_1.unreachable)();
296
296
  }
297
297
  if (!skipEntity) {
298
298
  const entityOffset = nestedEntities.at(-1).entityOffset;
@@ -4,3 +4,10 @@ export declare function getFileContents(source: FileSource, fileName?: string):
4
4
  export declare function isHttpUrl(string: string): boolean;
5
5
  export declare function getUsername(string: string): string;
6
6
  export declare function getChatListId(chatList: string): 0 | 1;
7
+ export declare function checkMessageId(messageId: number): number;
8
+ export declare function checkStoryId(storyId: number): number;
9
+ export declare function checkPollOption(option: string): void;
10
+ export declare function checkArray<T>(array: T[], check: (value: T) => void): void;
11
+ export declare function checkCallbackQueryId(id: string): void;
12
+ export declare function checkInlineQueryId(id: string): void;
13
+ export declare function isMtprotoFunction(value: unknown): boolean;
@@ -23,11 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getChatListId = exports.getUsername = exports.isHttpUrl = exports.getFileContents = exports.resolve = void 0;
26
+ exports.isMtprotoFunction = exports.checkInlineQueryId = exports.checkCallbackQueryId = exports.checkArray = exports.checkPollOption = exports.checkStoryId = exports.checkMessageId = exports.getChatListId = exports.getUsername = exports.isHttpUrl = exports.getFileContents = exports.resolve = void 0;
27
27
  const dntShim = __importStar(require("../_dnt.shims.js"));
28
28
  const _0_deps_js_1 = require("../0_deps.js");
29
29
  const _0_errors_js_1 = require("../0_errors.js");
30
- const _1_utilities_js_1 = require("../1_utilities.js");
30
+ const _2_tl_js_1 = require("../2_tl.js");
31
31
  const resolve = () => Promise.resolve();
32
32
  exports.resolve = resolve;
33
33
  async function getFileContents(source, fileName = "") {
@@ -55,7 +55,7 @@ async function getFileContents(source, fileName = "") {
55
55
  fileName = _0_deps_js_1.path.basename(path_);
56
56
  }
57
57
  else {
58
- (0, _1_utilities_js_1.UNREACHABLE)();
58
+ (0, _0_deps_js_1.unreachable)();
59
59
  }
60
60
  }
61
61
  const res = await fetch(url);
@@ -153,7 +153,57 @@ function getChatListId(chatList) {
153
153
  case "archived":
154
154
  return 1;
155
155
  default:
156
- (0, _1_utilities_js_1.UNREACHABLE)();
156
+ (0, _0_deps_js_1.unreachable)();
157
157
  }
158
158
  }
159
159
  exports.getChatListId = getChatListId;
160
+ function checkMessageId(messageId) {
161
+ if (typeof messageId !== "number" || isNaN(messageId) || !messageId) {
162
+ throw new _0_errors_js_1.InputError("Invalid message ID");
163
+ }
164
+ return messageId;
165
+ }
166
+ exports.checkMessageId = checkMessageId;
167
+ function checkStoryId(storyId) {
168
+ if (typeof storyId !== "number" || isNaN(storyId) || !storyId) {
169
+ throw new _0_errors_js_1.InputError("Invalid story ID");
170
+ }
171
+ return storyId;
172
+ }
173
+ exports.checkStoryId = checkStoryId;
174
+ function checkPollOption(option) {
175
+ if (!option.trim()) {
176
+ throw new _0_errors_js_1.InputError("Poll option must not be empty.");
177
+ }
178
+ }
179
+ exports.checkPollOption = checkPollOption;
180
+ function checkArray(array, check) {
181
+ for (const item of array) {
182
+ check(item);
183
+ }
184
+ }
185
+ exports.checkArray = checkArray;
186
+ function checkCallbackQueryId(id) {
187
+ if (typeof id !== "string" || !id.trim()) {
188
+ throw new _0_errors_js_1.InputError("Invalid callback query ID.");
189
+ }
190
+ }
191
+ exports.checkCallbackQueryId = checkCallbackQueryId;
192
+ function checkInlineQueryId(id) {
193
+ if (typeof id !== "string" || !id.trim()) {
194
+ throw new _0_errors_js_1.InputError("Invalid inline query ID.");
195
+ }
196
+ }
197
+ exports.checkInlineQueryId = checkInlineQueryId;
198
+ function isMtprotoFunction(value) {
199
+ return value instanceof _2_tl_js_1.functions.ping ||
200
+ value instanceof _2_tl_js_1.functions.ping_delay_disconnect ||
201
+ value instanceof _2_tl_js_1.functions.req_pq_multi ||
202
+ value instanceof _2_tl_js_1.functions.rpc_drop_answer ||
203
+ value instanceof _2_tl_js_1.functions.get_future_salts ||
204
+ value instanceof _2_tl_js_1.functions.destroy_session ||
205
+ value instanceof _2_tl_js_1.functions.destroy_auth_key ||
206
+ value instanceof _2_tl_js_1.functions.req_DH_params ||
207
+ value instanceof _2_tl_js_1.functions.set_client_DH_params;
208
+ }
209
+ exports.isMtprotoFunction = isMtprotoFunction;
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _AccountManager_instances, _AccountManager_c, _AccountManager_toggleUsername;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AccountManager = void 0;
16
- const _1_utilities_js_1 = require("../1_utilities.js");
16
+ const _0_deps_js_1 = require("../0_deps.js");
17
17
  const _2_tl_js_1 = require("../2_tl.js");
18
18
  const _3_types_js_1 = require("../3_types.js");
19
19
  class AccountManager {
@@ -43,7 +43,7 @@ class AccountManager {
43
43
  return await __classPrivateFieldGet(this, _AccountManager_c, "f").api.channels.reorderUsernames({ channel: new _2_tl_js_1.types.InputChannel(peer), order });
44
44
  }
45
45
  else {
46
- (0, _1_utilities_js_1.UNREACHABLE)();
46
+ (0, _0_deps_js_1.unreachable)();
47
47
  }
48
48
  }
49
49
  async hideUsernames(id) {
@@ -53,7 +53,7 @@ class AccountManager {
53
53
  return await __classPrivateFieldGet(this, _AccountManager_c, "f").api.channels.deactivateAllUsernames({ channel: new _2_tl_js_1.types.InputChannel(peer) });
54
54
  }
55
55
  else {
56
- (0, _1_utilities_js_1.UNREACHABLE)();
56
+ (0, _0_deps_js_1.unreachable)();
57
57
  }
58
58
  }
59
59
  async getInactiveChats() {
@@ -75,6 +75,6 @@ _AccountManager_c = new WeakMap(), _AccountManager_instances = new WeakSet(), _A
75
75
  await __classPrivateFieldGet(this, _AccountManager_c, "f").api.channels.toggleUsername({ channel: new _2_tl_js_1.types.InputChannel(peer), username, active });
76
76
  }
77
77
  else {
78
- (0, _1_utilities_js_1.UNREACHABLE)();
78
+ (0, _0_deps_js_1.unreachable)();
79
79
  }
80
80
  };
@@ -122,7 +122,7 @@ _ClientEncrypted_authKey = new WeakMap(), _ClientEncrypted_authKeyId = new WeakM
122
122
  __classPrivateFieldGet(this, _ClientEncrypted_L, "f").outBin(payload);
123
123
  }, _ClientEncrypted_receiveLoop = async function _ClientEncrypted_receiveLoop() {
124
124
  if (!this.transport) {
125
- (0, _1_utilities_js_1.UNREACHABLE)();
125
+ (0, _0_deps_js_1.unreachable)();
126
126
  }
127
127
  while (this.connected) {
128
128
  try {
@@ -238,6 +238,6 @@ _ClientEncrypted_authKey = new WeakMap(), _ClientEncrypted_authKeyId = new WeakM
238
238
  }
239
239
  }
240
240
  else {
241
- (0, _1_utilities_js_1.UNREACHABLE)();
241
+ (0, _0_deps_js_1.unreachable)();
242
242
  }
243
243
  };
@@ -71,11 +71,11 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
71
71
  }
72
72
  }
73
73
  if (!resPq) {
74
- (0, _1_utilities_js_1.UNREACHABLE)();
74
+ (0, _0_deps_js_1.unreachable)();
75
75
  }
76
76
  const pq_ = (0, _1_utilities_js_1.bigIntFromBuffer)(resPq.pq, false, false);
77
77
  LcreateAuthKey.debug(`pq=${pq_}`);
78
- const [p_, q_] = (0, _0_deps_js_1.factorize)(pq_);
78
+ const [p_, q_] = (0, _1_utilities_js_1.factorize)(pq_);
79
79
  LcreateAuthKey.debug("factorized pq");
80
80
  LcreateAuthKey.debug(`p=${p_}, q=${q_}`);
81
81
  const p = (0, _1_utilities_js_1.bufferFromBigInt)(p_, 4, false, false);
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _FileManager_instances, _FileManager_c, _FileManager_Lupload, _FileManager_downloadInner;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.FileManager = void 0;
16
+ const _0_deps_js_1 = require("../0_deps.js");
16
17
  const _0_errors_js_1 = require("../0_errors.js");
17
18
  const _1_utilities_js_1 = require("../1_utilities.js");
18
19
  const _2_tl_js_1 = require("../2_tl.js");
@@ -107,7 +108,7 @@ class FileManager {
107
108
  switch (fileId_.type) {
108
109
  case _3_types_js_1.FileType.ProfilePhoto: {
109
110
  if (fileId_.location.source.type != _3_types_js_1.PhotoSourceType.ChatPhotoBig && fileId_.location.source.type != _3_types_js_1.PhotoSourceType.ChatPhotoSmall) {
110
- (0, _1_utilities_js_1.UNREACHABLE)();
111
+ (0, _0_deps_js_1.unreachable)();
111
112
  }
112
113
  const big = fileId_.location.source.type == _3_types_js_1.PhotoSourceType.ChatPhotoBig;
113
114
  const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(Number(fileId_.location.source.chatId)); // TODO: use access hash from source?
@@ -134,7 +135,7 @@ class FileManager {
134
135
  id: fileId_.location.id,
135
136
  access_hash: fileId_.location.accessHash,
136
137
  file_reference: fileId_.fileReference ?? new Uint8Array(),
137
- thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : (0, _1_utilities_js_1.UNREACHABLE)(),
138
+ thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : (0, _0_deps_js_1.unreachable)(),
138
139
  });
139
140
  for await (const chunk of __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params)) {
140
141
  yield chunk;
@@ -155,7 +156,7 @@ class FileManager {
155
156
  }
156
157
  }
157
158
  else {
158
- (0, _1_utilities_js_1.UNREACHABLE)();
159
+ (0, _0_deps_js_1.unreachable)();
159
160
  }
160
161
  }
161
162
  async getStickerSetName(inputStickerSet, hash = 0) {
@@ -259,7 +260,7 @@ _FileManager_c = new WeakMap(), _FileManager_Lupload = new WeakMap(), _FileManag
259
260
  }
260
261
  }
261
262
  else {
262
- (0, _1_utilities_js_1.UNREACHABLE)();
263
+ (0, _0_deps_js_1.unreachable)();
263
264
  }
264
265
  }
265
266
  }
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _ReactionManager_c;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ReactionManager = void 0;
16
- const _1_utilities_js_1 = require("../1_utilities.js");
16
+ const _0_deps_js_1 = require("../0_deps.js");
17
17
  const _2_tl_js_1 = require("../2_tl.js");
18
18
  const _3_types_js_1 = require("../3_types.js");
19
19
  class ReactionManager {
@@ -80,7 +80,7 @@ class ReactionManager {
80
80
  }
81
81
  }
82
82
  else {
83
- (0, _1_utilities_js_1.UNREACHABLE)();
83
+ (0, _0_deps_js_1.unreachable)();
84
84
  }
85
85
  }
86
86
  }
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _UpdateManager_instances, _a, _UpdateManager_c, _UpdateManager_updateState, _UpdateManager_updateHandler, _UpdateManager_LrecoverUpdateGap, _UpdateManager_LrecoverChannelUpdateGap, _UpdateManager_L$handleUpdate, _UpdateManager_L$processUpdates, _UpdateManager_LfetchState, _UpdateManager_defaultDropPendingUpdates, _UpdateManager_mustDropPendingUpdates, _UpdateManager_state, _UpdateManager_getState, _UpdateManager_setState, _UpdateManager_handleUpdateQueues, _UpdateManager_nonFirst, _UpdateManager_getChannelPtsWithDropPendingUpdatesCheck, _UpdateManager_checkGap, _UpdateManager_checkGapQts, _UpdateManager_checkChannelGap, _UpdateManager_channelUpdateQueues, _UpdateManager_processChannelPtsUpdateInner, _UpdateManager_queueUpdate, _UpdateManager_processChannelPtsUpdate, _UpdateManager_processPtsUpdateInner, _UpdateManager_ptsUpdateQueue, _UpdateManager_processPtsUpdate, _UpdateManager_processQtsUpdateInner, _UpdateManager_qtsUpdateQueue, _UpdateManager_processQtsUpdate, _UpdateManager_processUpdatesQueue, _UpdateManager_processUpdates, _UpdateManager_setUpdateStateDate, _UpdateManager_setUpdatePts, _UpdateManager_setUpdateQts, _UpdateManager_getLocalState, _UpdateManager_recoverChannelUpdateGap, _UpdateManager_handleUpdatesSet, _UpdateManager_handleStoredUpdates, _UpdateManager_handleUpdate;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.UpdateManager = void 0;
16
+ const _0_deps_js_1 = require("../0_deps.js");
16
17
  const _1_utilities_js_1 = require("../1_utilities.js");
17
18
  const _2_tl_js_1 = require("../2_tl.js");
18
19
  const _4_constants_js_1 = require("../4_constants.js");
@@ -253,7 +254,7 @@ class UpdateManager {
253
254
  state = difference.intermediate_state;
254
255
  }
255
256
  else {
256
- (0, _1_utilities_js_1.UNREACHABLE)();
257
+ (0, _0_deps_js_1.unreachable)();
257
258
  }
258
259
  }
259
260
  else if (difference instanceof _2_tl_js_1.types.updates.DifferenceTooLong) {
@@ -269,7 +270,7 @@ class UpdateManager {
269
270
  break;
270
271
  }
271
272
  else {
272
- (0, _1_utilities_js_1.UNREACHABLE)();
273
+ (0, _0_deps_js_1.unreachable)();
273
274
  }
274
275
  }
275
276
  }
@@ -515,7 +516,7 @@ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState
515
516
  }
516
517
  else if (updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
517
518
  if (!(call instanceof _2_tl_js_1.functions.messages.sendMessage)) {
518
- (0, _1_utilities_js_1.UNREACHABLE)();
519
+ (0, _0_deps_js_1.unreachable)();
519
520
  }
520
521
  updates = [
521
522
  new _2_tl_js_1.types.UpdateNewMessage({
@@ -545,7 +546,7 @@ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState
545
546
  updates = [updates_];
546
547
  }
547
548
  else {
548
- (0, _1_utilities_js_1.UNREACHABLE)();
549
+ (0, _0_deps_js_1.unreachable)();
549
550
  }
550
551
  /// We process the updates when we are sure there is no gap.
551
552
  if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
@@ -566,7 +567,7 @@ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState
566
567
  await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, __classPrivateFieldGet(this, _UpdateManager_updateState, "f"));
567
568
  }
568
569
  else {
569
- (0, _1_utilities_js_1.UNREACHABLE)();
570
+ (0, _0_deps_js_1.unreachable)();
570
571
  }
571
572
  }
572
573
  else if (_a.isPtsUpdate(update)) {
@@ -608,7 +609,7 @@ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState
608
609
  await __classPrivateFieldGet(this, _UpdateManager_instances, "m", _UpdateManager_setState).call(this, localState);
609
610
  }
610
611
  else {
611
- (0, _1_utilities_js_1.UNREACHABLE)();
612
+ (0, _0_deps_js_1.unreachable)();
612
613
  }
613
614
  }
614
615
  }
@@ -651,7 +652,7 @@ _a = UpdateManager, _UpdateManager_c = new WeakMap(), _UpdateManager_updateState
651
652
  pts = pts_;
652
653
  }
653
654
  else {
654
- (0, _1_utilities_js_1.UNREACHABLE)();
655
+ (0, _0_deps_js_1.unreachable)();
655
656
  }
656
657
  __classPrivateFieldGet(this, _UpdateManager_LrecoverChannelUpdateGap, "f").debug("processed channelDifferenceTooLong");
657
658
  }