@mtkruto/node 0.153.0 → 0.160.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.
- package/esm/3_types.d.ts +3 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +3 -0
- package/esm/4_constants.d.ts +1 -0
- package/esm/4_constants.d.ts.map +1 -1
- package/esm/4_constants.js +1 -0
- package/esm/client/0_markdown.js +4 -4
- package/esm/client/0_params.d.ts +11 -1
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/1_client_generic.d.ts +100 -3
- package/esm/client/1_client_generic.d.ts.map +1 -1
- package/esm/client/1_client_plain.d.ts +1 -1
- package/esm/client/1_client_plain.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +25 -13
- package/esm/client/2_client_encrypted.d.ts +6 -3
- package/esm/client/2_client_encrypted.d.ts.map +1 -1
- package/esm/client/2_client_encrypted.js +166 -49
- package/esm/client/2_file_manager.js +1 -1
- package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +3 -2
- package/esm/client/2_payment_manager.js +2 -2
- package/esm/client/2_takeout_manager.js +2 -2
- package/esm/client/2_update_manager.d.ts.map +1 -1
- package/esm/client/2_update_manager.js +16 -11
- package/esm/client/3_account_manager.js +3 -3
- package/esm/client/3_message_manager.d.ts +11 -0
- package/esm/client/3_message_manager.d.ts.map +1 -1
- package/esm/client/3_message_manager.js +195 -74
- package/esm/client/3_sticker_set_manager.js +3 -3
- package/esm/client/3_video_chat_manager.js +1 -1
- package/esm/client/4_callback_query_manager.js +2 -2
- package/esm/client/4_chat_list_manager.js +3 -3
- package/esm/client/4_chat_manager.d.ts +3 -2
- package/esm/client/4_chat_manager.d.ts.map +1 -1
- package/esm/client/4_chat_manager.js +12 -5
- package/esm/client/4_contact_manager.js +1 -1
- package/esm/client/4_gift_manager.js +11 -11
- package/esm/client/4_inline_query_manager.js +1 -1
- package/esm/client/4_story_manager.d.ts +3 -1
- package/esm/client/4_story_manager.d.ts.map +1 -1
- package/esm/client/4_story_manager.js +17 -3
- package/esm/client/6_client.d.ts +102 -3
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +130 -2
- package/esm/client/6_client_dispatcher.d.ts +100 -3
- package/esm/client/6_client_dispatcher.d.ts.map +1 -1
- package/esm/client/6_client_dispatcher.js +126 -1
- package/esm/connection/0_get_tls_header.d.ts.map +1 -1
- package/esm/connection/0_get_tls_header.js +19 -0
- package/esm/connection/1_connection_web_socket.js +2 -2
- package/esm/session/0_session_state.d.ts +1 -0
- package/esm/session/0_session_state.d.ts.map +1 -1
- package/esm/session/0_session_state.js +8 -4
- package/esm/session/1_session.d.ts +1 -0
- package/esm/session/1_session.d.ts.map +1 -1
- package/esm/session/1_session.js +3 -0
- package/esm/session/2_session_encrypted.d.ts +11 -6
- package/esm/session/2_session_encrypted.d.ts.map +1 -1
- package/esm/session/2_session_encrypted.js +20 -12
- package/esm/storage/1_utilities.js +2 -2
- package/esm/transport/2_transport_provider_web_socket.js +1 -1
- package/esm/types/0_button_style.js +1 -1
- package/esm/types/0_chat_member_rights.js +34 -34
- package/esm/types/0_chat_photo.js +2 -2
- package/esm/types/0_dice.d.ts +1 -1
- package/esm/types/0_dice.d.ts.map +1 -1
- package/esm/types/0_giveaway_parameters.js +1 -1
- package/esm/types/0_live_stream_channel.d.ts +1 -1
- package/esm/types/0_live_stream_channel.d.ts.map +1 -1
- package/esm/types/0_report_reason.d.ts +53 -0
- package/esm/types/0_report_reason.d.ts.map +1 -0
- package/esm/types/0_report_reason.js +45 -0
- package/esm/types/0_story_report_option.d.ts +26 -0
- package/esm/types/0_story_report_option.d.ts.map +1 -0
- package/esm/types/0_story_report_option.js +25 -0
- package/esm/types/0_video_chat.js +2 -2
- package/esm/types/1_inline_keyboard_button.d.ts +2 -2
- package/esm/types/1_message_reaction.js +1 -1
- package/esm/types/1_sticker.js +1 -1
- package/esm/types/1_story_reaction.js +1 -1
- package/esm/types/1_story_report_result.d.ts +37 -0
- package/esm/types/1_story_report_result.d.ts.map +1 -0
- package/esm/types/1_story_report_result.js +36 -0
- package/esm/types/2_chat.js +2 -2
- package/esm/types/2_chat_member.js +3 -3
- package/esm/types/2_message_entity.js +1 -1
- package/esm/types/2_story_interactive_area.js +3 -3
- package/esm/types/3_chat_settings.js +1 -1
- package/esm/types/3_forward_header.js +3 -3
- package/esm/types/3_inline_query.js +1 -1
- package/esm/types/3_invite_link.js +2 -2
- package/esm/types/3_story.js +3 -3
- package/esm/types/4_gift.js +1 -1
- package/esm/types/5_gift_non_upgraded_information.js +8 -8
- package/esm/types/5_gift_upgraded_information.js +5 -5
- package/esm/types/6_poll_media.d.ts +1 -1
- package/esm/types/6_poll_media.d.ts.map +1 -1
- package/esm/types/7_inline_query_result.js +8 -8
- package/esm/types/7_poll_option.d.ts +1 -1
- package/esm/types/7_poll_option.d.ts.map +1 -1
- package/esm/types/8_inline_query_answer.js +1 -1
- package/esm/types/9_message.js +3 -3
- package/esm/utilities/0_env.js +1 -1
- package/package.json +1 -1
- package/script/3_types.d.ts +3 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +3 -0
- package/script/4_constants.d.ts +1 -0
- package/script/4_constants.d.ts.map +1 -1
- package/script/4_constants.js +2 -1
- package/script/client/0_markdown.js +4 -4
- package/script/client/0_params.d.ts +11 -1
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/1_client_generic.d.ts +100 -3
- package/script/client/1_client_generic.d.ts.map +1 -1
- package/script/client/1_client_plain.d.ts +1 -1
- package/script/client/1_client_plain.d.ts.map +1 -1
- package/script/client/1_client_plain.js +24 -12
- package/script/client/2_client_encrypted.d.ts +6 -3
- package/script/client/2_client_encrypted.d.ts.map +1 -1
- package/script/client/2_client_encrypted.js +166 -49
- package/script/client/2_file_manager.js +1 -1
- package/script/client/2_network_statistics_manager.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +3 -2
- package/script/client/2_payment_manager.js +2 -2
- package/script/client/2_takeout_manager.js +2 -2
- package/script/client/2_update_manager.d.ts.map +1 -1
- package/script/client/2_update_manager.js +16 -11
- package/script/client/3_account_manager.js +3 -3
- package/script/client/3_message_manager.d.ts +11 -0
- package/script/client/3_message_manager.d.ts.map +1 -1
- package/script/client/3_message_manager.js +194 -73
- package/script/client/3_sticker_set_manager.js +3 -3
- package/script/client/3_video_chat_manager.js +1 -1
- package/script/client/4_callback_query_manager.js +2 -2
- package/script/client/4_chat_list_manager.js +3 -3
- package/script/client/4_chat_manager.d.ts +3 -2
- package/script/client/4_chat_manager.d.ts.map +1 -1
- package/script/client/4_chat_manager.js +11 -4
- package/script/client/4_contact_manager.js +1 -1
- package/script/client/4_gift_manager.js +11 -11
- package/script/client/4_inline_query_manager.js +1 -1
- package/script/client/4_story_manager.d.ts +3 -1
- package/script/client/4_story_manager.d.ts.map +1 -1
- package/script/client/4_story_manager.js +15 -1
- package/script/client/6_client.d.ts +102 -3
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +130 -2
- package/script/client/6_client_dispatcher.d.ts +100 -3
- package/script/client/6_client_dispatcher.d.ts.map +1 -1
- package/script/client/6_client_dispatcher.js +126 -1
- package/script/connection/0_get_tls_header.d.ts.map +1 -1
- package/script/connection/0_get_tls_header.js +19 -0
- package/script/connection/1_connection_web_socket.js +2 -2
- package/script/session/0_session_state.d.ts +1 -0
- package/script/session/0_session_state.d.ts.map +1 -1
- package/script/session/0_session_state.js +8 -4
- package/script/session/1_session.d.ts +1 -0
- package/script/session/1_session.d.ts.map +1 -1
- package/script/session/1_session.js +3 -0
- package/script/session/2_session_encrypted.d.ts +11 -6
- package/script/session/2_session_encrypted.d.ts.map +1 -1
- package/script/session/2_session_encrypted.js +20 -12
- package/script/storage/1_utilities.js +2 -2
- package/script/transport/2_transport_provider_web_socket.js +1 -1
- package/script/types/0_button_style.js +1 -1
- package/script/types/0_chat_member_rights.js +34 -34
- package/script/types/0_chat_photo.js +2 -2
- package/script/types/0_dice.d.ts +1 -1
- package/script/types/0_dice.d.ts.map +1 -1
- package/script/types/0_giveaway_parameters.js +1 -1
- package/script/types/0_live_stream_channel.d.ts +1 -1
- package/script/types/0_live_stream_channel.d.ts.map +1 -1
- package/script/types/0_report_reason.d.ts +53 -0
- package/script/types/0_report_reason.d.ts.map +1 -0
- package/script/types/0_report_reason.js +48 -0
- package/script/types/0_story_report_option.d.ts +26 -0
- package/script/types/0_story_report_option.d.ts.map +1 -0
- package/script/types/0_story_report_option.js +28 -0
- package/script/types/0_video_chat.js +2 -2
- package/script/types/1_inline_keyboard_button.d.ts +2 -2
- package/script/types/1_message_reaction.js +1 -1
- package/script/types/1_sticker.js +1 -1
- package/script/types/1_story_reaction.js +1 -1
- package/script/types/1_story_report_result.d.ts +37 -0
- package/script/types/1_story_report_result.d.ts.map +1 -0
- package/script/types/1_story_report_result.js +39 -0
- package/script/types/2_chat.js +2 -2
- package/script/types/2_chat_member.js +3 -3
- package/script/types/2_message_entity.js +1 -1
- package/script/types/2_story_interactive_area.js +3 -3
- package/script/types/3_chat_settings.js +1 -1
- package/script/types/3_forward_header.js +3 -3
- package/script/types/3_inline_query.js +1 -1
- package/script/types/3_invite_link.js +2 -2
- package/script/types/3_story.js +3 -3
- package/script/types/4_gift.js +1 -1
- package/script/types/5_gift_non_upgraded_information.js +8 -8
- package/script/types/5_gift_upgraded_information.js +5 -5
- package/script/types/6_poll_media.d.ts +1 -1
- package/script/types/6_poll_media.d.ts.map +1 -1
- package/script/types/7_inline_query_result.js +8 -8
- package/script/types/7_poll_option.d.ts +1 -1
- package/script/types/7_poll_option.d.ts.map +1 -1
- package/script/types/8_inline_query_answer.js +1 -1
- package/script/types/9_message.js +3 -3
- package/script/utilities/0_env.js +1 -1
|
@@ -21,7 +21,7 @@ import { assert, assertEquals, concat, ige256Decrypt, ige256Encrypt, unreachable
|
|
|
21
21
|
import { factorize, getLogger, getRandomInt, intFromBytes, intToBytes, modExp, rsaPad, sha1 } from "../1_utilities.js";
|
|
22
22
|
import { Mtproto } from "../2_tl.js";
|
|
23
23
|
import { getDcId } from "../3_transport.js";
|
|
24
|
-
import { PUBLIC_KEYS } from "../4_constants.js";
|
|
24
|
+
import { PUBLIC_KEYS, TEMPORARY_AUTH_KEY_TTL } from "../4_constants.js";
|
|
25
25
|
import { SessionPlain } from "../4_session.js";
|
|
26
26
|
import { ClientAbstract } from "./0_client_abstract.js";
|
|
27
27
|
const L = getLogger("ClientPlain");
|
|
@@ -40,9 +40,9 @@ export class ClientPlain extends ClientAbstract {
|
|
|
40
40
|
const body = await this.session.receive();
|
|
41
41
|
return await Mtproto.deserializeType(Mtproto.mustGetReturnType(function_._), body);
|
|
42
42
|
}
|
|
43
|
-
async createAuthKey() {
|
|
43
|
+
async createAuthKey(isTemporary) {
|
|
44
44
|
const nonce = getRandomInt(16);
|
|
45
|
-
LcreateAuthKey.debug("auth key creation started
|
|
45
|
+
LcreateAuthKey.debug(`${isTemporary ? "temporary " : ""}auth key creation started`);
|
|
46
46
|
let resPq = null;
|
|
47
47
|
for (let i = 0; i < 10; i++) {
|
|
48
48
|
try {
|
|
@@ -84,16 +84,28 @@ export class ClientPlain extends ClientAbstract {
|
|
|
84
84
|
const pq = resPq.pq;
|
|
85
85
|
const serverNonce = resPq.server_nonce;
|
|
86
86
|
const newNonce = getRandomInt(32);
|
|
87
|
-
let encryptedData = await rsaPad(Mtproto.serializeObject(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
let encryptedData = await rsaPad(Mtproto.serializeObject(isTemporary
|
|
88
|
+
? {
|
|
89
|
+
_: "p_q_inner_data_temp_dc",
|
|
90
|
+
pq,
|
|
91
|
+
p,
|
|
92
|
+
q,
|
|
93
|
+
dc,
|
|
94
|
+
new_nonce: newNonce,
|
|
95
|
+
nonce,
|
|
96
|
+
server_nonce: serverNonce,
|
|
97
|
+
expires_in: TEMPORARY_AUTH_KEY_TTL,
|
|
98
|
+
}
|
|
99
|
+
: {
|
|
100
|
+
_: "p_q_inner_data_dc",
|
|
101
|
+
pq,
|
|
102
|
+
p,
|
|
103
|
+
q,
|
|
104
|
+
dc,
|
|
105
|
+
new_nonce: newNonce,
|
|
106
|
+
nonce,
|
|
107
|
+
server_nonce: serverNonce,
|
|
108
|
+
}), publicKey);
|
|
97
109
|
const dhParams = await this.invoke({
|
|
98
110
|
_: "req_DH_params",
|
|
99
111
|
nonce,
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"2_client_encrypted.d.ts","sourceRoot":"","sources":["../../src/client/2_client_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAA8E,KAAK,YAAY,EAA8B,MAAM,mBAAmB,CAAC;AAC9J,OAAO,EAAE,GAAG,EAAgB,OAAO,EAAiC,MAAM,YAAY,CAAC;AACvF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,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;IACzB,8EAA8E;IAC9E,8BAA8B,CAAC,EAAE,OAAO,CAAC;CAC1C;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IAChE,QAAQ,CAAC,EAAE,CAAC,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|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "../4_constants.js";
|
|
21
|
+
import { concat, delay, ige256Encrypt, SECOND } from "../0_deps.js";
|
|
22
|
+
import { ConnectionError } from "../0_errors.js";
|
|
23
|
+
import { drop, fromUnixTimestamp, getLogger, getRandomId, intFromBytes, mod, sha1, toUnixTimestamp } from "../1_utilities.js";
|
|
24
|
+
import { Api, Mtproto, serializeMessage, TLWriter, X } from "../2_tl.js";
|
|
25
|
+
import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, SYSTEM_LANG_CODE, SYSTEM_VERSION, TEMPORARY_AUTH_KEY_TTL } from "../4_constants.js";
|
|
26
|
+
import { ConnectionNotInited, InputError } from "../4_errors.js";
|
|
26
27
|
import { constructTelegramError } from "../4_errors.js";
|
|
27
28
|
import { SessionEncrypted, SessionError } from "../4_session.js";
|
|
28
29
|
import { ClientAbstract } from "./0_client_abstract.js";
|
|
@@ -35,62 +36,155 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
35
36
|
static #AUTH_KEY_CREATION_MAX_TRIES = 10;
|
|
36
37
|
handlers = {};
|
|
37
38
|
#L;
|
|
38
|
-
#
|
|
39
|
+
#dc;
|
|
40
|
+
#apiId;
|
|
41
|
+
#params;
|
|
42
|
+
#authKey = new Uint8Array();
|
|
43
|
+
#authKeyId = 0n;
|
|
44
|
+
#temporaryAuthKey = new Uint8Array();
|
|
45
|
+
#temporaryAuthKeyExpiresIn = 0;
|
|
39
46
|
session;
|
|
40
47
|
#sentRequests = new Map();
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#deviceModel;
|
|
44
|
-
#langCode;
|
|
45
|
-
#langPack;
|
|
46
|
-
#systemLangCode;
|
|
47
|
-
#systemVersion;
|
|
48
|
-
#disableUpdates;
|
|
48
|
+
#isAuthKeyBound = false;
|
|
49
|
+
#isPerfectForwardSecrecyEnabled = false;
|
|
49
50
|
constructor(dc, apiId, params) {
|
|
50
51
|
super();
|
|
51
52
|
this.#L = getLogger("ClientEncrypted").client(id++);
|
|
52
|
-
this.#
|
|
53
|
+
this.#dc = dc;
|
|
54
|
+
this.#apiId = apiId;
|
|
55
|
+
this.#params = params;
|
|
56
|
+
this.#isPerfectForwardSecrecyEnabled = params?.isPerfectForwardSecrecyEnabled ?? false;
|
|
53
57
|
this.session = new SessionEncrypted(dc, params);
|
|
58
|
+
this.session.handlers.onTransportError = this.#onTransportError.bind(this);
|
|
54
59
|
this.session.handlers.onUpdate = this.#onUpdate.bind(this);
|
|
55
60
|
this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
|
|
56
61
|
this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
|
|
57
62
|
this.session.handlers.onRpcError = this.#onRpcError.bind(this);
|
|
58
63
|
this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
|
|
59
64
|
this.session.handlers.onPong = this.#onPong.bind(this);
|
|
60
|
-
this.#apiId = apiId;
|
|
61
|
-
this.#appVersion = params?.appVersion ?? APP_VERSION;
|
|
62
|
-
this.#deviceModel = params?.deviceModel ?? DEVICE_MODEL;
|
|
63
|
-
this.#langCode = params?.langCode ?? LANG_CODE;
|
|
64
|
-
this.#langPack = params?.langPack ?? LANG_PACK;
|
|
65
|
-
this.#systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
|
|
66
|
-
this.#systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
|
|
67
|
-
this.#disableUpdates = params?.disableUpdates ?? false;
|
|
68
65
|
}
|
|
69
|
-
async
|
|
66
|
+
async #encryptMessage(message) {
|
|
67
|
+
const payloadWriter = new TLWriter();
|
|
68
|
+
payloadWriter.writeInt64(getRandomId());
|
|
69
|
+
payloadWriter.writeInt64(getRandomId());
|
|
70
|
+
payloadWriter.write(await serializeMessage(message));
|
|
71
|
+
let payload = payloadWriter.buffer;
|
|
72
|
+
const payloadSha1 = await sha1(payload);
|
|
73
|
+
const messageKey = payloadSha1.subarray(4, 20);
|
|
74
|
+
payloadWriter.write(new Uint8Array(mod(-payload.byteLength, 16)));
|
|
75
|
+
payload = payloadWriter.buffer;
|
|
76
|
+
const sha1A = await sha1(concat([messageKey, this.#authKey.subarray(0, 32)]));
|
|
77
|
+
const sha1B = await sha1(concat([this.#authKey.slice(32, 48), messageKey, this.#authKey.slice(48, 64)]));
|
|
78
|
+
const sha1C = await sha1(concat([this.#authKey.slice(64, 96), messageKey]));
|
|
79
|
+
const sha1D = await sha1(concat([messageKey, this.#authKey.slice(96, 128)]));
|
|
80
|
+
const encryptionKey = concat([sha1A.slice(0, 8), sha1B.slice(8, 20), sha1C.slice(4, 16)]);
|
|
81
|
+
const encryptionIv = concat([sha1A.slice(8, 20), sha1B.slice(0, 8), sha1C.slice(16, 20), sha1D.slice(0, 8)]);
|
|
82
|
+
const encrypted = ige256Encrypt(payload, encryptionKey, encryptionIv);
|
|
83
|
+
const messageWriter = new TLWriter();
|
|
84
|
+
messageWriter.writeInt64(this.#authKeyId);
|
|
85
|
+
messageWriter.write(messageKey);
|
|
86
|
+
messageWriter.write(encrypted);
|
|
87
|
+
return messageWriter.buffer;
|
|
88
|
+
}
|
|
89
|
+
#connectPromise;
|
|
90
|
+
connect() {
|
|
91
|
+
return this.#connectPromise ??= this.#connect().finally(() => this.#connectPromise = undefined);
|
|
92
|
+
}
|
|
93
|
+
async #connect() {
|
|
70
94
|
if (!this.authKey.byteLength) {
|
|
71
95
|
await this.#createAuthKey();
|
|
72
96
|
}
|
|
97
|
+
else if (this.#isPerfectForwardSecrecyEnabled) {
|
|
98
|
+
this.#L.debug("creating temporary auth key");
|
|
99
|
+
await this.#createAuthKeyInner(true);
|
|
100
|
+
}
|
|
73
101
|
await super.connect();
|
|
102
|
+
if (this.#isPerfectForwardSecrecyEnabled) {
|
|
103
|
+
this.#isAuthKeyBound = false;
|
|
104
|
+
await this.#bindTemporaryAuthKey();
|
|
105
|
+
drop(this.#refreshTemporaryAuthKey());
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.#isAuthKeyBound = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async #bindTemporaryAuthKey() {
|
|
112
|
+
const nonce = getRandomId();
|
|
113
|
+
const expires_at = toUnixTimestamp(new Date()) + TEMPORARY_AUTH_KEY_TTL;
|
|
114
|
+
this.#temporaryAuthKeyExpiresIn = fromUnixTimestamp(expires_at).getTime() - Date.now();
|
|
115
|
+
const object = {
|
|
116
|
+
_: "bind_auth_key_inner",
|
|
117
|
+
perm_auth_key_id: this.#authKeyId,
|
|
118
|
+
nonce,
|
|
119
|
+
expires_at,
|
|
120
|
+
temp_auth_key_id: this.session.authKeyId,
|
|
121
|
+
temp_session_id: this.session.id,
|
|
122
|
+
};
|
|
123
|
+
const encrypted_message = await this.#encryptMessage({
|
|
124
|
+
_: "message",
|
|
125
|
+
seqno: 0,
|
|
126
|
+
msg_id: this.session.previewNextMessageId(),
|
|
127
|
+
body: Mtproto.serializeObject(object),
|
|
128
|
+
});
|
|
129
|
+
await this.invoke({
|
|
130
|
+
_: "auth.bindTempAuthKey",
|
|
131
|
+
perm_auth_key_id: this.#authKeyId,
|
|
132
|
+
nonce,
|
|
133
|
+
encrypted_message,
|
|
134
|
+
expires_at,
|
|
135
|
+
}), this.#isAuthKeyBound = true;
|
|
136
|
+
}
|
|
137
|
+
#temporaryAuthKeyTimeoutController;
|
|
138
|
+
async #refreshTemporaryAuthKey() {
|
|
139
|
+
this.#temporaryAuthKeyTimeoutController?.abort();
|
|
140
|
+
const controller = this.#temporaryAuthKeyTimeoutController = new AbortController();
|
|
141
|
+
await delay(Math.max(0, this.#temporaryAuthKeyExpiresIn - 5 * SECOND), { signal: controller.signal });
|
|
142
|
+
if (this.#temporaryAuthKeyTimeoutController !== controller) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.#temporaryAuthKeyTimeoutController = undefined;
|
|
146
|
+
this.#L.debug("reconnecting with a new temporary auth key");
|
|
147
|
+
this.disconnect();
|
|
148
|
+
drop(this.connect());
|
|
74
149
|
}
|
|
75
150
|
disconnect() {
|
|
76
151
|
super.disconnect();
|
|
152
|
+
this.#temporaryAuthKeyTimeoutController?.abort();
|
|
153
|
+
this.#temporaryAuthKeyTimeoutController = undefined;
|
|
77
154
|
this.lastRequest = undefined;
|
|
155
|
+
const error = new ConnectionError("The connection was closed.");
|
|
156
|
+
for (const request of this.#sentRequests.values()) {
|
|
157
|
+
request.promiseWithResolvers.reject(error);
|
|
158
|
+
}
|
|
159
|
+
this.#sentRequests.clear();
|
|
78
160
|
}
|
|
79
161
|
#createAuthKeyPromise;
|
|
80
162
|
#createAuthKey() {
|
|
81
|
-
return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
|
|
163
|
+
return this.#createAuthKeyPromise ??= (this.#isPerfectForwardSecrecyEnabled ? Promise.all([this.#createAuthKeyInner(false), this.#createAuthKeyInner(true)]) : this.#createAuthKeyInner(false)).finally(() => {
|
|
82
164
|
this.#createAuthKeyPromise = undefined;
|
|
83
165
|
});
|
|
84
166
|
}
|
|
85
|
-
async #createAuthKeyInner() {
|
|
167
|
+
async #createAuthKeyInner(isTemporary) {
|
|
86
168
|
let lastErr;
|
|
87
169
|
let errored = false;
|
|
170
|
+
const plain = new ClientPlain(this.#dc, this.#params);
|
|
88
171
|
for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
|
|
89
172
|
try {
|
|
90
|
-
await
|
|
91
|
-
const [authKey, serverSalt] = await
|
|
92
|
-
|
|
93
|
-
|
|
173
|
+
await plain.connect();
|
|
174
|
+
const [authKey, serverSalt] = await plain.createAuthKey(isTemporary);
|
|
175
|
+
if (isTemporary) {
|
|
176
|
+
this.#temporaryAuthKey = authKey;
|
|
177
|
+
await this.session.setAuthKey(this.#temporaryAuthKey);
|
|
178
|
+
this.session.serverSalt = serverSalt;
|
|
179
|
+
this.#isConnectionInited = false;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
await this.setAuthKey(authKey);
|
|
183
|
+
}
|
|
184
|
+
if (!this.#isPerfectForwardSecrecyEnabled) {
|
|
185
|
+
await this.session.setAuthKey(authKey);
|
|
186
|
+
this.session.serverSalt = serverSalt;
|
|
187
|
+
}
|
|
94
188
|
errored = false;
|
|
95
189
|
break;
|
|
96
190
|
}
|
|
@@ -103,7 +197,7 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
103
197
|
this.#L.error("failed to create auth key:", err);
|
|
104
198
|
}
|
|
105
199
|
finally {
|
|
106
|
-
|
|
200
|
+
plain.disconnect();
|
|
107
201
|
}
|
|
108
202
|
}
|
|
109
203
|
if (errored) {
|
|
@@ -111,12 +205,19 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
111
205
|
}
|
|
112
206
|
}
|
|
113
207
|
get authKey() {
|
|
114
|
-
return this.session.authKey;
|
|
208
|
+
return this.#isPerfectForwardSecrecyEnabled ? this.#authKey : this.session.authKey;
|
|
115
209
|
}
|
|
116
210
|
async setAuthKey(authKey) {
|
|
117
|
-
|
|
211
|
+
if (this.#isPerfectForwardSecrecyEnabled) {
|
|
212
|
+
const hash = await sha1(authKey);
|
|
213
|
+
this.#authKeyId = intFromBytes(hash.slice(-8));
|
|
214
|
+
this.#authKey = authKey;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
await this.session.setAuthKey(authKey);
|
|
218
|
+
}
|
|
118
219
|
}
|
|
119
|
-
#
|
|
220
|
+
#isConnectionInited = false;
|
|
120
221
|
lastRequest;
|
|
121
222
|
async #send(function_) {
|
|
122
223
|
this.lastRequest = new Date();
|
|
@@ -125,27 +226,27 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
125
226
|
body = Mtproto.serializeObject(function_);
|
|
126
227
|
}
|
|
127
228
|
else {
|
|
128
|
-
if (this.#disableUpdates && !isMediaFunction(function_)) {
|
|
229
|
+
if (this.#isAuthKeyBound && this.#params?.disableUpdates && !isMediaFunction(function_)) {
|
|
129
230
|
function_ = { _: "invokeWithoutUpdates", query: function_ };
|
|
130
231
|
}
|
|
131
|
-
if (!this.#
|
|
232
|
+
if (this.#isAuthKeyBound && !this.#isConnectionInited) {
|
|
132
233
|
if (!this.#apiId) {
|
|
133
234
|
throw new InputError("apiId not set");
|
|
134
235
|
}
|
|
135
236
|
function_ = {
|
|
136
237
|
_: "initConnection",
|
|
137
238
|
api_id: this.#apiId,
|
|
138
|
-
app_version: this.#appVersion,
|
|
139
|
-
device_model: this.#deviceModel,
|
|
140
|
-
lang_code: this.#langCode,
|
|
141
|
-
lang_pack: this.#langPack,
|
|
239
|
+
app_version: this.#params?.appVersion ?? APP_VERSION,
|
|
240
|
+
device_model: this.#params?.deviceModel ?? DEVICE_MODEL,
|
|
241
|
+
lang_code: this.#params?.langCode ?? LANG_CODE,
|
|
242
|
+
lang_pack: this.#params?.langPack ?? LANG_PACK,
|
|
142
243
|
query: {
|
|
143
244
|
_: "invokeWithLayer",
|
|
144
245
|
layer: Api.LAYER,
|
|
145
246
|
query: function_,
|
|
146
247
|
},
|
|
147
|
-
system_lang_code: this.#systemLangCode,
|
|
148
|
-
system_version: this.#systemVersion,
|
|
248
|
+
system_lang_code: this.#params?.systemLangCode ?? SYSTEM_LANG_CODE,
|
|
249
|
+
system_version: this.#params?.systemVersion ?? SYSTEM_VERSION,
|
|
149
250
|
};
|
|
150
251
|
}
|
|
151
252
|
body = Api.serializeObject(function_);
|
|
@@ -190,6 +291,17 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
190
291
|
this.#sentRequests.set(messageId, sentRequest);
|
|
191
292
|
return await sentRequest.promiseWithResolvers.promise;
|
|
192
293
|
}
|
|
294
|
+
async #onTransportError(transportError) {
|
|
295
|
+
this.#L.error("transport error:", transportError);
|
|
296
|
+
if (!this.#isPerfectForwardSecrecyEnabled) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (transportError.code === -404) {
|
|
300
|
+
this.#L.debug("reconnecting with a new temporary auth key");
|
|
301
|
+
this.disconnect();
|
|
302
|
+
await this.connect();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
193
305
|
async #onUpdate(body) {
|
|
194
306
|
let type;
|
|
195
307
|
try {
|
|
@@ -197,18 +309,18 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
197
309
|
}
|
|
198
310
|
catch (err) {
|
|
199
311
|
this.#L.error("failed to deserialize update:", err);
|
|
200
|
-
this.handlers.onDeserializationError?.();
|
|
312
|
+
await this.handlers.onDeserializationError?.();
|
|
201
313
|
return;
|
|
202
314
|
}
|
|
203
315
|
if (Api.isOfEnum("Update", type) || Api.isOfEnum("Updates", type)) {
|
|
204
|
-
this.handlers.onUpdate?.(type);
|
|
316
|
+
await this.handlers.onUpdate?.(type);
|
|
205
317
|
}
|
|
206
318
|
else {
|
|
207
319
|
this.#L.warning("received unknown type:", repr(type));
|
|
208
320
|
}
|
|
209
321
|
}
|
|
210
322
|
#onNewServerSalt(serverSalt) {
|
|
211
|
-
this.handlers.onNewServerSalt?.(serverSalt);
|
|
323
|
+
drop(this.handlers.onNewServerSalt?.(serverSalt));
|
|
212
324
|
}
|
|
213
325
|
async #onMessageFailed(msgId, error) {
|
|
214
326
|
const request = this.#sentRequests.get(msgId);
|
|
@@ -223,13 +335,18 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
223
335
|
}
|
|
224
336
|
}
|
|
225
337
|
async #onRpcError(msgId, error) {
|
|
338
|
+
if (error.error_message === "AUTH_KEY_PERM_EMPTY" || error.error_message === "ENCRYPTED_MESSAGE_INVALID") {
|
|
339
|
+
this.#L.debug("reconnecting with a new temporary auth key because of", error.error_message);
|
|
340
|
+
this.disconnect();
|
|
341
|
+
await this.connect();
|
|
342
|
+
}
|
|
226
343
|
const request = this.#sentRequests.get(msgId);
|
|
227
344
|
this.#L.debug("received rpc_error with req_msg_id =", msgId, "for", request === undefined ? "unknown" : "known", "request");
|
|
228
345
|
if (request) {
|
|
229
346
|
this.#sentRequests.delete(msgId);
|
|
230
347
|
const reason = constructTelegramError(error, request.call);
|
|
231
348
|
if (reason instanceof ConnectionNotInited) {
|
|
232
|
-
this.#
|
|
349
|
+
this.#isConnectionInited = false;
|
|
233
350
|
await this.#resend(request);
|
|
234
351
|
}
|
|
235
352
|
else {
|
|
@@ -251,15 +368,15 @@ export class ClientEncrypted extends ClientAbstract {
|
|
|
251
368
|
catch (err) {
|
|
252
369
|
sentRequest.promiseWithResolvers.reject(err);
|
|
253
370
|
this.#L.error("failed to deserialize rpc_result body:", err);
|
|
254
|
-
this.handlers.onDeserializationError?.();
|
|
371
|
+
await this.handlers.onDeserializationError?.();
|
|
255
372
|
return;
|
|
256
373
|
}
|
|
257
374
|
finally {
|
|
258
375
|
this.#sentRequests.delete(msgId);
|
|
259
376
|
}
|
|
260
377
|
}
|
|
261
|
-
if (!this.#
|
|
262
|
-
this.#
|
|
378
|
+
if (!this.#isConnectionInited) {
|
|
379
|
+
this.#isConnectionInited = true;
|
|
263
380
|
}
|
|
264
381
|
}
|
|
265
382
|
#onPong(pong) {
|
|
@@ -434,7 +434,7 @@ export class FileManager {
|
|
|
434
434
|
}
|
|
435
435
|
const big = fileId_.location.source.type === PhotoSourceType.ChatPhotoBig;
|
|
436
436
|
const peer = await this.#c.getInputPeer(Number(fileId_.location.source.chatId));
|
|
437
|
-
const location = { _: "inputPeerPhotoFileLocation", big: big
|
|
437
|
+
const location = { _: "inputPeerPhotoFileLocation", big: big || undefined, peer, photo_id: fileId_.location.id };
|
|
438
438
|
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
439
439
|
break;
|
|
440
440
|
}
|
|
@@ -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;
|
|
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"}
|
|
@@ -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 { drop } from "../utilities/0_misc.js";
|
|
20
21
|
import { getLogger } from "../utilities/1_logger.js";
|
|
21
22
|
export class NetworkStatisticsManager {
|
|
22
23
|
#c;
|
|
@@ -48,12 +49,12 @@ export class NetworkStatisticsManager {
|
|
|
48
49
|
read: (count) => {
|
|
49
50
|
const key = isMedia ? "netstat_media_read" : "netstat_messages_read";
|
|
50
51
|
this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
|
|
51
|
-
this.#write();
|
|
52
|
+
drop(this.#write());
|
|
52
53
|
},
|
|
53
54
|
write: (count) => {
|
|
54
55
|
const key = isMedia ? "netstat_media_write" : "netstat_messages_write";
|
|
55
56
|
this.#pendingWrites[key] = (this.#pendingWrites[key] ?? 0) + count;
|
|
56
|
-
this.#write();
|
|
57
|
+
drop(this.#write());
|
|
57
58
|
},
|
|
58
59
|
};
|
|
59
60
|
}
|
|
@@ -48,7 +48,7 @@ export class PaymentManager {
|
|
|
48
48
|
if (!queryId) {
|
|
49
49
|
throw new InputError("Invalid pre-checkout query ID");
|
|
50
50
|
}
|
|
51
|
-
await this.#c.invoke({ _: "messages.setBotPrecheckoutResults", query_id: queryId, error: params?.error, success: ok
|
|
51
|
+
await this.#c.invoke({ _: "messages.setBotPrecheckoutResults", query_id: queryId, error: params?.error, success: ok || undefined });
|
|
52
52
|
}
|
|
53
53
|
async refundStarPayment(userId, telegramPaymentChargeId) {
|
|
54
54
|
this.#c.storage.assertBot("refundStarPayment");
|
|
@@ -82,7 +82,7 @@ export class PaymentManager {
|
|
|
82
82
|
const peer = await this.#c.getInputPeer(chatId);
|
|
83
83
|
const offset = params?.offset ?? "";
|
|
84
84
|
const limit = getLimit(params?.limit);
|
|
85
|
-
const result = await this.#c.invoke({ _: "payments.getStarsTransactions", peer, ton: params?.isTon
|
|
85
|
+
const result = await this.#c.invoke({ _: "payments.getStarsTransactions", peer, ton: params?.isTon || undefined, offset, limit, inbound: params?.isInbound || undefined, outbound: params?.isOutbound || undefined, ascending: params?.isAscending || undefined, subscription_id: params?.subscriptionId });
|
|
86
86
|
return constructStarTransactionList(result, this.#c.getPeer);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -25,12 +25,12 @@ export class TakeoutManager {
|
|
|
25
25
|
}
|
|
26
26
|
async startTakeoutSession(params) {
|
|
27
27
|
this.#c.storage.assertUser("startTakeoutSession");
|
|
28
|
-
const result = await this.#c.invoke({ _: "account.initTakeoutSession", contacts: params?.isExportingContacts
|
|
28
|
+
const result = await this.#c.invoke({ _: "account.initTakeoutSession", contacts: params?.isExportingContacts || undefined, message_users: params?.isExportingPrivateChats || undefined, message_chats: params?.isExportingGroupChats || undefined, message_megagroups: params?.isExportingSupergroupChats || undefined, message_channels: params?.isExportingChannelChats || undefined, files: params?.isExportingFiles || undefined, file_max_size: params?.maxFileSize ? BigInt(params.maxFileSize) : undefined });
|
|
29
29
|
return String(result.id);
|
|
30
30
|
}
|
|
31
31
|
async endTakeoutSession(takeoutId, params) {
|
|
32
32
|
this.#c.storage.assertUser("endTakeoutSession");
|
|
33
|
-
await this.#c.invoke({ _: "account.finishTakeoutSession", success: params?.isFailed
|
|
33
|
+
await this.#c.invoke({ _: "account.finishTakeoutSession", success: !params?.isFailed || undefined }, { takeoutId });
|
|
34
34
|
}
|
|
35
35
|
async getLeftChannels(takeoutId, params) {
|
|
36
36
|
this.#c.storage.assertUser("getLeftChannels");
|
|
@@ -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,CAAC,qBAAqB,GACzB,GAAG,CAAC,w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IAAI;IAsMvH,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAsVrC,gBAAgB,CAAC,OAAO,EAAE,aAAa;IAKjC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,cAAc;IA4C5C,SAAS,CAAC,MAAM,EAAE,EAAE;IAW1B,aAAa;CAMd"}
|
|
@@ -393,13 +393,13 @@ export class UpdateManager {
|
|
|
393
393
|
this.#processUpdatesQueue.add(() => this.#processUpdates(updates, checkGap, call).finally(callback));
|
|
394
394
|
}
|
|
395
395
|
async #processUpdates(updates_, checkGap, call = null) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
396
|
+
// First, individual updates (Update[1]) are extracted from Updates.[2]
|
|
397
|
+
//
|
|
398
|
+
// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
399
|
+
//
|
|
400
|
+
// [1]: https://core.telegram.org/type/Update
|
|
401
|
+
// [2]: https://core.telegram.org/type/Updates
|
|
402
|
+
// [3]: https://core.telegram.org/constructor/updatesTooLong
|
|
403
403
|
let updates;
|
|
404
404
|
if (Api.is("updatesCombined", updates_) || Api.is("updates", updates_)) {
|
|
405
405
|
updates = updates_.updates;
|
|
@@ -426,7 +426,7 @@ export class UpdateManager {
|
|
|
426
426
|
return;
|
|
427
427
|
}
|
|
428
428
|
else if (localSeq + 1 < seqStart) {
|
|
429
|
-
// There's an
|
|
429
|
+
// There's an update gap that must be filled.
|
|
430
430
|
await this.recoverUpdateGap("localSeq + 1 < seqStart");
|
|
431
431
|
}
|
|
432
432
|
}
|
|
@@ -524,7 +524,7 @@ export class UpdateManager {
|
|
|
524
524
|
if (Api.is("updates", updates_) || Api.is("updatesCombined", updates_)) {
|
|
525
525
|
this.processChats(updates_.chats, updates_);
|
|
526
526
|
this.processUsers(updates_.users, updates_);
|
|
527
|
-
this.#setUpdateStateDate(updates_.date);
|
|
527
|
+
await this.#setUpdateStateDate(updates_.date);
|
|
528
528
|
}
|
|
529
529
|
else if (Api.isOneOf([
|
|
530
530
|
"updateShort",
|
|
@@ -624,7 +624,12 @@ export class UpdateManager {
|
|
|
624
624
|
continue;
|
|
625
625
|
}
|
|
626
626
|
else {
|
|
627
|
-
|
|
627
|
+
if (this.#c.isDisconnected()) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
throw err;
|
|
632
|
+
}
|
|
628
633
|
}
|
|
629
634
|
}
|
|
630
635
|
if (Api.is("updates.difference", difference) || Api.is("updates.differenceSlice", difference)) {
|
|
@@ -953,7 +958,7 @@ export class UpdateManager {
|
|
|
953
958
|
}
|
|
954
959
|
const controller = new AbortController();
|
|
955
960
|
const promise = Promise.resolve().then(async () => {
|
|
956
|
-
const logger = this.#LopenChat.branch(Api.peerToChatId(channel)
|
|
961
|
+
const logger = this.#LopenChat.branch(String(Api.peerToChatId(channel)));
|
|
957
962
|
while (true) {
|
|
958
963
|
if (this.#c.isDisconnected()) {
|
|
959
964
|
logger.debug("disconnected, stopping the loop");
|
|
@@ -415,7 +415,7 @@ export class AccountManager {
|
|
|
415
415
|
}
|
|
416
416
|
async #toggleBotAddedtoAttachmentsMenu(botId, isWriteAllowed, enabled) {
|
|
417
417
|
const bot = await this.#c.getInputUser(botId);
|
|
418
|
-
await this.#c.invoke({ _: "messages.toggleBotInAttachMenu", bot, write_allowed: isWriteAllowed
|
|
418
|
+
await this.#c.invoke({ _: "messages.toggleBotInAttachMenu", bot, write_allowed: isWriteAllowed || undefined, enabled });
|
|
419
419
|
}
|
|
420
420
|
async addBotToAttachmentsMenu(botId, params) {
|
|
421
421
|
this.#c.storage.assertUser("addBotToAttachmentsMenu");
|
|
@@ -456,7 +456,7 @@ export class AccountManager {
|
|
|
456
456
|
}
|
|
457
457
|
const bot = params?.botId ? await this.#c.getInputUser(params.botId) : undefined;
|
|
458
458
|
const file = await this.#c.fileManager.upload(photo, params, checkPhotoName(params));
|
|
459
|
-
await this.#c.invoke({ _: "photos.uploadProfilePhoto", fallback: params?.isPublic
|
|
459
|
+
await this.#c.invoke({ _: "photos.uploadProfilePhoto", fallback: params?.isPublic || undefined, file, bot });
|
|
460
460
|
}
|
|
461
461
|
async updateProfileVideo(photo, params) {
|
|
462
462
|
if (params?.botId && this.#c.storage.isBot) {
|
|
@@ -464,7 +464,7 @@ export class AccountManager {
|
|
|
464
464
|
}
|
|
465
465
|
const bot = params?.botId ? await this.#c.getInputUser(params.botId) : undefined;
|
|
466
466
|
const video = await this.#c.fileManager.upload(photo, params, () => "video.mp4");
|
|
467
|
-
await this.#c.invoke({ _: "photos.uploadProfilePhoto", fallback: params?.isPublic
|
|
467
|
+
await this.#c.invoke({ _: "photos.uploadProfilePhoto", fallback: params?.isPublic || undefined, video, video_start_ts: params?.thumbnailTimestamp, bot });
|
|
468
468
|
}
|
|
469
469
|
async removeProfilePhoto(params) {
|
|
470
470
|
if (params?.botId && this.#c.storage.isBot) {
|
|
@@ -134,6 +134,17 @@ export declare class MessageManager implements UpdateProcessor<MessageManagerUpd
|
|
|
134
134
|
translateMessages(toLanguage: string, chatId: ID, messageIds: number[], params?: TranslateTextParams): Promise<TranslatedText[]>;
|
|
135
135
|
translateMessage(toLanguage: string, chatId: ID, messageId: number, params?: TranslateTextParams): Promise<TranslatedText>;
|
|
136
136
|
getRichText(chatId: ID, messageId: number): Promise<import("../3_types.js").RichText | null>;
|
|
137
|
+
getScheduledMessages(chatId: ID): Promise<Message[]>;
|
|
138
|
+
getFavoriteStickers(): Promise<import("../3_types.js").Sticker[]>;
|
|
139
|
+
addStickerToFavorites(fileId: string): Promise<void>;
|
|
140
|
+
removeStickerFromFavorites(fileId: string): Promise<void>;
|
|
141
|
+
addStickerToRecents(fileId: string): Promise<void>;
|
|
142
|
+
removeStickerFromRecents(fileId: string): Promise<void>;
|
|
143
|
+
clearRecentStickers(): Promise<void>;
|
|
144
|
+
getRecentStickers(): Promise<import("../3_types.js").Sticker[]>;
|
|
145
|
+
getSavedAnimations(): Promise<import("../3_types.js").Animation[]>;
|
|
146
|
+
saveAnimation(fileId: string): Promise<void>;
|
|
147
|
+
unsaveAnimation(fileId: string): Promise<void>;
|
|
137
148
|
}
|
|
138
149
|
export {};
|
|
139
150
|
//# sourceMappingURL=3_message_manager.d.ts.map
|