@mtkruto/node 0.152.0 → 0.154.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/esm/4_constants.d.ts +1 -0
  2. package/esm/4_constants.d.ts.map +1 -1
  3. package/esm/4_constants.js +1 -0
  4. package/esm/client/0_client_abstract.d.ts +1 -1
  5. package/esm/client/0_client_abstract.d.ts.map +1 -1
  6. package/esm/client/0_client_abstract.js +2 -2
  7. package/esm/client/0_password.js +1 -1
  8. package/esm/client/0_utilities.d.ts +1 -1
  9. package/esm/client/0_utilities.d.ts.map +1 -1
  10. package/esm/client/0_utilities.js +4 -4
  11. package/esm/client/1_client_plain.d.ts +1 -1
  12. package/esm/client/1_client_plain.d.ts.map +1 -1
  13. package/esm/client/1_client_plain.js +27 -15
  14. package/esm/client/2_client_encrypted.d.ts +6 -3
  15. package/esm/client/2_client_encrypted.d.ts.map +1 -1
  16. package/esm/client/2_client_encrypted.js +157 -50
  17. package/esm/client/2_file_manager.js +7 -7
  18. package/esm/client/2_network_statistics_manager.d.ts +2 -2
  19. package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
  20. package/esm/client/2_network_statistics_manager.js +13 -12
  21. package/esm/client/2_update_manager.d.ts.map +1 -1
  22. package/esm/client/2_update_manager.js +6 -1
  23. package/esm/client/6_client.d.ts +2 -0
  24. package/esm/client/6_client.d.ts.map +1 -1
  25. package/esm/client/6_client.js +14 -11
  26. package/esm/client/6_client_dispatcher.js +2 -2
  27. package/esm/connection/0_get_tls_header.js +5 -5
  28. package/esm/connection/1_connection_socks5.node.js +3 -3
  29. package/esm/connection/1_connection_tcp.node.js +3 -3
  30. package/esm/connection/1_connection_tls.node.js +3 -3
  31. package/esm/connection/1_connection_web_socket.js +4 -4
  32. package/esm/session/0_session_state.d.ts +1 -0
  33. package/esm/session/0_session_state.d.ts.map +1 -1
  34. package/esm/session/0_session_state.js +8 -4
  35. package/esm/session/1_session.d.ts +4 -3
  36. package/esm/session/1_session.d.ts.map +1 -1
  37. package/esm/session/1_session.js +8 -5
  38. package/esm/session/2_session_encrypted.d.ts +11 -6
  39. package/esm/session/2_session_encrypted.d.ts.map +1 -1
  40. package/esm/session/2_session_encrypted.js +22 -14
  41. package/esm/session/2_session_plain.js +2 -2
  42. package/esm/tl/1_tl_writer.js +5 -5
  43. package/esm/tl/2_message.js +1 -1
  44. package/esm/transport/1_transport_abridged.js +1 -1
  45. package/esm/transport/1_transport_intermediate.js +1 -1
  46. package/esm/transport/1_transport_provider.d.ts +2 -2
  47. package/esm/transport/1_transport_provider.d.ts.map +1 -1
  48. package/esm/transport/1_transport_provider.js +5 -5
  49. package/esm/transport/2_transport_provider_mtproxy.js +2 -2
  50. package/esm/transport/2_transport_provider_socks5.js +2 -2
  51. package/esm/transport/2_transport_provider_tcp.js +2 -2
  52. package/esm/transport/2_transport_provider_web_socket.js +3 -3
  53. package/esm/types/1_network_statistics.d.ts +1 -1
  54. package/esm/types/1_network_statistics.d.ts.map +1 -1
  55. package/esm/types/_file_id.js +1 -1
  56. package/esm/utilities/0_int.js +1 -1
  57. package/esm/utilities/1_auth.js +4 -4
  58. package/esm/utilities/1_crypto.js +7 -7
  59. package/package.json +1 -1
  60. package/script/4_constants.d.ts +1 -0
  61. package/script/4_constants.d.ts.map +1 -1
  62. package/script/4_constants.js +2 -1
  63. package/script/client/0_client_abstract.d.ts +1 -1
  64. package/script/client/0_client_abstract.d.ts.map +1 -1
  65. package/script/client/0_client_abstract.js +2 -2
  66. package/script/client/0_password.js +1 -1
  67. package/script/client/0_utilities.d.ts +1 -1
  68. package/script/client/0_utilities.d.ts.map +1 -1
  69. package/script/client/0_utilities.js +5 -5
  70. package/script/client/1_client_plain.d.ts +1 -1
  71. package/script/client/1_client_plain.d.ts.map +1 -1
  72. package/script/client/1_client_plain.js +26 -14
  73. package/script/client/2_client_encrypted.d.ts +6 -3
  74. package/script/client/2_client_encrypted.d.ts.map +1 -1
  75. package/script/client/2_client_encrypted.js +157 -50
  76. package/script/client/2_file_manager.js +7 -7
  77. package/script/client/2_network_statistics_manager.d.ts +2 -2
  78. package/script/client/2_network_statistics_manager.d.ts.map +1 -1
  79. package/script/client/2_network_statistics_manager.js +13 -12
  80. package/script/client/2_update_manager.d.ts.map +1 -1
  81. package/script/client/2_update_manager.js +6 -1
  82. package/script/client/6_client.d.ts +2 -0
  83. package/script/client/6_client.d.ts.map +1 -1
  84. package/script/client/6_client.js +14 -11
  85. package/script/client/6_client_dispatcher.js +2 -2
  86. package/script/connection/0_get_tls_header.js +5 -5
  87. package/script/connection/1_connection_socks5.node.js +3 -3
  88. package/script/connection/1_connection_tcp.node.js +3 -3
  89. package/script/connection/1_connection_tls.node.js +3 -3
  90. package/script/connection/1_connection_web_socket.js +4 -4
  91. package/script/session/0_session_state.d.ts +1 -0
  92. package/script/session/0_session_state.d.ts.map +1 -1
  93. package/script/session/0_session_state.js +8 -4
  94. package/script/session/1_session.d.ts +4 -3
  95. package/script/session/1_session.d.ts.map +1 -1
  96. package/script/session/1_session.js +8 -5
  97. package/script/session/2_session_encrypted.d.ts +11 -6
  98. package/script/session/2_session_encrypted.d.ts.map +1 -1
  99. package/script/session/2_session_encrypted.js +22 -14
  100. package/script/session/2_session_plain.js +2 -2
  101. package/script/tl/1_tl_writer.js +5 -5
  102. package/script/tl/2_message.js +1 -1
  103. package/script/transport/1_transport_abridged.js +1 -1
  104. package/script/transport/1_transport_intermediate.js +1 -1
  105. package/script/transport/1_transport_provider.d.ts +2 -2
  106. package/script/transport/1_transport_provider.d.ts.map +1 -1
  107. package/script/transport/1_transport_provider.js +5 -5
  108. package/script/transport/2_transport_provider_mtproxy.js +2 -2
  109. package/script/transport/2_transport_provider_socks5.js +2 -2
  110. package/script/transport/2_transport_provider_tcp.js +2 -2
  111. package/script/transport/2_transport_provider_web_socket.js +3 -3
  112. package/script/types/1_network_statistics.d.ts +1 -1
  113. package/script/types/1_network_statistics.d.ts.map +1 -1
  114. package/script/types/_file_id.js +1 -1
  115. package/script/utilities/0_int.js +1 -1
  116. package/script/utilities/1_auth.js +4 -4
  117. package/script/utilities/1_crypto.js +7 -7
