@tgsnake/skema 1.12.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 +125 -16
- 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 +47 -5
- package/dist/{raw → src/raw}/All.js +48 -9
- package/dist/{raw → src/raw}/Raw.d.ts +17546 -9
- package/dist/{raw → src/raw}/Raw.js +44899 -21694
- 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,237 @@
|
|
|
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 { Buffer } from '../../../deps.js';
|
|
12
|
+
import { bufferToBigint as toBigint } from '../../../helpers.js';
|
|
13
|
+
/**
|
|
14
|
+
* Serializer and deserializer for standard 32-bit (4-byte) signed or unsigned integers.
|
|
15
|
+
*
|
|
16
|
+
* @extends TLObject
|
|
17
|
+
*/
|
|
18
|
+
export class Int extends TLObject {
|
|
19
|
+
/**
|
|
20
|
+
* The byte size of a standard 32-bit integer (4 bytes).
|
|
21
|
+
*/
|
|
22
|
+
static SIZE = 4;
|
|
23
|
+
/**
|
|
24
|
+
* Serializes a 32-bit integer into a Buffer.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The integer value to write (accepts `number` or `bigint`).
|
|
27
|
+
* @param signed - Set to `true` if the integer is signed; set to `false` if unsigned. Defaults to `true`.
|
|
28
|
+
* @param little - Set to `true` to write in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
29
|
+
* @returns A Buffer containing the 4-byte representation of the integer.
|
|
30
|
+
*/
|
|
31
|
+
static write(value, signed = true, little = true) {
|
|
32
|
+
const buffer = Buffer.alloc(Int.SIZE);
|
|
33
|
+
if (signed) {
|
|
34
|
+
if (little) {
|
|
35
|
+
buffer.writeInt32LE(Number(value));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
buffer.writeInt32BE(Number(value));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (little) {
|
|
43
|
+
buffer.writeUInt32LE(Number(value));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
buffer.writeUInt32BE(Number(value));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return buffer;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads and decodes a 32-bit integer from a binary stream.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The `BytesIO` stream to read the integer from.
|
|
55
|
+
* @param signed - Set to `true` to parse as a signed integer; set to `false` for unsigned. Defaults to `true`.
|
|
56
|
+
* @param little - Set to `true` to read in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
57
|
+
* @param size - The exact number of bytes to read from the stream. Defaults to `Int.SIZE`.
|
|
58
|
+
* @returns A promise resolving to the decoded number.
|
|
59
|
+
*/
|
|
60
|
+
static async read(data, signed = true, little = true, size = Int.SIZE) {
|
|
61
|
+
if (signed) {
|
|
62
|
+
if (little) {
|
|
63
|
+
return data.readInt32LE(size);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return data.readInt32BE(size);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (little) {
|
|
71
|
+
return data.readUInt32LE(size);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return data.readUInt32BE(size);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Serializer and deserializer for 64-bit (8-byte) signed or unsigned integers.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* In MTProto, 64-bit integers are heavily used for message IDs, session IDs, chat IDs,
|
|
84
|
+
* and salt values. Because standard JS numbers only support safe integers up to 53 bits,
|
|
85
|
+
* this class operates on native JavaScript `bigint` values.
|
|
86
|
+
*
|
|
87
|
+
* @extends TLObject
|
|
88
|
+
*/
|
|
89
|
+
export class Long extends TLObject {
|
|
90
|
+
/**
|
|
91
|
+
* The byte size of a 64-bit long integer (8 bytes).
|
|
92
|
+
*/
|
|
93
|
+
static SIZE = 8;
|
|
94
|
+
/**
|
|
95
|
+
* Reads and decodes a 64-bit integer from a binary stream.
|
|
96
|
+
*
|
|
97
|
+
* @param data - The `BytesIO` stream to read the long integer from.
|
|
98
|
+
* @param signed - Set to `true` to parse as a signed integer; set to `false` for unsigned. Defaults to `true`.
|
|
99
|
+
* @param little - Set to `true` to read in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
100
|
+
* @param size - The exact number of bytes to read from the stream. Defaults to `Long.SIZE`.
|
|
101
|
+
* @returns A promise resolving to the decoded native `bigint`.
|
|
102
|
+
*/
|
|
103
|
+
static async read(data, signed = true, little = true, size = Long.SIZE) {
|
|
104
|
+
if (signed) {
|
|
105
|
+
if (little) {
|
|
106
|
+
return data.readBigInt64LE(size);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return data.readBigInt64BE(size);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (little) {
|
|
114
|
+
return data.readBigUInt64LE(size);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return data.readBigUInt64BE(size);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Serializes a 64-bit integer value into a Buffer.
|
|
123
|
+
*
|
|
124
|
+
* @param value - The native `bigint` value to serialize.
|
|
125
|
+
* @param signed - Set to `true` if the integer is signed; set to `false` if unsigned. Defaults to `true`.
|
|
126
|
+
* @param little - Set to `true` to write in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
127
|
+
* @returns A Buffer containing the 8-byte representation of the 64-bit integer.
|
|
128
|
+
*/
|
|
129
|
+
static write(value, signed = true, little = true) {
|
|
130
|
+
const buffer = Buffer.alloc(Long.SIZE);
|
|
131
|
+
if (signed) {
|
|
132
|
+
if (little) {
|
|
133
|
+
buffer.writeBigInt64LE(BigInt(value));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
buffer.writeBigInt64BE(BigInt(value));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (little) {
|
|
141
|
+
buffer.writeBigUInt64LE(BigInt(value));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
buffer.writeBigUInt64BE(BigInt(value));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return buffer;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Serializer and deserializer for 128-bit (16-byte) integers.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Used in MTProto cryptographic handshakes, secure nonces, and session key generation.
|
|
155
|
+
* Operates on native JavaScript `bigint` values.
|
|
156
|
+
*
|
|
157
|
+
* @extends Long
|
|
158
|
+
*/
|
|
159
|
+
export class Int128 extends Long {
|
|
160
|
+
/**
|
|
161
|
+
* The byte size of a 128-bit integer (16 bytes).
|
|
162
|
+
*/
|
|
163
|
+
static SIZE = 16;
|
|
164
|
+
/**
|
|
165
|
+
* Reads and decodes a 128-bit integer from a binary stream.
|
|
166
|
+
*
|
|
167
|
+
* @param data - The `BytesIO` stream to read the integer from.
|
|
168
|
+
* @param signed - Set to `true` to parse as signed; set to `false` for unsigned. Defaults to `true`.
|
|
169
|
+
* @param little - Set to `true` to read in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
170
|
+
* @param size - The exact number of bytes to read from the stream. Defaults to `Int128.SIZE`.
|
|
171
|
+
* @returns A promise resolving to the decoded native `bigint`.
|
|
172
|
+
*/
|
|
173
|
+
static async read(data, signed = true, little = true, size = Int128.SIZE) {
|
|
174
|
+
return toBigint(data.read(size), little, signed);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Serializes a 128-bit integer into a Buffer.
|
|
178
|
+
*
|
|
179
|
+
* @param value - The native `bigint` to serialize.
|
|
180
|
+
* @param _signed - Unused parameter.
|
|
181
|
+
* @param _little - Unused parameter.
|
|
182
|
+
* @returns A Buffer containing the 16-byte representation of the 128-bit integer.
|
|
183
|
+
*/
|
|
184
|
+
static write(value, _signed = true, _little = true) {
|
|
185
|
+
const bytesArray = [];
|
|
186
|
+
for (let i = 0; i < Int128.SIZE; i++) {
|
|
187
|
+
let shift = value >> BigInt(Long.SIZE * i);
|
|
188
|
+
shift &= BigInt(255);
|
|
189
|
+
bytesArray[i] = Number(String(shift));
|
|
190
|
+
}
|
|
191
|
+
return Buffer.from(bytesArray);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Serializer and deserializer for 256-bit (32-byte) integers.
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* Extensively used in cryptographic tasks, DH (Diffie-Hellman) parameters, and authorization key hashing.
|
|
199
|
+
* Operates on native JavaScript `bigint` values.
|
|
200
|
+
*
|
|
201
|
+
* @extends Long
|
|
202
|
+
*/
|
|
203
|
+
export class Int256 extends Long {
|
|
204
|
+
/**
|
|
205
|
+
* The byte size of a 256-bit integer (32 bytes).
|
|
206
|
+
*/
|
|
207
|
+
static SIZE = 32;
|
|
208
|
+
/**
|
|
209
|
+
* Reads and decodes a 256-bit integer from a binary stream.
|
|
210
|
+
*
|
|
211
|
+
* @param data - The `BytesIO` stream to read the integer from.
|
|
212
|
+
* @param signed - Set to `true` to parse as signed; set to `false` for unsigned. Defaults to `true`.
|
|
213
|
+
* @param little - Set to `true` to read in little-endian format; set to `false` for big-endian. Defaults to `true`.
|
|
214
|
+
* @param size - The exact number of bytes to read from the stream. Defaults to `Int256.SIZE`.
|
|
215
|
+
* @returns A promise resolving to the decoded native `bigint`.
|
|
216
|
+
*/
|
|
217
|
+
static async read(data, signed = true, little = true, size = Int256.SIZE) {
|
|
218
|
+
return Int128.read(data, signed, little, size);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Serializes a 256-bit integer into a Buffer.
|
|
222
|
+
*
|
|
223
|
+
* @param value - The native `bigint` to serialize.
|
|
224
|
+
* @param _signed - Unused parameter.
|
|
225
|
+
* @param _little - Unused parameter.
|
|
226
|
+
* @returns A Buffer containing the 32-byte representation of the 256-bit integer.
|
|
227
|
+
*/
|
|
228
|
+
static write(value, _signed = true, _little = true) {
|
|
229
|
+
const bytesArray = [];
|
|
230
|
+
for (let i = 0; i < Int256.SIZE; i++) {
|
|
231
|
+
let shift = value >> BigInt(Long.SIZE * i);
|
|
232
|
+
shift &= BigInt(255);
|
|
233
|
+
bytesArray[i] = Number(String(shift));
|
|
234
|
+
}
|
|
235
|
+
return Buffer.from(bytesArray);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
* Serializer and deserializer for UTF-8 encoded strings.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* In MTProto, strings are treated as standard UTF-8 text and are packed/aligned using
|
|
17
|
+
* the same length-prefix and padding logic as the {@link Bytes} primitive class.
|
|
18
|
+
*
|
|
19
|
+
* @extends TLObject
|
|
20
|
+
*/
|
|
21
|
+
export declare class String extends TLObject {
|
|
22
|
+
/**
|
|
23
|
+
* Serializes a JavaScript string into a UTF-8 length-prefixed and padded Buffer.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The input string to serialize.
|
|
26
|
+
* @returns A Buffer containing the encoded string.
|
|
27
|
+
*/
|
|
28
|
+
static write(value: string): Buffer;
|
|
29
|
+
/**
|
|
30
|
+
* Reads, aligns, and decodes a UTF-8 string from a binary stream.
|
|
31
|
+
*
|
|
32
|
+
* @param data - The `BytesIO` stream containing the serialized string.
|
|
33
|
+
* @param _args - Unused additional parameters.
|
|
34
|
+
* @returns A promise resolving to the decoded native JavaScript string.
|
|
35
|
+
*/
|
|
36
|
+
static read(data: BytesIO, ..._args: Array<any>): Promise<string>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 { Buffer } from '../../../deps.js';
|
|
12
|
+
import { Bytes } from './Bytes.js';
|
|
13
|
+
/**
|
|
14
|
+
* Serializer and deserializer for UTF-8 encoded strings.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* In MTProto, strings are treated as standard UTF-8 text and are packed/aligned using
|
|
18
|
+
* the same length-prefix and padding logic as the {@link Bytes} primitive class.
|
|
19
|
+
*
|
|
20
|
+
* @extends TLObject
|
|
21
|
+
*/
|
|
22
|
+
export class String extends TLObject {
|
|
23
|
+
/**
|
|
24
|
+
* Serializes a JavaScript string into a UTF-8 length-prefixed and padded Buffer.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The input string to serialize.
|
|
27
|
+
* @returns A Buffer containing the encoded string.
|
|
28
|
+
*/
|
|
29
|
+
static write(value) {
|
|
30
|
+
return Bytes.write(Buffer.from(value, 'utf8'));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads, aligns, and decodes a UTF-8 string from a binary stream.
|
|
34
|
+
*
|
|
35
|
+
* @param data - The `BytesIO` stream containing the serialized string.
|
|
36
|
+
* @param _args - Unused additional parameters.
|
|
37
|
+
* @returns A promise resolving to the decoded native JavaScript string.
|
|
38
|
+
*/
|
|
39
|
+
static async read(data, ..._args) {
|
|
40
|
+
return (await Bytes.read(data)).toString('utf8');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
* Serializer and deserializer for generic, strongly-typed vectors (arrays) of MTProto objects.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* In MTProto, vectors can be either "boxed" (serialized with the explicit `Vector.ID` class tag prefix)
|
|
17
|
+
* or "bare" (serialized directly as an array of items without the leading class ID). This class supports both
|
|
18
|
+
* boxed serialization/deserialization and bare item parsers.
|
|
19
|
+
*
|
|
20
|
+
* @extends TLObject
|
|
21
|
+
*/
|
|
22
|
+
export declare class Vector extends TLObject {
|
|
23
|
+
/**
|
|
24
|
+
* The unique class ID identifier representing `Vector` (0x1cb5c415).
|
|
25
|
+
*/
|
|
26
|
+
static ID: number;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes an array of values into an MTProto-boxed vector Buffer.
|
|
29
|
+
*
|
|
30
|
+
* @param value - The array of elements to serialize.
|
|
31
|
+
* @param tl - An optional custom type layer descriptor supplying a dedicated elements `write` method.
|
|
32
|
+
* @returns A Buffer containing the boxed vector bytes.
|
|
33
|
+
*/
|
|
34
|
+
static write(value: Array<any>, tl?: any): Buffer;
|
|
35
|
+
/**
|
|
36
|
+
* Helper deserializer reading a single "bare" item from a stream based on a calculated element byte size.
|
|
37
|
+
*
|
|
38
|
+
* @param data - The `BytesIO` stream to read from.
|
|
39
|
+
* @param size - The precalculated byte size of a single element.
|
|
40
|
+
* @returns A promise resolving to the parsed element.
|
|
41
|
+
*/
|
|
42
|
+
static readBare(data: BytesIO, size: number): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* Reads, unpacks, and deserializes a strongly-typed boxed vector from a binary stream.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* This method first extracts the element count. If a specialized element parser (`tl`) is provided,
|
|
48
|
+
* it uses it. Otherwise, it calculates the average element byte size dynamically using the remaining
|
|
49
|
+
* buffer capacity and delegates bare item parsing to {@link readBare}.
|
|
50
|
+
*
|
|
51
|
+
* @param data - The `BytesIO` stream containing the serialized vector.
|
|
52
|
+
* @param tl - An optional custom type layer descriptor supplying a dedicated elements `read` method.
|
|
53
|
+
* @returns A promise resolving to an array of parsed elements.
|
|
54
|
+
*/
|
|
55
|
+
static read(data: BytesIO, tl?: any): Promise<Array<any>>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
import { Int, Long } from './index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Serializer and deserializer for generic, strongly-typed vectors (arrays) of MTProto objects.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* In MTProto, vectors can be either "boxed" (serialized with the explicit `Vector.ID` class tag prefix)
|
|
18
|
+
* or "bare" (serialized directly as an array of items without the leading class ID). This class supports both
|
|
19
|
+
* boxed serialization/deserialization and bare item parsers.
|
|
20
|
+
*
|
|
21
|
+
* @extends TLObject
|
|
22
|
+
*/
|
|
23
|
+
export class Vector extends TLObject {
|
|
24
|
+
/**
|
|
25
|
+
* The unique class ID identifier representing `Vector` (0x1cb5c415).
|
|
26
|
+
*/
|
|
27
|
+
static ID = 0x1cb5c415;
|
|
28
|
+
/**
|
|
29
|
+
* Serializes an array of values into an MTProto-boxed vector Buffer.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The array of elements to serialize.
|
|
32
|
+
* @param tl - An optional custom type layer descriptor supplying a dedicated elements `write` method.
|
|
33
|
+
* @returns A Buffer containing the boxed vector bytes.
|
|
34
|
+
*/
|
|
35
|
+
static write(value, tl) {
|
|
36
|
+
const bytes = new BytesIO();
|
|
37
|
+
bytes.write(Int.write(Vector.ID, false));
|
|
38
|
+
bytes.write(Int.write(value.length));
|
|
39
|
+
for (const i of value) {
|
|
40
|
+
if (tl) {
|
|
41
|
+
bytes.write(tl.write(i));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
bytes.write(i.write());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return Buffer.from(bytes.buffer);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Helper deserializer reading a single "bare" item from a stream based on a calculated element byte size.
|
|
51
|
+
*
|
|
52
|
+
* @param data - The `BytesIO` stream to read from.
|
|
53
|
+
* @param size - The precalculated byte size of a single element.
|
|
54
|
+
* @returns A promise resolving to the parsed element.
|
|
55
|
+
*/
|
|
56
|
+
static async readBare(data, size) {
|
|
57
|
+
if (size === 4) {
|
|
58
|
+
return await Int.read(data);
|
|
59
|
+
}
|
|
60
|
+
if (size === 8) {
|
|
61
|
+
return await Long.read(data);
|
|
62
|
+
}
|
|
63
|
+
return await TLObject.read(data);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads, unpacks, and deserializes a strongly-typed boxed vector from a binary stream.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This method first extracts the element count. If a specialized element parser (`tl`) is provided,
|
|
70
|
+
* it uses it. Otherwise, it calculates the average element byte size dynamically using the remaining
|
|
71
|
+
* buffer capacity and delegates bare item parsing to {@link readBare}.
|
|
72
|
+
*
|
|
73
|
+
* @param data - The `BytesIO` stream containing the serialized vector.
|
|
74
|
+
* @param tl - An optional custom type layer descriptor supplying a dedicated elements `read` method.
|
|
75
|
+
* @returns A promise resolving to an array of parsed elements.
|
|
76
|
+
*/
|
|
77
|
+
static async read(data, tl) {
|
|
78
|
+
const results = [];
|
|
79
|
+
const count = await Int.read(data);
|
|
80
|
+
const left = Buffer.byteLength(data.read());
|
|
81
|
+
const size = count ? left / count : 0;
|
|
82
|
+
data.seek(-left, 1);
|
|
83
|
+
for (let i = 0; i < count; i++) {
|
|
84
|
+
if (tl) {
|
|
85
|
+
results.push(await tl.read(data));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
results.push(await Vector.readBare(data, size));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Re-exports all raw primitive encoders/decoders for MTProto integers,
|
|
12
|
+
* variable-length bytes, floats, strings, booleans, and vectors.
|
|
13
|
+
*/
|
|
14
|
+
export { Int, Long, Int128, Int256 } from './Int.js';
|
|
15
|
+
export { Bytes } from './Bytes.js';
|
|
16
|
+
export { String } from './String.js';
|
|
17
|
+
export { Bool, BoolTrue, BoolFalse } from './Bool.js';
|
|
18
|
+
export { Vector } from './Vector.js';
|
|
19
|
+
export { Double } from './Double.js';
|
|
20
|
+
export { Float } from './Float.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Re-exports all raw primitive encoders/decoders for MTProto integers,
|
|
12
|
+
* variable-length bytes, floats, strings, booleans, and vectors.
|
|
13
|
+
*/
|
|
14
|
+
export { Int, Long, Int128, Int256 } from './Int.js';
|
|
15
|
+
export { Bytes } from './Bytes.js';
|
|
16
|
+
export { String } from './String.js';
|
|
17
|
+
export { Bool, BoolTrue, BoolFalse } from './Bool.js';
|
|
18
|
+
export { Vector } from './Vector.js';
|
|
19
|
+
export { Double } from './Double.js';
|
|
20
|
+
export { Float } from './Float.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Main exports for compiled TLObjects, zlib packer, MTProto envelopes,
|
|
12
|
+
* and decrypted secret chat message containers.
|
|
13
|
+
*/
|
|
14
|
+
export { Raw } from './Raw.js';
|
|
15
|
+
export { AllTLObject } from './All.js';
|
|
16
|
+
export { Primitive, TLObject, GzipPacked, Message, MsgContainer } from './core/index.js';
|
|
17
|
+
export { SecretChatMessage, SecretChatMessageService, UpdateSecretChatMessage, TypeTGenerate, } from './UpdateSecretChat.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Main exports for compiled TLObjects, zlib packer, MTProto envelopes,
|
|
12
|
+
* and decrypted secret chat message containers.
|
|
13
|
+
*/
|
|
14
|
+
export { Raw } from './Raw.js';
|
|
15
|
+
export { AllTLObject } from './All.js';
|
|
16
|
+
export { Primitive, TLObject, GzipPacked, Message, MsgContainer } from './core/index.js';
|
|
17
|
+
export { SecretChatMessage, SecretChatMessageService, UpdateSecretChatMessage, } from './UpdateSecretChat.js';
|
package/package.json
CHANGED
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tgsnake/skema",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A compiled Telegram TL Schema and Telegram errors Schema into usable JavaScript classes with full TypeScript support",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"build
|
|
32
|
-
"build:
|
|
33
|
-
"build:
|
|
34
|
-
"build:
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@tgsnake/skema",
|
|
3
|
+
"version": "2.0.0-browser.0",
|
|
4
|
+
"description": "A compiled Telegram TL Schema and Telegram errors Schema into usable JavaScript classes with full TypeScript support",
|
|
5
|
+
"main": "dist/mod.js",
|
|
6
|
+
"types": "dist/mod.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"packageManager": "yarn@4.9.2",
|
|
9
|
+
"homepage": "https://tgsnake.js.org",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"tgsnake",
|
|
12
|
+
"mtproto",
|
|
13
|
+
"telegram"
|
|
14
|
+
],
|
|
15
|
+
"bugs": "https://github.com/tgsnake/skema/issues",
|
|
16
|
+
"repository": "https://github.com/tgsnake/skema",
|
|
17
|
+
"author": "butthx",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/**"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"engineStrict": true,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.0.0",
|
|
25
|
+
"npm": ">=6.0.0",
|
|
26
|
+
"yarn": ">=1.0.0",
|
|
27
|
+
"deno": ">=1.0.0",
|
|
28
|
+
"bun": ">=1.0.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"build:api": "node ./generator/api",
|
|
33
|
+
"build:sync": "node ./generator/sync-tl",
|
|
34
|
+
"build:error": "node ./generator/error",
|
|
35
|
+
"build:jsr": "node ./generator/jsr_version/index.js",
|
|
36
|
+
"build:docs": "typedoc --tsconfig tsconfig.json --out docs src/index.ts",
|
|
37
|
+
"prepare": "yarn build",
|
|
38
|
+
"prettier": "NODE_OPTIONS=--max_old_space_size=4096 prettier -w ."
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/bun": "^1.3.14",
|
|
42
|
+
"@types/node": "^25.9.1",
|
|
43
|
+
"prettier": "^3.8.3",
|
|
44
|
+
"typedoc": "^0.28.19",
|
|
45
|
+
"typescript": "^6.0.3"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@tgsnake/bytesio": "browser",
|
|
49
|
+
"@tgsnake/log": "browser",
|
|
50
|
+
"big-integer": "^1.6.52",
|
|
51
|
+
"browserify-zlib": "^0.2.0",
|
|
52
|
+
"buffer": "^6.0.3"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/Logger.d.ts
DELETED
package/dist/Logger.js
DELETED