@mtkruto/browser 0.119.0 → 0.119.1
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/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
package/esm/tl/1_tl_writer.js
CHANGED
|
@@ -18,27 +18,15 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
// deno-lint-ignore-file no-explicit-any
|
|
21
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
23
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
24
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
25
|
-
};
|
|
26
|
-
var _TLWriter_instances, _TLWriter_path, _TLWriter_serialize, _TLWriter_serializeVector, _TLWriter_serializePrimitive, _TLWriter_isTypeValid;
|
|
27
21
|
import { concat } from "../0_deps.js";
|
|
28
22
|
import { TLError } from "../0_errors.js";
|
|
29
23
|
import { analyzeOptionalParam, BOOL_FALSE, BOOL_TRUE, getOptionalParamInnerType, getVectorItemType, isOptionalParam, repr, VECTOR } from "./0_utilities.js";
|
|
30
24
|
import { intToBytes } from "../utilities/0_int.js";
|
|
31
25
|
import { encodeText } from "../1_utilities.js";
|
|
32
26
|
export class TLWriter {
|
|
27
|
+
_buffer = new Uint8Array();
|
|
28
|
+
#path = new Array();
|
|
33
29
|
constructor() {
|
|
34
|
-
_TLWriter_instances.add(this);
|
|
35
|
-
Object.defineProperty(this, "_buffer", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: new Uint8Array()
|
|
40
|
-
});
|
|
41
|
-
_TLWriter_path.set(this, new Array());
|
|
42
30
|
}
|
|
43
31
|
get buffer() {
|
|
44
32
|
return this._buffer;
|
|
@@ -48,15 +36,15 @@ export class TLWriter {
|
|
|
48
36
|
return this;
|
|
49
37
|
}
|
|
50
38
|
writeInt24(int, isSigned = true) {
|
|
51
|
-
this.write(intToBytes(int, 24 / 8, { isSigned, path:
|
|
39
|
+
this.write(intToBytes(int, 24 / 8, { isSigned, path: this.#path }));
|
|
52
40
|
return this;
|
|
53
41
|
}
|
|
54
42
|
writeInt32(int, isSigned = true) {
|
|
55
|
-
this.write(intToBytes(int, 32 / 8, { isSigned, path:
|
|
43
|
+
this.write(intToBytes(int, 32 / 8, { isSigned, path: this.#path }));
|
|
56
44
|
return this;
|
|
57
45
|
}
|
|
58
46
|
writeInt64(int, isSigned = true) {
|
|
59
|
-
this.write(intToBytes(int, 64 / 8, { isSigned, path:
|
|
47
|
+
this.write(intToBytes(int, 64 / 8, { isSigned, path: this.#path }));
|
|
60
48
|
return this;
|
|
61
49
|
}
|
|
62
50
|
writeDouble(double) {
|
|
@@ -66,11 +54,11 @@ export class TLWriter {
|
|
|
66
54
|
return this;
|
|
67
55
|
}
|
|
68
56
|
writeInt128(int, isSigned = true) {
|
|
69
|
-
this.write(intToBytes(int, 128 / 8, { isSigned, path:
|
|
57
|
+
this.write(intToBytes(int, 128 / 8, { isSigned, path: this.#path }));
|
|
70
58
|
return this;
|
|
71
59
|
}
|
|
72
60
|
writeInt256(int, isSigned = true) {
|
|
73
|
-
this.write(intToBytes(int, 256 / 8, { isSigned, path:
|
|
61
|
+
this.write(intToBytes(int, 256 / 8, { isSigned, path: this.#path }));
|
|
74
62
|
return this;
|
|
75
63
|
}
|
|
76
64
|
writeBytes(bytes) {
|
|
@@ -96,183 +84,186 @@ export class TLWriter {
|
|
|
96
84
|
return this;
|
|
97
85
|
}
|
|
98
86
|
writeObject(value, schema) {
|
|
99
|
-
|
|
87
|
+
this.#serialize(value._, value, schema);
|
|
100
88
|
return this;
|
|
101
89
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializeVector).call(this, type, value, schema)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const maybeDefinition = schema.definitions[value._];
|
|
111
|
-
if (!maybeDefinition) {
|
|
112
|
-
throw new TLError(`Unknown constructor: ${value._}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
113
|
-
}
|
|
114
|
-
if (type !== "!X" && !__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_isTypeValid).call(this, type, value, schema)) {
|
|
115
|
-
throw new TLError(`Expected ${type} but instead got ${value._}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
116
|
-
}
|
|
117
|
-
const type__ = value;
|
|
118
|
-
const [id, parameters_] = maybeDefinition;
|
|
119
|
-
this.writeInt32(id, false);
|
|
120
|
-
let isFirstPathElementExisting = false;
|
|
121
|
-
for (let [name, type] of parameters_.values()) {
|
|
122
|
-
if (isOptionalParam(type) && type__[name] === undefined) {
|
|
123
|
-
continue;
|
|
90
|
+
#serialize(type, value, schema) {
|
|
91
|
+
if (this.#serializePrimitive(type, value)) {
|
|
92
|
+
return;
|
|
124
93
|
}
|
|
125
|
-
if (type
|
|
126
|
-
|
|
127
|
-
const flagField_ = name;
|
|
128
|
-
for (const [name, type] of parameters_) {
|
|
129
|
-
if (isOptionalParam(type)) {
|
|
130
|
-
const { flagField, bitIndex } = analyzeOptionalParam(type);
|
|
131
|
-
if (flagField === flagField_) {
|
|
132
|
-
if (type__[name] !== undefined) {
|
|
133
|
-
flags |= 1 << bitIndex;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
this.writeInt32(flags);
|
|
139
|
-
continue;
|
|
94
|
+
if (this.#serializeVector(type, value, schema)) {
|
|
95
|
+
return;
|
|
140
96
|
}
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
97
|
+
const maybeDefinition = schema.definitions[value._];
|
|
98
|
+
if (!maybeDefinition) {
|
|
99
|
+
throw new TLError(`Unknown constructor: ${value._}`, this.#path);
|
|
144
100
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
isFirstPathElementExisting = true;
|
|
101
|
+
if (type !== "!X" && !this.#isTypeValid(type, value, schema)) {
|
|
102
|
+
throw new TLError(`Expected ${type} but instead got ${value._}`, this.#path);
|
|
148
103
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
return;
|
|
158
|
-
}, _TLWriter_serializeVector = function _TLWriter_serializeVector(type, value, schema) {
|
|
159
|
-
const itemType = getVectorItemType(type);
|
|
160
|
-
if (!itemType) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
if (!Array.isArray(value)) {
|
|
164
|
-
throw new TLError(`Expected an array but received ${repr(value)}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
165
|
-
}
|
|
166
|
-
this.writeInt32(VECTOR, false);
|
|
167
|
-
this.writeInt32(value.length);
|
|
168
|
-
for (const item of value) {
|
|
169
|
-
__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, itemType, item, schema);
|
|
170
|
-
}
|
|
171
|
-
return true;
|
|
172
|
-
}, _TLWriter_serializePrimitive = function _TLWriter_serializePrimitive(type, value) {
|
|
173
|
-
const valueRepr = repr(value);
|
|
174
|
-
switch (type) {
|
|
175
|
-
case "bytes":
|
|
176
|
-
if ((value instanceof Uint8Array)) {
|
|
177
|
-
this.writeBytes(value);
|
|
104
|
+
const type__ = value;
|
|
105
|
+
const [id, parameters_] = maybeDefinition;
|
|
106
|
+
this.writeInt32(id, false);
|
|
107
|
+
let isFirstPathElementExisting = false;
|
|
108
|
+
for (let [name, type] of parameters_.values()) {
|
|
109
|
+
if (isOptionalParam(type) && type__[name] === undefined) {
|
|
110
|
+
continue;
|
|
178
111
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
112
|
+
if (type === "#") {
|
|
113
|
+
let flags = 0;
|
|
114
|
+
const flagField_ = name;
|
|
115
|
+
for (const [name, type] of parameters_) {
|
|
116
|
+
if (isOptionalParam(type)) {
|
|
117
|
+
const { flagField, bitIndex } = analyzeOptionalParam(type);
|
|
118
|
+
if (flagField === flagField_) {
|
|
119
|
+
if (type__[name] !== undefined) {
|
|
120
|
+
flags |= 1 << bitIndex;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this.writeInt32(flags);
|
|
126
|
+
continue;
|
|
189
127
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.writeInt256(value);
|
|
128
|
+
const pathElement = `[${value._}.]${name}`;
|
|
129
|
+
if (isFirstPathElementExisting) {
|
|
130
|
+
this.#path[this.#path.length - 1] = pathElement;
|
|
194
131
|
}
|
|
195
132
|
else {
|
|
196
|
-
|
|
133
|
+
this.#path.push(pathElement);
|
|
134
|
+
isFirstPathElementExisting = true;
|
|
197
135
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (typeof value === "bigint") {
|
|
201
|
-
this.writeInt64(value);
|
|
136
|
+
if (type__[name] === undefined && !isOptionalParam(type)) {
|
|
137
|
+
throw new TLError("Missing required field", this.#path);
|
|
202
138
|
}
|
|
203
|
-
|
|
204
|
-
|
|
139
|
+
if (isOptionalParam(type)) {
|
|
140
|
+
type = getOptionalParamInnerType(type);
|
|
205
141
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
142
|
+
this.#serialize(type, type__[name], schema);
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
#serializeVector(type, value, schema) {
|
|
147
|
+
const itemType = getVectorItemType(type);
|
|
148
|
+
if (!itemType) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (!Array.isArray(value)) {
|
|
152
|
+
throw new TLError(`Expected an array but received ${repr(value)}`, this.#path);
|
|
153
|
+
}
|
|
154
|
+
this.writeInt32(VECTOR, false);
|
|
155
|
+
this.writeInt32(value.length);
|
|
156
|
+
for (const item of value) {
|
|
157
|
+
this.#serialize(itemType, item, schema);
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
#serializePrimitive(type, value) {
|
|
162
|
+
const valueRepr = repr(value);
|
|
163
|
+
switch (type) {
|
|
164
|
+
case "bytes":
|
|
165
|
+
if ((value instanceof Uint8Array)) {
|
|
166
|
+
this.writeBytes(value);
|
|
211
167
|
}
|
|
212
168
|
else {
|
|
213
|
-
this
|
|
169
|
+
throw new TLError(`Expected Uint8Array but received ${valueRepr}`, this.#path);
|
|
214
170
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return true;
|
|
220
|
-
case "int":
|
|
221
|
-
//
|
|
222
|
-
if (value === null) {
|
|
223
|
-
value = 0;
|
|
224
|
-
}
|
|
225
|
-
//
|
|
226
|
-
if (typeof value === "number") {
|
|
227
|
-
if (value % 1 === 0) {
|
|
228
|
-
this.writeInt32(value);
|
|
171
|
+
return true;
|
|
172
|
+
case "int128":
|
|
173
|
+
if (typeof value === "bigint") {
|
|
174
|
+
this.writeInt128(value);
|
|
229
175
|
}
|
|
230
176
|
else {
|
|
231
|
-
throw new TLError(
|
|
177
|
+
throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
232
178
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
179
|
+
return true;
|
|
180
|
+
case "int256":
|
|
181
|
+
if (typeof value === "bigint") {
|
|
182
|
+
this.writeInt256(value);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
case "long":
|
|
189
|
+
if (typeof value === "bigint") {
|
|
190
|
+
this.writeInt64(value);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
case "Bool":
|
|
197
|
+
if (typeof value === "boolean") {
|
|
198
|
+
if (value) {
|
|
199
|
+
this.writeInt32(BOOL_TRUE);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.writeInt32(BOOL_FALSE);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
throw new TLError(`Expected boolean but received ${valueRepr}`, this.#path);
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
case "int":
|
|
210
|
+
//
|
|
211
|
+
if (value === null) {
|
|
212
|
+
value = 0;
|
|
213
|
+
}
|
|
214
|
+
//
|
|
215
|
+
if (typeof value === "number") {
|
|
216
|
+
if (value % 1 === 0) {
|
|
217
|
+
this.writeInt32(value);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
throw new TLError("Expected an integer value but received a floating point", this.#path);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new TLError(`Expected number but received ${valueRepr}`, this.#path);
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
case "double":
|
|
228
|
+
//
|
|
229
|
+
if (value === null) {
|
|
230
|
+
value = 0;
|
|
231
|
+
}
|
|
232
|
+
//
|
|
233
|
+
if (typeof value === "number") {
|
|
234
|
+
this.writeDouble(value);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
throw new TLError(`Expected number but received ${valueRepr}`, this.#path);
|
|
238
|
+
}
|
|
239
|
+
return true;
|
|
240
|
+
case "string":
|
|
241
|
+
if (typeof value === "string") {
|
|
242
|
+
this.writeString(value);
|
|
243
|
+
}
|
|
244
|
+
else if (value instanceof Uint8Array) {
|
|
245
|
+
this.writeBytes(value);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.writeString("");
|
|
249
|
+
}
|
|
250
|
+
// else {
|
|
251
|
+
// throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
|
|
252
|
+
// }
|
|
253
|
+
return true;
|
|
254
|
+
case "true":
|
|
255
|
+
if (value !== true) {
|
|
256
|
+
throw new TLError(`Expected \`true\` but received ${valueRepr}`, this.#path);
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
default:
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
272
262
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
263
|
+
#isTypeValid(type, value, schema) {
|
|
264
|
+
if (type === value._) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
return schema.definitions[value._]?.[2] === type;
|
|
276
268
|
}
|
|
277
|
-
|
|
278
|
-
};
|
|
269
|
+
}
|
|
@@ -18,14 +18,7 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
export class Transport {
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(this, "obfuscationParameters", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: null
|
|
27
|
-
});
|
|
28
|
-
}
|
|
21
|
+
obfuscationParameters = null;
|
|
29
22
|
async encrypt(buffer) {
|
|
30
23
|
if (this.obfuscationParameters) {
|
|
31
24
|
return await this.obfuscationParameters.encryptionCTR.call(buffer);
|
|
@@ -17,57 +17,45 @@
|
|
|
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
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _TransportAbridged_connection, _TransportAbridged_obfuscated;
|
|
32
20
|
import { concat } from "../0_deps.js";
|
|
33
21
|
import { intFromBytes, intToBytes } from "../1_utilities.js";
|
|
34
22
|
import { getObfuscationParameters } from "./0_obfuscation.js";
|
|
35
23
|
import { Transport } from "./0_transport.js";
|
|
36
24
|
export class TransportAbridged extends Transport {
|
|
25
|
+
#connection;
|
|
26
|
+
#obfuscated;
|
|
37
27
|
constructor(connection, obfuscated = false) {
|
|
38
28
|
super();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__classPrivateFieldSet(this, _TransportAbridged_connection, connection, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _TransportAbridged_obfuscated, obfuscated, "f");
|
|
29
|
+
this.#connection = connection;
|
|
30
|
+
this.#obfuscated = obfuscated;
|
|
43
31
|
}
|
|
44
32
|
async initialize() {
|
|
45
|
-
if (
|
|
46
|
-
this.obfuscationParameters = await getObfuscationParameters(0xEFEFEFEF,
|
|
33
|
+
if (this.#obfuscated) {
|
|
34
|
+
this.obfuscationParameters = await getObfuscationParameters(0xEFEFEFEF, this.#connection);
|
|
47
35
|
}
|
|
48
36
|
else {
|
|
49
|
-
await
|
|
37
|
+
await this.#connection.write(new Uint8Array([0xEF]));
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
async receive() {
|
|
53
41
|
let length;
|
|
54
42
|
{
|
|
55
43
|
let buffer = new Uint8Array(1);
|
|
56
|
-
await
|
|
44
|
+
await this.#connection.read(buffer);
|
|
57
45
|
buffer = await this.decrypt(buffer);
|
|
58
46
|
if (buffer[0] < 0x7F) {
|
|
59
47
|
length = buffer[0];
|
|
60
48
|
}
|
|
61
49
|
else {
|
|
62
50
|
let buffer = new Uint8Array(3);
|
|
63
|
-
await
|
|
51
|
+
await this.#connection.read(buffer);
|
|
64
52
|
buffer = await this.decrypt(buffer);
|
|
65
53
|
length = Number(intFromBytes(buffer, { isSigned: false }));
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
56
|
length *= 4;
|
|
69
57
|
const buffer = new Uint8Array(length);
|
|
70
|
-
await
|
|
58
|
+
await this.#connection.read(buffer);
|
|
71
59
|
return await this.decrypt(buffer);
|
|
72
60
|
}
|
|
73
61
|
async send(buffer) {
|
|
@@ -75,7 +63,6 @@ export class TransportAbridged extends Transport {
|
|
|
75
63
|
const header = new Uint8Array([bufferLength >= 0x7F ? 0x7F : bufferLength]);
|
|
76
64
|
const length = bufferLength >= 0x7F ? intToBytes(bufferLength, 3, { isSigned: false }) : new Uint8Array();
|
|
77
65
|
const data = concat([header, length, buffer]);
|
|
78
|
-
await
|
|
66
|
+
await this.#connection.write(await this.encrypt(data));
|
|
79
67
|
}
|
|
80
68
|
}
|
|
81
|
-
_TransportAbridged_connection = new WeakMap(), _TransportAbridged_obfuscated = new WeakMap();
|
|
@@ -17,55 +17,42 @@
|
|
|
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
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
21
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
22
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
23
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
24
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
25
|
-
};
|
|
26
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
29
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
|
-
};
|
|
31
|
-
var _TransportIntermediate_connection, _TransportIntermediate_obfuscated;
|
|
32
20
|
import { concat } from "../0_deps.js";
|
|
33
21
|
import { intToBytes } from "../1_utilities.js";
|
|
34
22
|
import { getObfuscationParameters } from "./0_obfuscation.js";
|
|
35
23
|
import { Transport } from "./0_transport.js";
|
|
36
24
|
export class TransportIntermediate extends Transport {
|
|
25
|
+
#connection;
|
|
26
|
+
#obfuscated;
|
|
37
27
|
constructor(connection, obfuscated = false) {
|
|
38
28
|
super();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__classPrivateFieldSet(this, _TransportIntermediate_connection, connection, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _TransportIntermediate_obfuscated, obfuscated, "f");
|
|
29
|
+
this.#connection = connection;
|
|
30
|
+
this.#obfuscated = obfuscated;
|
|
43
31
|
}
|
|
44
32
|
async initialize() {
|
|
45
|
-
if (
|
|
46
|
-
this.obfuscationParameters = await getObfuscationParameters(0xEEEEEEEE,
|
|
33
|
+
if (this.#obfuscated) {
|
|
34
|
+
this.obfuscationParameters = await getObfuscationParameters(0xEEEEEEEE, this.#connection);
|
|
47
35
|
}
|
|
48
36
|
else {
|
|
49
|
-
await
|
|
37
|
+
await this.#connection.write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
async receive() {
|
|
53
41
|
let length;
|
|
54
42
|
{
|
|
55
43
|
let buffer = new Uint8Array(4);
|
|
56
|
-
await
|
|
44
|
+
await this.#connection.read(buffer);
|
|
57
45
|
buffer = await this.decrypt(buffer);
|
|
58
46
|
const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
59
47
|
length = dataView.getUint32(0, true);
|
|
60
48
|
}
|
|
61
49
|
const buffer = new Uint8Array(length);
|
|
62
|
-
await
|
|
50
|
+
await this.#connection.read(buffer);
|
|
63
51
|
return await this.decrypt(buffer);
|
|
64
52
|
}
|
|
65
53
|
async send(buffer) {
|
|
66
54
|
const length = intToBytes(buffer.length, 4);
|
|
67
55
|
const data = concat([length, buffer]);
|
|
68
|
-
await
|
|
56
|
+
await this.#connection.write(await this.encrypt(data));
|
|
69
57
|
}
|
|
70
58
|
}
|
|
71
|
-
_TransportIntermediate_connection = new WeakMap(), _TransportIntermediate_obfuscated = new WeakMap();
|
package/esm/utilities/0_mutex.js
CHANGED
|
@@ -17,29 +17,14 @@
|
|
|
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
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var _Mutex_untilUnlock;
|
|
32
20
|
export class Mutex {
|
|
33
|
-
|
|
34
|
-
_Mutex_untilUnlock.set(this, Promise.resolve());
|
|
35
|
-
}
|
|
21
|
+
#untilUnlock = Promise.resolve();
|
|
36
22
|
async lock() {
|
|
37
|
-
await
|
|
23
|
+
await this.#untilUnlock;
|
|
38
24
|
return new Promise((resolve0) => {
|
|
39
|
-
|
|
25
|
+
this.#untilUnlock = new Promise((resolve1) => {
|
|
40
26
|
resolve0(resolve1);
|
|
41
|
-
})
|
|
27
|
+
});
|
|
42
28
|
});
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
|
-
_Mutex_untilUnlock = new WeakMap();
|