@@ -29,7 +29,7 @@ exports.checkPollOption = checkPollOption;
29
29
  exports.checkArray = checkArray;
30
30
  exports.checkCallbackQueryId = checkCallbackQueryId;
31
31
  exports.checkInlineQueryId = checkInlineQueryId;
32
- exports.isCdnFunction = isCdnFunction;
32
+ exports.isMediaFunction = isMediaFunction;
33
33
  exports.canBeInputUser = canBeInputUser;
34
34
  exports.toInputUser = toInputUser;
35
35
  exports.canBeInputChannel = canBeInputChannel;
@@ -156,7 +156,7 @@ function checkInlineQueryId(id) {
156
156
  throw new _0_errors_js_1.InputError("Invalid inline query ID.");
157
157
  }
158
158
  }
159
- const CDN_FUNCTIONS = [
159
+ const MEDIA_FUNCTIONS = [
160
160
  "upload.saveFilePart",
161
161
  "upload.getFile",
162
162
  "upload.saveBigFilePart",
@@ -166,8 +166,8 @@ const CDN_FUNCTIONS = [
166
166
  "upload.getCdnFileHashes",
167
167
  "upload.getFileHashes",
168
168
  ];
169
- function isCdnFunction(value) {
170
- return _2_tl_js_1.Api.isOneOf(CDN_FUNCTIONS, value);
169
+ function isMediaFunction(value) {
170
+ return _2_tl_js_1.Api.isOneOf(MEDIA_FUNCTIONS, value);
171
171
  }
172
172
  function canBeInputUser(inputPeer) {
173
173
  return _2_tl_js_1.Api.isOneOf(["inputPeerSelf", "inputPeerUser", "inputPeerUserFromMessage"], inputPeer);
@@ -246,7 +246,7 @@ function checkStickerName(firstPart) {
246
246
  if ((0, _0_deps_js_1.startsWith)(firstPart, new Uint8Array([0x1F, 0x8B]))) {
247
247
  return "file.tgs";
248
248
  }
249
- else if (firstPart.length >= 12 && (0, _0_deps_js_1.equals)(firstPart.subarray(8, 12), new Uint8Array([0x57, 0x45, 0x42, 0x50]))) {
249
+ else if (firstPart.byteLength >= 12 && (0, _0_deps_js_1.equals)(firstPart.subarray(8, 12), new Uint8Array([0x57, 0x45, 0x42, 0x50]))) {
250
250
  return "file.webp";
251
251
  }
252
252
  else {
@@ -32,6 +32,6 @@ export declare class ClientPlain extends ClientAbstract implements ClientAbstrac
32
32
  session: SessionPlain;
33
33
  constructor(dc: DC, params?: ClientPlainParams);
34
34
  invoke<T extends Mtproto.AnyObject, R = T["_"] extends keyof Mtproto.Functions ? Mtproto.ReturnType<T> extends never ? Mtproto.ReturnType<Mtproto.Functions[T["_"]]> : never : never>(function_: T): Promise<R>;
35
- createAuthKey(): Promise<[Uint8Array<ArrayBuffer>, bigint]>;
35
+ createAuthKey(isTemporary: boolean): Promise<[Uint8Array<ArrayBuffer>, bigint]>;
36
36
  }
37
37
  //# sourceMappingURL=1_client_plain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"1_client_plain.d.ts","sourceRoot":"","sources":["../../src/client/1_client_plain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,EAAW,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAKxD,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,2KAA2K;IAC3K,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,oJAAoJ;AACpJ,qBAAa,WAAY,SAAQ,cAAe,YAAW,cAAc;;IAEvE,OAAO,EAAE,YAAY,CAAC;gBAEV,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,iBAAiB;IAMxC,MAAM,CAAC,CAAC,SAAS,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,OAAO,CAAC,SAAS,GAAG,OA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,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAM/M,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;CA4ItF"}
@@ -43,9 +43,9 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
43
43
  const body = await this.session.receive();
44
44
  return await _2_tl_js_1.Mtproto.deserializeType(_2_tl_js_1.Mtproto.mustGetReturnType(function_._), body);
45
45
  }
46
- async createAuthKey() {
46
+ async createAuthKey(isTemporary) {
47
47
  const nonce = (0, _1_utilities_js_1.getRandomInt)(16);
48
- LcreateAuthKey.debug("auth key creation started");
48
+ LcreateAuthKey.debug(`${isTemporary ? "temporary " : ""}auth key creation started`);
49
49
  let resPq = null;
50
50
  for (let i = 0; i < 10; i++) {
51
51
  try {
@@ -83,20 +83,32 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
83
83
  if (!publicKeyFingerprint || !publicKey) {
84
84
  throw new Error("No corresponding public key found");
85
85
  }
86
- const dc = (0, _3_transport_js_1.getDcId)(this.dc, this.isCdn);
86
+ const dc = (0, _3_transport_js_1.getDcId)(this.dc, this.isMedia);
87
87
  const pq = resPq.pq;
88
88
  const serverNonce = resPq.server_nonce;
89
89
  const newNonce = (0, _1_utilities_js_1.getRandomInt)(32);
90
- let encryptedData = await (0, _1_utilities_js_1.rsaPad)(_2_tl_js_1.Mtproto.serializeObject({
91
- _: "p_q_inner_data_dc",
92
- pq,
93
- p,
94
- q,
95
- dc,
96
- new_nonce: newNonce,
97
- nonce,
98
- server_nonce: serverNonce,
99
- }), publicKey);
90
+ let encryptedData = await (0, _1_utilities_js_1.rsaPad)(_2_tl_js_1.Mtproto.serializeObject(isTemporary
91
+ ? {
92
+ _: "p_q_inner_data_temp_dc",
93
+ pq,
94
+ p,
95
+ q,
96
+ dc,
97
+ new_nonce: newNonce,
98
+ nonce,
99
+ server_nonce: serverNonce,
100
+ expires_in: _4_constants_js_1.TEMPORARY_AUTH_KEY_TTL,
101
+ }
102
+ : {
103
+ _: "p_q_inner_data_dc",
104
+ pq,
105
+ p,
106
+ q,
107
+ dc,
108
+ new_nonce: newNonce,
109
+ nonce,
110
+ server_nonce: serverNonce,
111
+ }), publicKey);
100
112
  const dhParams = await this.invoke({
101
113
  _: "req_DH_params",
102
114
  nonce,
@@ -127,7 +139,7 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
127
139
  g_b: (0, _1_utilities_js_1.intToBytes)(gB, 256, { byteOrder: "big" }),
128
140
  });
129
141
  let dataWithHash = (0, _0_deps_js_1.concat)([await (0, _1_utilities_js_1.sha1)(data), data]);
130
- while (dataWithHash.length % 16 !== 0) {
142
+ while (dataWithHash.byteLength % 16 !== 0) {
131
143
  dataWithHash = (0, _0_deps_js_1.concat)([dataWithHash, new Uint8Array(1)]);
132
144
  }
133
145
  encryptedData = (0, _0_deps_js_1.ige256Encrypt)(dataWithHash, tmpAesKey, tmpAesIv);
@@ -17,6 +17,7 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
+ import { type MaybePromise } from "../1_utilities.js";
20
21
  import { Api, Mtproto } from "../2_tl.js";
21
22
  import type { DC } from "../3_transport.js";
22
23
  import { SessionEncrypted } from "../4_session.js";
@@ -37,11 +38,13 @@ export interface ClientEncryptedParams extends ClientPlainParams {
37
38
  systemVersion?: string;
38
39
  /** Whether to disable receiving updates. Defaults to `false`. */
39
40
  disableUpdates?: boolean;
41
+ /** Whether perfect forward secrecy should be enabled. Defaults to `false`. */
42
+ isPerfectForwardSecrecyEnabled?: boolean;
40
43
  }
41
44
  export interface ClientEncryptedHandlers {
42
- onNewServerSalt?: (newServerSalt: bigint) => void;
43
- onUpdate?: (update: Api.Updates | Api.Update) => void;
44
- onDeserializationError?: () => void;
45
+ onNewServerSalt?: (newServerSalt: bigint) => MaybePromise<void>;
46
+ onUpdate?: (update: Api.Updates | Api.Update) => MaybePromise<void>;
47
+ onDeserializationError?: () => MaybePromise<void>;
45
48
  }
46
49
  export declare class ClientEncrypted extends ClientAbstract {
47
50
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"2_client_encrypted.d.ts","sourceRoot":"","sources":["../../src/client/2_client_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAK,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAO1E,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,iKAAiK;IACjK,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8GAA8G;IAC9G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mHAAmH;IACnH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8GAA8G;IAC9G,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC;IACtD,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;AAED,qBAAa,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AE,IAAI,CAAC;IAgEb,MAAM,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,SAAS,GAAG,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAwG3T"}
@@ -21,12 +21,12 @@
21
21
  var _a;
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.ClientEncrypted = void 0;
24
- const _0_errors_js_1 = require("../0_errors.js");
24
+ const _0_deps_js_1 = require("../0_deps.js");
25
25
  const _1_utilities_js_1 = require("../1_utilities.js");
26
26
  const _2_tl_js_1 = require("../2_tl.js");
27
- const _3_errors_js_1 = require("../3_errors.js");
28
27
  const _4_constants_js_1 = require("../4_constants.js");
29
28
  const _4_errors_js_1 = require("../4_errors.js");
29
+ const _4_errors_js_2 = require("../4_errors.js");
30
30
  const _4_session_js_1 = require("../4_session.js");
31
31
  const _0_client_abstract_js_1 = require("./0_client_abstract.js");
32
32
  const _0_utilities_js_1 = require("./0_utilities.js");
@@ -38,62 +38,146 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
38
38
  static #AUTH_KEY_CREATION_MAX_TRIES = 10;
39
39
  handlers = {};
40
40
  #L;
41
- #plain;
41
+ #dc;
42
+ #apiId;
43
+ #params;
44
+ #authKey = new Uint8Array();
45
+ #authKeyId = 0n;
46
+ #temporaryAuthKey = new Uint8Array();
47
+ #temporaryAuthKeyExpiresIn = 0;
42
48
  session;
43
49
  #sentRequests = new Map();
44
- #apiId;
45
- #appVersion;
46
- #deviceModel;
47
- #langCode;
48
- #langPack;
49
- #systemLangCode;
50
- #systemVersion;
51
- #disableUpdates;
50
+ #isAuthKeyBound = false;
51
+ #isPerfectForwardSecrecyEnabled = false;
52
52
  constructor(dc, apiId, params) {
53
53
  super();
54
54
  this.#L = (0, _1_utilities_js_1.getLogger)("ClientEncrypted").client(id++);
55
- this.#plain = new _1_client_plain_js_1.ClientPlain(dc, params);
55
+ this.#dc = dc;
56
+ this.#apiId = apiId;
57
+ this.#params = params;
58
+ this.#isPerfectForwardSecrecyEnabled = params?.isPerfectForwardSecrecyEnabled ?? false;
56
59
  this.session = new _4_session_js_1.SessionEncrypted(dc, params);
60
+ this.session.handlers.onTransportError = this.#onTransportError.bind(this);
57
61
  this.session.handlers.onUpdate = this.#onUpdate.bind(this);
58
62
  this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
59
63
  this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
60
64
  this.session.handlers.onRpcError = this.#onRpcError.bind(this);
61
65
  this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
62
66
  this.session.handlers.onPong = this.#onPong.bind(this);
63
- this.#apiId = apiId;
64
- this.#appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
65
- this.#deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
66
- this.#langCode = params?.langCode ?? _4_constants_js_1.LANG_CODE;
67
- this.#langPack = params?.langPack ?? _4_constants_js_1.LANG_PACK;
68
- this.#systemLangCode = params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE;
69
- this.#systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
70
- this.#disableUpdates = params?.disableUpdates ?? false;
67
+ }
68
+ async #encryptMessage(message) {
69
+ const payloadWriter = new _2_tl_js_1.TLWriter();
70
+ payloadWriter.writeInt64((0, _1_utilities_js_1.getRandomId)());
71
+ payloadWriter.writeInt64((0, _1_utilities_js_1.getRandomId)());
72
+ payloadWriter.write(await (0, _2_tl_js_1.serializeMessage)(message));
73
+ let payload = payloadWriter.buffer;
74
+ const payloadSha1 = await (0, _1_utilities_js_1.sha1)(payload);
75
+ const messageKey = payloadSha1.subarray(4, 20);
76
+ payloadWriter.write(new Uint8Array((0, _1_utilities_js_1.mod)(-payload.length, 16)));
77
+ payload = payloadWriter.buffer;
78
+ const sha1A = await (0, _1_utilities_js_1.sha1)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.subarray(0, 32)]));
79
+ const sha1B = await (0, _1_utilities_js_1.sha1)((0, _0_deps_js_1.concat)([this.#authKey.slice(32, 48), messageKey, this.#authKey.slice(48, 64)]));
80
+ const sha1C = await (0, _1_utilities_js_1.sha1)((0, _0_deps_js_1.concat)([this.#authKey.slice(64, 96), messageKey]));
81
+ const sha1D = await (0, _1_utilities_js_1.sha1)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.slice(96, 128)]));
82
+ const encryptionKey = (0, _0_deps_js_1.concat)([sha1A.slice(0, 8), sha1B.slice(8, 20), sha1C.slice(4, 16)]);
83
+ const encryptionIv = (0, _0_deps_js_1.concat)([sha1A.slice(8, 20), sha1B.slice(0, 8), sha1C.slice(16, 20), sha1D.slice(0, 8)]);
84
+ const encrypted = (0, _0_deps_js_1.ige256Encrypt)(payload, encryptionKey, encryptionIv);
85
+ const messageWriter = new _2_tl_js_1.TLWriter();
86
+ messageWriter.writeInt64(this.#authKeyId);
87
+ messageWriter.write(messageKey);
88
+ messageWriter.write(encrypted);
89
+ return messageWriter.buffer;
71
90
  }
72
91
  async connect() {
73
- if (!this.authKey.length) {
92
+ if (!this.authKey.byteLength) {
74
93
  await this.#createAuthKey();
75
94
  }
95
+ else if (this.#isPerfectForwardSecrecyEnabled) {
96
+ this.#L.debug("creating temporary auth key");
97
+ await this.#createAuthKeyInner(true);
98
+ }
76
99
  await super.connect();
100
+ if (this.#isPerfectForwardSecrecyEnabled) {
101
+ this.#isAuthKeyBound = false;
102
+ await this.#bindTemporaryAuthKey();
103
+ (0, _1_utilities_js_1.drop)(this.#refreshTemporaryAuthKey());
104
+ }
105
+ else {
106
+ this.#isAuthKeyBound = true;
107
+ }
108
+ }
109
+ async #bindTemporaryAuthKey() {
110
+ const nonce = (0, _1_utilities_js_1.getRandomId)();
111
+ const expires_at = (0, _1_utilities_js_1.toUnixTimestamp)(new Date()) + _4_constants_js_1.TEMPORARY_AUTH_KEY_TTL;
112
+ this.#temporaryAuthKeyExpiresIn = (0, _1_utilities_js_1.fromUnixTimestamp)(expires_at).getTime() - Date.now();
113
+ const object = {
114
+ _: "bind_auth_key_inner",
115
+ perm_auth_key_id: this.#authKeyId,
116
+ nonce,
117
+ expires_at,
118
+ temp_auth_key_id: this.session.authKeyId,
119
+ temp_session_id: this.session.id,
120
+ };
121
+ const encrypted_message = await this.#encryptMessage({
122
+ _: "message",
123
+ seqno: 0,
124
+ msg_id: this.session.previewNextMessageId(),
125
+ body: _2_tl_js_1.Mtproto.serializeObject(object),
126
+ });
127
+ await this.invoke({
128
+ _: "auth.bindTempAuthKey",
129
+ perm_auth_key_id: this.#authKeyId,
130
+ nonce,
131
+ encrypted_message,
132
+ expires_at,
133
+ }), this.#isAuthKeyBound = true;
134
+ }
135
+ #temporaryAuthKeyTimeoutController;
136
+ async #refreshTemporaryAuthKey() {
137
+ this.#temporaryAuthKeyTimeoutController?.abort();
138
+ const controller = this.#temporaryAuthKeyTimeoutController = new AbortController();
139
+ await (0, _0_deps_js_1.delay)(Math.max(0, this.#temporaryAuthKeyExpiresIn - 5 * _0_deps_js_1.SECOND), { signal: controller.signal });
140
+ if (this.#temporaryAuthKeyTimeoutController !== controller) {
141
+ return;
142
+ }
143
+ this.#temporaryAuthKeyTimeoutController = undefined;
144
+ this.#L.debug("reconnecting with a new temporary auth key");
145
+ this.disconnect();
146
+ (0, _1_utilities_js_1.drop)(this.connect());
77
147
  }
78
148
  disconnect() {
79
149
  super.disconnect();
150
+ this.#temporaryAuthKeyTimeoutController?.abort();
151
+ this.#temporaryAuthKeyTimeoutController = undefined;
80
152
  this.lastRequest = undefined;
81
153
  }
82
154
  #createAuthKeyPromise;
83
155
  #createAuthKey() {
84
- return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
156
+ return this.#createAuthKeyPromise ??= (this.#isPerfectForwardSecrecyEnabled ? Promise.all([this.#createAuthKeyInner(false), this.#createAuthKeyInner(true)]) : this.#createAuthKeyInner(false)).finally(() => {
85
157
  this.#createAuthKeyPromise = undefined;
86
158
  });
87
159
  }
88
- async #createAuthKeyInner() {
160
+ async #createAuthKeyInner(isTemporary) {
89
161
  let lastErr;
90
162
  let errored = false;
163
+ const plain = new _1_client_plain_js_1.ClientPlain(this.#dc, this.#params);
91
164
  for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
92
165
  try {
93
- await this.#plain.connect();
94
- const [authKey, serverSalt] = await this.#plain.createAuthKey();
95
- await this.setAuthKey(authKey);
96
- this.serverSalt = serverSalt;
166
+ await plain.connect();
167
+ const [authKey, serverSalt] = await plain.createAuthKey(isTemporary);
168
+ if (isTemporary) {
169
+ this.#temporaryAuthKey = authKey;
170
+ await this.session.setAuthKey(this.#temporaryAuthKey);
171
+ this.session.serverSalt = serverSalt;
172
+ this.#isConnectionInited = false;
173
+ }
174
+ else {
175
+ await this.setAuthKey(authKey);
176
+ }
177
+ if (!this.#isPerfectForwardSecrecyEnabled) {
178
+ await this.session.setAuthKey(authKey);
179
+ this.session.serverSalt = serverSalt;
180
+ }
97
181
  errored = false;
98
182
  break;
99
183
  }
@@ -106,7 +190,7 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
106
190
  this.#L.error("failed to create auth key:", err);
107
191
  }
108
192
  finally {
109
- this.#plain.disconnect();
193
+ plain.disconnect();
110
194
  }
111
195
  }
112
196
  if (errored) {
@@ -114,12 +198,19 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
114
198
  }
115
199
  }
116
200
  get authKey() {
117
- return this.session.authKey;
201
+ return this.#isPerfectForwardSecrecyEnabled ? this.#authKey : this.session.authKey;
118
202
  }
119
203
  async setAuthKey(authKey) {
120
- await this.session.setAuthKey(authKey);
204
+ if (this.#isPerfectForwardSecrecyEnabled) {
205
+ const hash = await (0, _1_utilities_js_1.sha1)(authKey);
206
+ this.#authKeyId = (0, _1_utilities_js_1.intFromBytes)(hash.slice(-8));
207
+ this.#authKey = authKey;
208
+ }
209
+ else {
210
+ await this.session.setAuthKey(authKey);
211
+ }
121
212
  }
122
- #connectionInited = false;
213
+ #isConnectionInited = false;
123
214
  lastRequest;
124
215
  async #send(function_) {
125
216
  this.lastRequest = new Date();
@@ -128,27 +219,27 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
128
219
  body = _2_tl_js_1.Mtproto.serializeObject(function_);
129
220
  }
130
221
  else {
131
- if (this.#disableUpdates && !(0, _0_utilities_js_1.isCdnFunction)(function_)) {
222
+ if (this.#isAuthKeyBound && this.#params?.disableUpdates && !(0, _0_utilities_js_1.isMediaFunction)(function_)) {
132
223
  function_ = { _: "invokeWithoutUpdates", query: function_ };
133
224
  }
134
- if (!this.#connectionInited) {
225
+ if (this.#isAuthKeyBound && !this.#isConnectionInited) {
135
226
  if (!this.#apiId) {
136
- throw new _0_errors_js_1.InputError("apiId not set");
227
+ throw new _4_errors_js_1.InputError("apiId not set");
137
228
  }
138
229
  function_ = {
139
230
  _: "initConnection",
140
231
  api_id: this.#apiId,
141
- app_version: this.#appVersion,
142
- device_model: this.#deviceModel,
143
- lang_code: this.#langCode,
144
- lang_pack: this.#langPack,
232
+ app_version: this.#params?.appVersion ?? _4_constants_js_1.APP_VERSION,
233
+ device_model: this.#params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL,
234
+ lang_code: this.#params?.langCode ?? _4_constants_js_1.LANG_CODE,
235
+ lang_pack: this.#params?.langPack ?? _4_constants_js_1.LANG_PACK,
145
236
  query: {
146
237
  _: "invokeWithLayer",
147
238
  layer: _2_tl_js_1.Api.LAYER,
148
239
  query: function_,
149
240
  },
150
- system_lang_code: this.#systemLangCode,
151
- system_version: this.#systemVersion,
241
+ system_lang_code: this.#params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE,
242
+ system_version: this.#params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION,
152
243
  };
153
244
  }
154
245
  body = _2_tl_js_1.Api.serializeObject(function_);
@@ -193,6 +284,17 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
193
284
  this.#sentRequests.set(messageId, sentRequest);
194
285
  return await sentRequest.promiseWithResolvers.promise;
195
286
  }
287
+ async #onTransportError(transportError) {
288
+ this.#L.error("transport error:", transportError);
289
+ if (!this.#isPerfectForwardSecrecyEnabled) {
290
+ return;
291
+ }
292
+ if (transportError.code === -404) {
293
+ this.#L.debug("reconnecting with a new temporary auth key");
294
+ this.disconnect();
295
+ await this.connect();
296
+ }
297
+ }
196
298
  async #onUpdate(body) {
197
299
  let type;
198
300
  try {
@@ -200,18 +302,18 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
200
302
  }
201
303
  catch (err) {
202
304
  this.#L.error("failed to deserialize update:", err);
203
- this.handlers.onDeserializationError?.();
305
+ await this.handlers.onDeserializationError?.();
204
306
  return;
205
307
  }
206
308
  if (_2_tl_js_1.Api.isOfEnum("Update", type) || _2_tl_js_1.Api.isOfEnum("Updates", type)) {
207
- this.handlers.onUpdate?.(type);
309
+ await this.handlers.onUpdate?.(type);
208
310
  }
209
311
  else {
210
312
  this.#L.warning("received unknown type:", (0, _0_utilities_js_1.repr)(type));
211
313
  }
212
314
  }
213
315
  #onNewServerSalt(serverSalt) {
214
- this.handlers.onNewServerSalt?.(serverSalt);
316
+ (0, _1_utilities_js_1.drop)(this.handlers.onNewServerSalt?.(serverSalt));
215
317
  }
216
318
  async #onMessageFailed(msgId, error) {
217
319
  const request = this.#sentRequests.get(msgId);
@@ -226,17 +328,22 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
226
328
  }
227
329
  }
228
330
  async #onRpcError(msgId, error) {
331
+ if (error.error_message === "AUTH_KEY_PERM_EMPTY" || error.error_message === "ENCRYPTED_MESSAGE_INVALID") {
332
+ this.#L.debug("reconnecting with a new temporary auth key because of", error.error_message);
333
+ this.disconnect();
334
+ await this.connect();
335
+ }
229
336
  const request = this.#sentRequests.get(msgId);
230
337
  this.#L.debug("received rpc_error with req_msg_id =", msgId, "for", request === undefined ? "unknown" : "known", "request");
231
338
  if (request) {
232
339
  this.#sentRequests.delete(msgId);
233
- const reason = (0, _4_errors_js_1.constructTelegramError)(error, request.call);
234
- if (reason instanceof _3_errors_js_1.ConnectionNotInited) {
235
- this.#connectionInited = false;
340
+ const reason = (0, _4_errors_js_2.constructTelegramError)(error, request.call);
341
+ if (reason instanceof _4_errors_js_1.ConnectionNotInited) {
342
+ this.#isConnectionInited = false;
236
343
  await this.#resend(request);
237
344
  }
238
345
  else {
239
- request.promiseWithResolvers.reject((0, _4_errors_js_1.constructTelegramError)(error, request.call));
346
+ request.promiseWithResolvers.reject((0, _4_errors_js_2.constructTelegramError)(error, request.call));
240
347
  }
241
348
  }
242
349
  }
@@ -254,15 +361,15 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
254
361
  catch (err) {
255
362
  sentRequest.promiseWithResolvers.reject(err);
256
363
  this.#L.error("failed to deserialize rpc_result body:", err);
257
- this.handlers.onDeserializationError?.();
364
+ await this.handlers.onDeserializationError?.();
258
365
  return;
259
366
  }
260
367
  finally {
261
368
  this.#sentRequests.delete(msgId);
262
369
  }
263
370
  }
264
- if (!this.#connectionInited) {
265
- this.#connectionInited = true;
371
+ if (!this.#isConnectionInited) {
372
+ this.#isConnectionInited = true;
266
373
  }
267
374
  }
268
375
  #onPong(pong) {
@@ -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;AAIH,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"}
@@ -20,6 +20,7 @@
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.NetworkStatisticsManager = void 0;
23
+ const _0_misc_js_1 = require("../utilities/0_misc.js");
23
24
  const _1_logger_js_1 = require("../utilities/1_logger.js");
24
25
  class NetworkStatisticsManager {
25
26
  #c;
@@ -29,34 +30,34 @@ class NetworkStatisticsManager {
29
30
  this.#L = (0, _1_logger_js_1.getLogger)("NetworkStatisticsManager");
30
31
  }
31
32
  async getNetworkStatistics() {
32
- const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
33
+ const [messagesRead, messagesWrite, mediaRead, mediaWrite] = await Promise.all([
33
34
  this.#c.storage.get(["netstat_messages_read"]),
34
35
  this.#c.storage.get(["netstat_messages_write"]),
35
- this.#c.storage.get(["netstat_cdn_read"]),
36
- this.#c.storage.get(["netstat_cdn_write"]),
36
+ this.#c.storage.get(["netstat_media_read"]),
37
+ this.#c.storage.get(["netstat_media_write"]),
37
38
  ]);
38
39
  const messages = {
39
40
  sent: Number(messagesWrite || 0),
40
41
  received: Number(messagesRead || 0),
41
42
  };
42
- const cdn = {
43
- sent: Number(cdnWrite || 0),
44
- received: Number(cdnRead || 0),
43
+ const media = {
44
+ sent: Number(mediaWrite || 0),
45
+ received: Number(mediaRead || 0),
45
46
  };
46
- return { messages, cdn };
47
+ return { messages, media };
47
48
  }
48
49
  #pendingWrites = {};
49
- getTransportReadWriteCallback(isCcdn) {
50
+ getTransportReadWriteCallback(isMedia) {
50
51
  return {
51
52
  read: (count) => {
52
- const key = isCcdn ? "netstat_cdn_read" : "netstat_messages_read";
53
+ const key = isMedia ? "netstat_media_read" : "netstat_messages_read";
53
54
  this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
54
- this.#write();
55
+ (0, _0_misc_js_1.drop)(this.#write());
55
56
  },
56
57
  write: (count) => {
57
- const key = isCcdn ? "netstat_cdn_write" : "netstat_messages_write";
58
+ const key = isMedia ? "netstat_media_write" : "netstat_messages_write";
58
59
  this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
59
- this.#write();
60
+ (0, _0_misc_js_1.drop)(this.#write());
60
61
  },
61
62
  };
62
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"2_update_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_update_manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAiC,KAAK,EAAmB,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEtC,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,MAAM,SAAS,GACjB,GAAG,CAAC,gBAAgB,GACpB,GAAG,CAAC,oBAAoB,GACxB,GAAG,CAAC,sBAAsB,GAC1B,GAAG,CAAC,uBAAuB,GAC3B,GAAG,CAAC,2BAA2B,GAC/B,GAAG,CAAC,oBAAoB,GACxB,GAAG,CAAC,iBAAiB,GACrB,GAAG,CAAC,oBAAoB,GACxB,GAAG,CAAC,iBAAiB,GACrB,GAAG,CAAC,0BAA0B,GAC9B,GAAG,CAAC,aAAa,CAAC;AAEtB,MAAM,MAAM,gBAAgB,GACxB,GAAG,CAAC,uBAAuB,GAC3B,GAAG,CAAC,wBAAwB,GAC5B,GAAG,CAAC,2BAA2B,GAC/B,GAAG,CAAC,oBAAoB,CAAC;AAE7B,MAAM,MAAM,SAAS,GACjB,GAAG,CAAC,yBAAyB,GAC7B,GAAG,CAAC,qBAAqB,GACzB,GAAG,CAAC,gBAAgB,GACpB,GAAG,CA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