@tgsnake/skema 1.13.0 → 2.0.0-browser.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/LICENSE +1 -1
- package/README.md +124 -15
- package/dist/mod.d.ts +10 -0
- package/dist/mod.js +10 -0
- package/dist/src/Logger.d.ts +20 -0
- package/dist/src/Logger.js +23 -0
- package/dist/src/deps.d.ts +29 -0
- package/dist/src/deps.js +34 -0
- package/dist/src/errors/Base.d.ts +53 -0
- package/dist/src/errors/Base.js +114 -0
- package/dist/src/errors/Client.d.ts +69 -0
- package/dist/src/errors/Client.js +69 -0
- package/dist/src/errors/File.d.ts +89 -0
- package/dist/src/errors/File.js +99 -0
- package/dist/src/errors/RpcError.d.ts +115 -0
- package/dist/src/errors/RpcError.js +226 -0
- package/dist/src/errors/SecretChat.d.ts +78 -0
- package/dist/src/errors/SecretChat.js +88 -0
- package/dist/src/errors/WebSocket.d.ts +70 -0
- package/dist/src/errors/WebSocket.js +80 -0
- package/dist/{errors → src/errors}/exceptions/All.d.ts +14 -0
- package/dist/{errors → src/errors}/exceptions/All.js +15 -5
- package/dist/{errors → src/errors}/exceptions/BadRequest400.d.ts +15 -1
- package/dist/src/errors/exceptions/BadRequest400.js +2683 -0
- package/dist/{errors → src/errors}/exceptions/Flood420.d.ts +15 -1
- package/dist/{errors → src/errors}/exceptions/Flood420.js +25 -24
- package/dist/{errors → src/errors}/exceptions/Forbidden403.d.ts +15 -1
- package/dist/src/errors/exceptions/Forbidden403.js +243 -0
- package/dist/{errors → src/errors}/exceptions/InternalServerError500.d.ts +15 -1
- package/dist/src/errors/exceptions/InternalServerError500.js +255 -0
- package/dist/{errors → src/errors}/exceptions/NotAcceptable406.d.ts +15 -1
- package/dist/{errors → src/errors}/exceptions/NotAcceptable406.js +51 -76
- package/dist/src/errors/exceptions/NotFound404.d.ts +27 -0
- package/dist/src/errors/exceptions/NotFound404.js +27 -0
- package/dist/src/errors/exceptions/SeeOther303.d.ts +39 -0
- package/dist/src/errors/exceptions/SeeOther303.js +39 -0
- package/dist/src/errors/exceptions/ServiceUnavailable503.d.ts +31 -0
- package/dist/src/errors/exceptions/ServiceUnavailable503.js +31 -0
- package/dist/{errors → src/errors}/exceptions/Unauthorized401.d.ts +15 -1
- package/dist/src/errors/exceptions/Unauthorized401.js +55 -0
- package/dist/src/errors/exceptions/index.d.ts +24 -0
- package/dist/src/errors/exceptions/index.js +24 -0
- package/dist/src/errors/index.d.ts +142 -0
- package/dist/src/errors/index.js +178 -0
- package/dist/src/helpers.d.ts +102 -0
- package/dist/src/helpers.js +176 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +12 -0
- package/dist/{raw → src/raw}/All.d.ts +14 -0
- package/dist/{raw → src/raw}/All.js +15 -4
- package/dist/{raw → src/raw}/Raw.d.ts +17205 -3
- package/dist/{raw → src/raw}/Raw.js +44035 -21917
- package/dist/src/raw/UpdateSecretChat.d.ts +186 -0
- package/dist/src/raw/UpdateSecretChat.js +215 -0
- package/dist/src/raw/core/GzipPacked.d.ts +63 -0
- package/dist/src/raw/core/GzipPacked.js +76 -0
- package/dist/src/raw/core/Message.d.ts +68 -0
- package/dist/src/raw/core/Message.js +105 -0
- package/dist/src/raw/core/MsgContainer.d.ts +56 -0
- package/dist/src/raw/core/MsgContainer.js +77 -0
- package/dist/src/raw/core/TLObject.d.ts +108 -0
- package/dist/src/raw/core/TLObject.js +209 -0
- package/dist/src/raw/core/index.d.ts +19 -0
- package/dist/src/raw/core/index.js +19 -0
- package/dist/src/raw/core/primitive/Bool.d.ts +104 -0
- package/dist/src/raw/core/primitive/Bool.js +120 -0
- package/dist/src/raw/core/primitive/Bytes.d.ts +45 -0
- package/dist/src/raw/core/primitive/Bytes.js +76 -0
- package/dist/src/raw/core/primitive/Double.d.ts +37 -0
- package/dist/src/raw/core/primitive/Double.js +51 -0
- package/dist/src/raw/core/primitive/Float.d.ts +37 -0
- package/dist/src/raw/core/primitive/Float.js +51 -0
- package/dist/src/raw/core/primitive/Int.d.ts +144 -0
- package/dist/src/raw/core/primitive/Int.js +237 -0
- package/dist/src/raw/core/primitive/String.d.ts +37 -0
- package/dist/src/raw/core/primitive/String.js +42 -0
- package/dist/src/raw/core/primitive/Vector.d.ts +56 -0
- package/dist/src/raw/core/primitive/Vector.js +93 -0
- package/dist/src/raw/core/primitive/index.d.ts +20 -0
- package/dist/src/raw/core/primitive/index.js +20 -0
- package/dist/src/raw/index.d.ts +17 -0
- package/dist/src/raw/index.js +17 -0
- package/package.json +54 -50
- package/dist/Logger.d.ts +0 -3
- package/dist/Logger.js +0 -9
- package/dist/deps.d.ts +0 -8
- package/dist/deps.js +0 -19
- package/dist/errors/Base.d.ts +0 -9
- package/dist/errors/Base.js +0 -50
- package/dist/errors/Client.d.ts +0 -21
- package/dist/errors/Client.js +0 -29
- package/dist/errors/File.d.ts +0 -13
- package/dist/errors/File.js +0 -30
- package/dist/errors/RpcError.d.ts +0 -22
- package/dist/errors/RpcError.js +0 -120
- package/dist/errors/SecretChat.d.ts +0 -13
- package/dist/errors/SecretChat.js +0 -30
- package/dist/errors/WebSocket.d.ts +0 -13
- package/dist/errors/WebSocket.js +0 -30
- package/dist/errors/exceptions/BadRequest400.js +0 -3352
- package/dist/errors/exceptions/Forbidden403.js +0 -290
- package/dist/errors/exceptions/InternalServerError500.js +0 -305
- package/dist/errors/exceptions/NotFound404.d.ts +0 -13
- package/dist/errors/exceptions/NotFound404.js +0 -19
- package/dist/errors/exceptions/SeeOther303.d.ts +0 -25
- package/dist/errors/exceptions/SeeOther303.js +0 -34
- package/dist/errors/exceptions/ServiceUnavailable503.d.ts +0 -17
- package/dist/errors/exceptions/ServiceUnavailable503.js +0 -24
- package/dist/errors/exceptions/Unauthorized401.js +0 -54
- package/dist/errors/exceptions/index.d.ts +0 -10
- package/dist/errors/exceptions/index.js +0 -48
- package/dist/errors/index.d.ts +0 -31
- package/dist/errors/index.js +0 -111
- package/dist/helpers.d.ts +0 -6
- package/dist/helpers.js +0 -85
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -34
- package/dist/raw/UpdateSecretChat.d.ts +0 -43
- package/dist/raw/UpdateSecretChat.js +0 -91
- package/dist/raw/core/GzipPacked.d.ts +0 -9
- package/dist/raw/core/GzipPacked.js +0 -59
- package/dist/raw/core/Message.d.ts +0 -12
- package/dist/raw/core/Message.js +0 -80
- package/dist/raw/core/MsgContainer.d.ts +0 -10
- package/dist/raw/core/MsgContainer.js +0 -68
- package/dist/raw/core/TLObject.d.ts +0 -18
- package/dist/raw/core/TLObject.js +0 -108
- package/dist/raw/core/index.d.ts +0 -6
- package/dist/raw/core/index.js +0 -46
- package/dist/raw/core/primitive/Bool.d.ts +0 -19
- package/dist/raw/core/primitive/Bool.js +0 -41
- package/dist/raw/core/primitive/Bytes.d.ts +0 -6
- package/dist/raw/core/primitive/Bytes.js +0 -41
- package/dist/raw/core/primitive/Double.d.ts +0 -6
- package/dist/raw/core/primitive/Double.js +0 -24
- package/dist/raw/core/primitive/Float.d.ts +0 -6
- package/dist/raw/core/primitive/Float.js +0 -24
- package/dist/raw/core/primitive/Int.d.ts +0 -22
- package/dist/raw/core/primitive/Int.js +0 -122
- package/dist/raw/core/primitive/String.d.ts +0 -6
- package/dist/raw/core/primitive/String.js +0 -15
- package/dist/raw/core/primitive/Vector.d.ts +0 -8
- package/dist/raw/core/primitive/Vector.js +0 -49
- package/dist/raw/core/primitive/index.d.ts +0 -7
- package/dist/raw/core/primitive/index.js +0 -22
- package/dist/raw/index.d.ts +0 -4
- package/dist/raw/index.js +0 -17
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tgsnake - Telegram MTProto library for javascript or typescript.
|
|
3
|
+
* Copyright (C) 2026 tgsnake <https://github.com/tgsnake>
|
|
4
|
+
*
|
|
5
|
+
* THIS FILE IS PART OF TGSNAKE
|
|
6
|
+
*
|
|
7
|
+
* tgsnake is a free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the MIT License as published.
|
|
9
|
+
*/
|
|
10
|
+
import { Raw } from './Raw.js';
|
|
11
|
+
import { TLObject } from './core/TLObject.js';
|
|
12
|
+
/**
|
|
13
|
+
* Interface representing an E2E decryption generator context.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Any secret chat management instance passed into `UpdateSecretChatMessage.generate` must implement
|
|
17
|
+
* this interface to decrypt incoming encrypted raw Telegram message updates.
|
|
18
|
+
*
|
|
19
|
+
* @interface TypeTGenerate
|
|
20
|
+
*/
|
|
21
|
+
export interface TypeTGenerate {
|
|
22
|
+
/**
|
|
23
|
+
* Decrypts a raw encrypted secret chat message.
|
|
24
|
+
*
|
|
25
|
+
* @param message - The raw encrypted message object received from Telegram.
|
|
26
|
+
* @returns A promise resolving to the decrypted raw message structure.
|
|
27
|
+
*/
|
|
28
|
+
decrypt: (message: Raw.TypeEncryptedMessage) => Promise<Raw.TypeDecryptedMessage>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Represents a decrypted secret chat message update wrapper.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* This modified update structure wraps raw incoming Telegram encrypted updates (`UpdateNewEncryptedMessage`)
|
|
35
|
+
* and replaces the encrypted message payload with its fully-decrypted message or service structure.
|
|
36
|
+
* This simplifies message handling by eliminating manual decrypt stages.
|
|
37
|
+
*
|
|
38
|
+
* @extends TLObject
|
|
39
|
+
*/
|
|
40
|
+
export declare class UpdateSecretChatMessage extends TLObject {
|
|
41
|
+
/**
|
|
42
|
+
* The decrypted message or service message payload.
|
|
43
|
+
*/
|
|
44
|
+
message: SecretChatMessage | SecretChatMessageService;
|
|
45
|
+
/**
|
|
46
|
+
* The queue timestamp (QTS) parameter indicating the sequence order of the update.
|
|
47
|
+
*/
|
|
48
|
+
qts: number;
|
|
49
|
+
/**
|
|
50
|
+
* The original raw Telegram encrypted update instance.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
_original: Raw.UpdateNewEncryptedMessage;
|
|
55
|
+
/**
|
|
56
|
+
* Constructs a new UpdateSecretChatMessage wrapper.
|
|
57
|
+
*
|
|
58
|
+
* @param params - Initial parameter values.
|
|
59
|
+
*/
|
|
60
|
+
constructor(params: {
|
|
61
|
+
message: SecretChatMessage | SecretChatMessageService;
|
|
62
|
+
qts: number;
|
|
63
|
+
original: Raw.UpdateNewEncryptedMessage;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Decrypts a raw encrypted update and generates a fully decrypted `UpdateSecretChatMessage` wrapper.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This static factory determines whether the encrypted message is a standard user message or
|
|
70
|
+
* a service message (e.g. key exchange requests), calls `secretChat.decrypt()` to decrypt the body,
|
|
71
|
+
* constructs the appropriate wrapper class (`SecretChatMessage` or `SecretChatMessageService`),
|
|
72
|
+
* and returns the finalized update object.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam T - The secret chat context class implementing {@link TypeTGenerate}.
|
|
75
|
+
* @param update - The raw `UpdateNewEncryptedMessage` containing the encrypted payload.
|
|
76
|
+
* @param secretChat - The secret chat session manager used to decrypt the message bytes.
|
|
77
|
+
* @returns A promise resolving to the decrypted `UpdateSecretChatMessage` instance.
|
|
78
|
+
*/
|
|
79
|
+
static generate<T>(update: Raw.UpdateNewEncryptedMessage, secretChat: T): Promise<UpdateSecretChatMessage>;
|
|
80
|
+
/**
|
|
81
|
+
* The original raw encrypted message container received from Telegram.
|
|
82
|
+
*
|
|
83
|
+
* @returns The raw original encrypted update object.
|
|
84
|
+
*/
|
|
85
|
+
get original(): Raw.UpdateNewEncryptedMessage;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Represents a decrypted standard text or media message within a secret chat.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* Wraps the decrypted end-to-end encrypted payload together with its local random ID, chat context,
|
|
92
|
+
* timestamp, and optional media file attachments.
|
|
93
|
+
*
|
|
94
|
+
* @extends TLObject
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const secretMessage = new SecretChatMessage({
|
|
98
|
+
* randomId: 1234567890123456789n,
|
|
99
|
+
* chatId: 42,
|
|
100
|
+
* date: 1680000000,
|
|
101
|
+
* message: decryptedMessageInstance,
|
|
102
|
+
* file: encryptedFileInstance
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare class SecretChatMessage extends TLObject {
|
|
107
|
+
/**
|
|
108
|
+
* A unique 64-bit identifier chosen by the client to prevent replay attacks.
|
|
109
|
+
*/
|
|
110
|
+
randomId: bigint;
|
|
111
|
+
/**
|
|
112
|
+
* The unique secret chat identifier.
|
|
113
|
+
*/
|
|
114
|
+
chatId: number;
|
|
115
|
+
/**
|
|
116
|
+
* The Unix timestamp indicating when the message was sent.
|
|
117
|
+
*/
|
|
118
|
+
date: number;
|
|
119
|
+
/**
|
|
120
|
+
* The decrypted inner message payload mapping to a standard version-specific schema.
|
|
121
|
+
*/
|
|
122
|
+
message: Raw.DecryptedMessage8 | Raw.DecryptedMessage17 | Raw.DecryptedMessage45 | Raw.DecryptedMessage73;
|
|
123
|
+
/**
|
|
124
|
+
* The encrypted file attachment description associated with this message, if any.
|
|
125
|
+
*/
|
|
126
|
+
file: Raw.TypeEncryptedFile;
|
|
127
|
+
/**
|
|
128
|
+
* Constructs a new SecretChatMessage instance.
|
|
129
|
+
*
|
|
130
|
+
* @param params - Initial parameter values.
|
|
131
|
+
*/
|
|
132
|
+
constructor(params: {
|
|
133
|
+
randomId: bigint;
|
|
134
|
+
chatId: number;
|
|
135
|
+
date: number;
|
|
136
|
+
message: Raw.DecryptedMessage8 | Raw.DecryptedMessage17 | Raw.DecryptedMessage45 | Raw.DecryptedMessage73;
|
|
137
|
+
file: Raw.TypeEncryptedFile;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Represents a decrypted service command message within a secret chat.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Used for background negotiation signals such as typing notifications, read receipt confirmations,
|
|
145
|
+
* self-destruct changes, or encryption key exchanges.
|
|
146
|
+
*
|
|
147
|
+
* @extends TLObject
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const serviceMessage = new SecretChatMessageService({
|
|
151
|
+
* randomId: 1234567890123456789n,
|
|
152
|
+
* chatId: 42,
|
|
153
|
+
* date: 1680000000,
|
|
154
|
+
* message: decryptedMessageService8Instance
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare class SecretChatMessageService extends TLObject {
|
|
159
|
+
/**
|
|
160
|
+
* A unique 64-bit identifier chosen by the client to prevent replay attacks.
|
|
161
|
+
*/
|
|
162
|
+
randomId: bigint;
|
|
163
|
+
/**
|
|
164
|
+
* The unique secret chat identifier.
|
|
165
|
+
*/
|
|
166
|
+
chatId: number;
|
|
167
|
+
/**
|
|
168
|
+
* The Unix timestamp indicating when the message was sent.
|
|
169
|
+
*/
|
|
170
|
+
date: number;
|
|
171
|
+
/**
|
|
172
|
+
* The decrypted inner service message payload.
|
|
173
|
+
*/
|
|
174
|
+
message: Raw.DecryptedMessageService8 | Raw.DecryptedMessageService17;
|
|
175
|
+
/**
|
|
176
|
+
* Constructs a new SecretChatMessageService instance.
|
|
177
|
+
*
|
|
178
|
+
* @param params - Initial parameter values.
|
|
179
|
+
*/
|
|
180
|
+
constructor(params: {
|
|
181
|
+
randomId: bigint;
|
|
182
|
+
chatId: number;
|
|
183
|
+
date: number;
|
|
184
|
+
message: Raw.DecryptedMessageService8 | Raw.DecryptedMessageService17;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tgsnake - Telegram MTProto library for javascript or typescript.
|
|
3
|
+
* Copyright (C) 2026 tgsnake <https://github.com/tgsnake>
|
|
4
|
+
*
|
|
5
|
+
* THIS FILE IS PART OF TGSNAKE
|
|
6
|
+
*
|
|
7
|
+
* tgsnake is a free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the MIT License as published.
|
|
9
|
+
*/
|
|
10
|
+
import { Raw } from './Raw.js';
|
|
11
|
+
import { TLObject } from './core/TLObject.js';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a decrypted secret chat message update wrapper.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This modified update structure wraps raw incoming Telegram encrypted updates (`UpdateNewEncryptedMessage`)
|
|
17
|
+
* and replaces the encrypted message payload with its fully-decrypted message or service structure.
|
|
18
|
+
* This simplifies message handling by eliminating manual decrypt stages.
|
|
19
|
+
*
|
|
20
|
+
* @extends TLObject
|
|
21
|
+
*/
|
|
22
|
+
export class UpdateSecretChatMessage extends TLObject {
|
|
23
|
+
/**
|
|
24
|
+
* The decrypted message or service message payload.
|
|
25
|
+
*/
|
|
26
|
+
message;
|
|
27
|
+
/**
|
|
28
|
+
* The queue timestamp (QTS) parameter indicating the sequence order of the update.
|
|
29
|
+
*/
|
|
30
|
+
qts;
|
|
31
|
+
/**
|
|
32
|
+
* The original raw Telegram encrypted update instance.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
_original;
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new UpdateSecretChatMessage wrapper.
|
|
39
|
+
*
|
|
40
|
+
* @param params - Initial parameter values.
|
|
41
|
+
*/
|
|
42
|
+
constructor(params) {
|
|
43
|
+
super();
|
|
44
|
+
this.classType = 'modified_types_UpdateNewEncryptedMessage';
|
|
45
|
+
this.className = 'UpdateSecretChatMessage';
|
|
46
|
+
this.constructorId = 1;
|
|
47
|
+
this.subclassOfId = 0x9f89304e;
|
|
48
|
+
this._slots = ['message', 'qts'];
|
|
49
|
+
this.message = params.message;
|
|
50
|
+
this.qts = params.qts;
|
|
51
|
+
this._original = params.original;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Decrypts a raw encrypted update and generates a fully decrypted `UpdateSecretChatMessage` wrapper.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* This static factory determines whether the encrypted message is a standard user message or
|
|
58
|
+
* a service message (e.g. key exchange requests), calls `secretChat.decrypt()` to decrypt the body,
|
|
59
|
+
* constructs the appropriate wrapper class (`SecretChatMessage` or `SecretChatMessageService`),
|
|
60
|
+
* and returns the finalized update object.
|
|
61
|
+
*
|
|
62
|
+
* @typeParam T - The secret chat context class implementing {@link TypeTGenerate}.
|
|
63
|
+
* @param update - The raw `UpdateNewEncryptedMessage` containing the encrypted payload.
|
|
64
|
+
* @param secretChat - The secret chat session manager used to decrypt the message bytes.
|
|
65
|
+
* @returns A promise resolving to the decrypted `UpdateSecretChatMessage` instance.
|
|
66
|
+
*/
|
|
67
|
+
static async generate(update, secretChat) {
|
|
68
|
+
const decrypted = await secretChat.decrypt(update.message);
|
|
69
|
+
if (update.message instanceof Raw.EncryptedMessageService) {
|
|
70
|
+
return new UpdateSecretChatMessage({
|
|
71
|
+
message: new SecretChatMessageService({
|
|
72
|
+
randomId: update.message.randomId,
|
|
73
|
+
chatId: update.message.chatId,
|
|
74
|
+
date: update.message.date,
|
|
75
|
+
// @ts-ignore: TS doesn't know that decrypted is a DecryptedMessageService
|
|
76
|
+
message: decrypted,
|
|
77
|
+
}),
|
|
78
|
+
qts: update.qts,
|
|
79
|
+
original: update,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return new UpdateSecretChatMessage({
|
|
83
|
+
message: new SecretChatMessage({
|
|
84
|
+
randomId: update.message.randomId,
|
|
85
|
+
chatId: update.message.chatId,
|
|
86
|
+
date: update.message.date,
|
|
87
|
+
file: update.message.file,
|
|
88
|
+
// @ts-ignore: TS doesn't know that decrypted is a DecryptedMessage
|
|
89
|
+
message: decrypted,
|
|
90
|
+
}),
|
|
91
|
+
qts: update.qts,
|
|
92
|
+
original: update,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The original raw encrypted message container received from Telegram.
|
|
97
|
+
*
|
|
98
|
+
* @returns The raw original encrypted update object.
|
|
99
|
+
*/
|
|
100
|
+
get original() {
|
|
101
|
+
return this._original;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Represents a decrypted standard text or media message within a secret chat.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Wraps the decrypted end-to-end encrypted payload together with its local random ID, chat context,
|
|
109
|
+
* timestamp, and optional media file attachments.
|
|
110
|
+
*
|
|
111
|
+
* @extends TLObject
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const secretMessage = new SecretChatMessage({
|
|
115
|
+
* randomId: 1234567890123456789n,
|
|
116
|
+
* chatId: 42,
|
|
117
|
+
* date: 1680000000,
|
|
118
|
+
* message: decryptedMessageInstance,
|
|
119
|
+
* file: encryptedFileInstance
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export class SecretChatMessage extends TLObject {
|
|
124
|
+
/**
|
|
125
|
+
* A unique 64-bit identifier chosen by the client to prevent replay attacks.
|
|
126
|
+
*/
|
|
127
|
+
randomId;
|
|
128
|
+
/**
|
|
129
|
+
* The unique secret chat identifier.
|
|
130
|
+
*/
|
|
131
|
+
chatId;
|
|
132
|
+
/**
|
|
133
|
+
* The Unix timestamp indicating when the message was sent.
|
|
134
|
+
*/
|
|
135
|
+
date;
|
|
136
|
+
/**
|
|
137
|
+
* The decrypted inner message payload mapping to a standard version-specific schema.
|
|
138
|
+
*/
|
|
139
|
+
message;
|
|
140
|
+
/**
|
|
141
|
+
* The encrypted file attachment description associated with this message, if any.
|
|
142
|
+
*/
|
|
143
|
+
file;
|
|
144
|
+
/**
|
|
145
|
+
* Constructs a new SecretChatMessage instance.
|
|
146
|
+
*
|
|
147
|
+
* @param params - Initial parameter values.
|
|
148
|
+
*/
|
|
149
|
+
constructor(params) {
|
|
150
|
+
super();
|
|
151
|
+
this.classType = 'modified_types_EncryptedMessage';
|
|
152
|
+
this.className = 'SecretChatMessage';
|
|
153
|
+
this.constructorId = 2;
|
|
154
|
+
this.subclassOfId = 0x239f2e51;
|
|
155
|
+
this._slots = ['randomId', 'chatId', 'date', 'message', 'file'];
|
|
156
|
+
this.randomId = params.randomId;
|
|
157
|
+
this.chatId = params.chatId;
|
|
158
|
+
this.date = params.date;
|
|
159
|
+
this.message = params.message;
|
|
160
|
+
this.file = params.file;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Represents a decrypted service command message within a secret chat.
|
|
165
|
+
*
|
|
166
|
+
* @remarks
|
|
167
|
+
* Used for background negotiation signals such as typing notifications, read receipt confirmations,
|
|
168
|
+
* self-destruct changes, or encryption key exchanges.
|
|
169
|
+
*
|
|
170
|
+
* @extends TLObject
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const serviceMessage = new SecretChatMessageService({
|
|
174
|
+
* randomId: 1234567890123456789n,
|
|
175
|
+
* chatId: 42,
|
|
176
|
+
* date: 1680000000,
|
|
177
|
+
* message: decryptedMessageService8Instance
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export class SecretChatMessageService extends TLObject {
|
|
182
|
+
/**
|
|
183
|
+
* A unique 64-bit identifier chosen by the client to prevent replay attacks.
|
|
184
|
+
*/
|
|
185
|
+
randomId;
|
|
186
|
+
/**
|
|
187
|
+
* The unique secret chat identifier.
|
|
188
|
+
*/
|
|
189
|
+
chatId;
|
|
190
|
+
/**
|
|
191
|
+
* The Unix timestamp indicating when the message was sent.
|
|
192
|
+
*/
|
|
193
|
+
date;
|
|
194
|
+
/**
|
|
195
|
+
* The decrypted inner service message payload.
|
|
196
|
+
*/
|
|
197
|
+
message;
|
|
198
|
+
/**
|
|
199
|
+
* Constructs a new SecretChatMessageService instance.
|
|
200
|
+
*
|
|
201
|
+
* @param params - Initial parameter values.
|
|
202
|
+
*/
|
|
203
|
+
constructor(params) {
|
|
204
|
+
super();
|
|
205
|
+
this.classType = 'modified_types_EncryptedMessageService';
|
|
206
|
+
this.className = 'SecretChatMessageService';
|
|
207
|
+
this.constructorId = 3;
|
|
208
|
+
this.subclassOfId = 0x239f2e51;
|
|
209
|
+
this._slots = ['randomId', 'chatId', 'date', 'message'];
|
|
210
|
+
this.randomId = params.randomId;
|
|
211
|
+
this.chatId = params.chatId;
|
|
212
|
+
this.date = params.date;
|
|
213
|
+
this.message = params.message;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tgsnake - Telegram MTProto library for javascript or typescript.
|
|
3
|
+
* Copyright (C) 2026 tgsnake <https://github.com/tgsnake>
|
|
4
|
+
*
|
|
5
|
+
* THIS FILE IS PART OF TGSNAKE
|
|
6
|
+
*
|
|
7
|
+
* tgsnake is a free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the MIT License as published.
|
|
9
|
+
*/
|
|
10
|
+
import { BytesIO, Buffer } from '../../deps.js';
|
|
11
|
+
import { TLObject } from './TLObject.js';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a Gzip-compressed wrapper around another serialized TLObject payload.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Telegram MTProto automatically packages certain large responses or bulk payloads
|
|
17
|
+
* within a `gzip_packed` constructor to optimize bandwidth and network performance.
|
|
18
|
+
* This class handles the transparent zlib-based compression and decompression of these payloads.
|
|
19
|
+
*
|
|
20
|
+
* @extends TLObject
|
|
21
|
+
*/
|
|
22
|
+
export declare class GzipPacked extends TLObject {
|
|
23
|
+
/**
|
|
24
|
+
* The unique class ID identifier representing `GzipPacked` (0x3072cfa1).
|
|
25
|
+
*/
|
|
26
|
+
static ID: number;
|
|
27
|
+
/**
|
|
28
|
+
* The underlying inner deserialized TLObject that was compressed.
|
|
29
|
+
*/
|
|
30
|
+
packedData: TLObject;
|
|
31
|
+
/**
|
|
32
|
+
* Constructs a new GzipPacked instance.
|
|
33
|
+
*
|
|
34
|
+
* @param packedData - The inner uncompressed TLObject to package.
|
|
35
|
+
*/
|
|
36
|
+
constructor(packedData: TLObject);
|
|
37
|
+
/**
|
|
38
|
+
* Reads, decompresses, and deserializes a Gzip-packed payload from a binary stream.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* This method:
|
|
42
|
+
* 1. Reads the length-prefixed compressed bytes from the input stream.
|
|
43
|
+
* 2. Runs native zlib gunzip (`gunzipSync`) on the compressed data.
|
|
44
|
+
* 3. Wraps the raw uncompressed bytes inside a new `BytesIO` stream.
|
|
45
|
+
* 4. Recursively parses the decompressed buffer as a valid `TLObject`.
|
|
46
|
+
*
|
|
47
|
+
* @param data - The `BytesIO` stream containing the compressed `gzip_packed` data structure.
|
|
48
|
+
* @param _args - Unused additional parameters.
|
|
49
|
+
* @returns A promise resolving to the decompressed `GzipPacked` instance wrapping the deserialized object.
|
|
50
|
+
*/
|
|
51
|
+
static read(data: BytesIO, ..._args: Array<any>): Promise<GzipPacked>;
|
|
52
|
+
/**
|
|
53
|
+
* Serializes and zlib-compresses the inner TLObject into a raw binary buffer.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* Serializes the payload by first writing the 32-bit `GzipPacked.ID` identifier, followed by
|
|
57
|
+
* the length-prefixed zlib-compressed buffer containing the inner TLObject's binary output.
|
|
58
|
+
*
|
|
59
|
+
* @override
|
|
60
|
+
* @returns A Buffer representing the compressed MTProto binary structure.
|
|
61
|
+
*/
|
|
62
|
+
write(): Buffer;
|
|
63
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tgsnake - Telegram MTProto library for javascript or typescript.
|
|
3
|
+
* Copyright (C) 2026 tgsnake <https://github.com/tgsnake>
|
|
4
|
+
*
|
|
5
|
+
* THIS FILE IS PART OF TGSNAKE
|
|
6
|
+
*
|
|
7
|
+
* tgsnake is a free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the MIT License as published.
|
|
9
|
+
*/
|
|
10
|
+
import { BytesIO, gzipSync, gunzipSync, Buffer } from '../../deps.js';
|
|
11
|
+
import { TLObject } from './TLObject.js';
|
|
12
|
+
import * as Primitive from './primitive/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Represents a Gzip-compressed wrapper around another serialized TLObject payload.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Telegram MTProto automatically packages certain large responses or bulk payloads
|
|
18
|
+
* within a `gzip_packed` constructor to optimize bandwidth and network performance.
|
|
19
|
+
* This class handles the transparent zlib-based compression and decompression of these payloads.
|
|
20
|
+
*
|
|
21
|
+
* @extends TLObject
|
|
22
|
+
*/
|
|
23
|
+
export class GzipPacked extends TLObject {
|
|
24
|
+
/**
|
|
25
|
+
* The unique class ID identifier representing `GzipPacked` (0x3072cfa1).
|
|
26
|
+
*/
|
|
27
|
+
static ID = 0x3072cfa1;
|
|
28
|
+
/**
|
|
29
|
+
* The underlying inner deserialized TLObject that was compressed.
|
|
30
|
+
*/
|
|
31
|
+
packedData;
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new GzipPacked instance.
|
|
34
|
+
*
|
|
35
|
+
* @param packedData - The inner uncompressed TLObject to package.
|
|
36
|
+
*/
|
|
37
|
+
constructor(packedData) {
|
|
38
|
+
super();
|
|
39
|
+
this.className = 'GzipPacked';
|
|
40
|
+
this._slots = ['packedData'];
|
|
41
|
+
this.packedData = packedData;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads, decompresses, and deserializes a Gzip-packed payload from a binary stream.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* This method:
|
|
48
|
+
* 1. Reads the length-prefixed compressed bytes from the input stream.
|
|
49
|
+
* 2. Runs native zlib gunzip (`gunzipSync`) on the compressed data.
|
|
50
|
+
* 3. Wraps the raw uncompressed bytes inside a new `BytesIO` stream.
|
|
51
|
+
* 4. Recursively parses the decompressed buffer as a valid `TLObject`.
|
|
52
|
+
*
|
|
53
|
+
* @param data - The `BytesIO` stream containing the compressed `gzip_packed` data structure.
|
|
54
|
+
* @param _args - Unused additional parameters.
|
|
55
|
+
* @returns A promise resolving to the decompressed `GzipPacked` instance wrapping the deserialized object.
|
|
56
|
+
*/
|
|
57
|
+
static async read(data, ..._args) {
|
|
58
|
+
return (await TLObject.read(new BytesIO(gunzipSync(await Primitive.Bytes.read(data)))));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Serializes and zlib-compresses the inner TLObject into a raw binary buffer.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Serializes the payload by first writing the 32-bit `GzipPacked.ID` identifier, followed by
|
|
65
|
+
* the length-prefixed zlib-compressed buffer containing the inner TLObject's binary output.
|
|
66
|
+
*
|
|
67
|
+
* @override
|
|
68
|
+
* @returns A Buffer representing the compressed MTProto binary structure.
|
|
69
|
+
*/
|
|
70
|
+
write() {
|
|
71
|
+
const bytes = new BytesIO();
|
|
72
|
+
bytes.write(Primitive.Int.write(GzipPacked.ID, false));
|
|
73
|
+
bytes.write(Primitive.Bytes.write(gzipSync(this.packedData.write())));
|
|
74
|
+
return Buffer.from(bytes.buffer);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tgsnake - Telegram MTProto library for javascript or typescript.
|
|
3
|
+
* Copyright (C) 2026 tgsnake <https://github.com/tgsnake>
|
|
4
|
+
*
|
|
5
|
+
* THIS FILE IS PART OF TGSNAKE
|
|
6
|
+
*
|
|
7
|
+
* tgsnake is a free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the MIT License as published.
|
|
9
|
+
*/
|
|
10
|
+
import { TLObject } from './TLObject.js';
|
|
11
|
+
import { BytesIO, Buffer } from '../../deps.js';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a standard MTProto transport container message.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Every message transmitted or received over the MTProto protocol is wrapped in a `Message` envelope.
|
|
17
|
+
* The envelope includes metadata crucial for routing and ordering: the message ID (which indicates
|
|
18
|
+
* client/server time synchronization), the message sequence number, the body byte length, and the actual
|
|
19
|
+
* serialized payload/body TLObject.
|
|
20
|
+
*
|
|
21
|
+
* @extends TLObject
|
|
22
|
+
*/
|
|
23
|
+
export declare class Message extends TLObject {
|
|
24
|
+
/**
|
|
25
|
+
* The unique class ID identifier representing `Message` (0x5bb8e511).
|
|
26
|
+
*/
|
|
27
|
+
static ID: number;
|
|
28
|
+
/**
|
|
29
|
+
* The unique 64-bit message identifier, representing the creation time of the message in seconds multiplied by 2^32.
|
|
30
|
+
*/
|
|
31
|
+
msgId: bigint;
|
|
32
|
+
/**
|
|
33
|
+
* The message sequence number, indicating the order of the message in the session.
|
|
34
|
+
*/
|
|
35
|
+
seqNo: number;
|
|
36
|
+
/**
|
|
37
|
+
* The length of the serialized message body in bytes.
|
|
38
|
+
*/
|
|
39
|
+
length: number;
|
|
40
|
+
/**
|
|
41
|
+
* The inner body deserialized as a `TLObject`.
|
|
42
|
+
*/
|
|
43
|
+
body: TLObject;
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a new Message envelope.
|
|
46
|
+
*
|
|
47
|
+
* @param body - The inner body payload of the message.
|
|
48
|
+
* @param msgId - The 64-bit message identifier.
|
|
49
|
+
* @param seqNo - The session message sequence number.
|
|
50
|
+
* @param length - The byte length of the body.
|
|
51
|
+
*/
|
|
52
|
+
constructor(body: TLObject, msgId: bigint, seqNo: number, length: number);
|
|
53
|
+
/**
|
|
54
|
+
* Reads and deserializes a `Message` envelope from a binary stream.
|
|
55
|
+
*
|
|
56
|
+
* @param data - The `BytesIO` stream containing the serialized message envelope.
|
|
57
|
+
* @param _args - Unused additional parameters.
|
|
58
|
+
* @returns A promise resolving to the deserialized `Message` instance.
|
|
59
|
+
*/
|
|
60
|
+
static read(data: BytesIO, ..._args: Array<any>): Promise<Message>;
|
|
61
|
+
/**
|
|
62
|
+
* Serializes the message envelope and its body into a raw binary buffer.
|
|
63
|
+
*
|
|
64
|
+
* @override
|
|
65
|
+
* @returns A Buffer representing the complete message envelope structure.
|
|
66
|
+
*/
|
|
67
|
+
write(): Buffer;
|
|
68
|
+
}
|