@mtkruto/browser 0.119.0 → 0.120.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/README.md +1 -1
- 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/script/tl/1_tl_writer.js
CHANGED
|
@@ -19,12 +19,6 @@
|
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
21
|
// deno-lint-ignore-file no-explicit-any
|
|
22
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
24
|
-
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");
|
|
25
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
26
|
-
};
|
|
27
|
-
var _TLWriter_instances, _TLWriter_path, _TLWriter_serialize, _TLWriter_serializeVector, _TLWriter_serializePrimitive, _TLWriter_isTypeValid;
|
|
28
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
23
|
exports.TLWriter = void 0;
|
|
30
24
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -33,15 +27,9 @@ const _0_utilities_js_1 = require("./0_utilities.js");
|
|
|
33
27
|
const _0_int_js_1 = require("../utilities/0_int.js");
|
|
34
28
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
35
29
|
class TLWriter {
|
|
30
|
+
_buffer = new Uint8Array();
|
|
31
|
+
#path = new Array();
|
|
36
32
|
constructor() {
|
|
37
|
-
_TLWriter_instances.add(this);
|
|
38
|
-
Object.defineProperty(this, "_buffer", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: new Uint8Array()
|
|
43
|
-
});
|
|
44
|
-
_TLWriter_path.set(this, new Array());
|
|
45
33
|
}
|
|
46
34
|
get buffer() {
|
|
47
35
|
return this._buffer;
|
|
@@ -51,15 +39,15 @@ class TLWriter {
|
|
|
51
39
|
return this;
|
|
52
40
|
}
|
|
53
41
|
writeInt24(int, isSigned = true) {
|
|
54
|
-
this.write((0, _0_int_js_1.intToBytes)(int, 24 / 8, { isSigned, path:
|
|
42
|
+
this.write((0, _0_int_js_1.intToBytes)(int, 24 / 8, { isSigned, path: this.#path }));
|
|
55
43
|
return this;
|
|
56
44
|
}
|
|
57
45
|
writeInt32(int, isSigned = true) {
|
|
58
|
-
this.write((0, _0_int_js_1.intToBytes)(int, 32 / 8, { isSigned, path:
|
|
46
|
+
this.write((0, _0_int_js_1.intToBytes)(int, 32 / 8, { isSigned, path: this.#path }));
|
|
59
47
|
return this;
|
|
60
48
|
}
|
|
61
49
|
writeInt64(int, isSigned = true) {
|
|
62
|
-
this.write((0, _0_int_js_1.intToBytes)(int, 64 / 8, { isSigned, path:
|
|
50
|
+
this.write((0, _0_int_js_1.intToBytes)(int, 64 / 8, { isSigned, path: this.#path }));
|
|
63
51
|
return this;
|
|
64
52
|
}
|
|
65
53
|
writeDouble(double) {
|
|
@@ -69,11 +57,11 @@ class TLWriter {
|
|
|
69
57
|
return this;
|
|
70
58
|
}
|
|
71
59
|
writeInt128(int, isSigned = true) {
|
|
72
|
-
this.write((0, _0_int_js_1.intToBytes)(int, 128 / 8, { isSigned, path:
|
|
60
|
+
this.write((0, _0_int_js_1.intToBytes)(int, 128 / 8, { isSigned, path: this.#path }));
|
|
73
61
|
return this;
|
|
74
62
|
}
|
|
75
63
|
writeInt256(int, isSigned = true) {
|
|
76
|
-
this.write((0, _0_int_js_1.intToBytes)(int, 256 / 8, { isSigned, path:
|
|
64
|
+
this.write((0, _0_int_js_1.intToBytes)(int, 256 / 8, { isSigned, path: this.#path }));
|
|
77
65
|
return this;
|
|
78
66
|
}
|
|
79
67
|
writeBytes(bytes) {
|
|
@@ -99,184 +87,187 @@ class TLWriter {
|
|
|
99
87
|
return this;
|
|
100
88
|
}
|
|
101
89
|
writeObject(value, schema) {
|
|
102
|
-
|
|
90
|
+
this.#serialize(value._, value, schema);
|
|
103
91
|
return this;
|
|
104
92
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializePrimitive).call(this, type, value)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializeVector).call(this, type, value, schema)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const maybeDefinition = schema.definitions[value._];
|
|
115
|
-
if (!maybeDefinition) {
|
|
116
|
-
throw new _0_errors_js_1.TLError(`Unknown constructor: ${value._}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
117
|
-
}
|
|
118
|
-
if (type !== "!X" && !__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_isTypeValid).call(this, type, value, schema)) {
|
|
119
|
-
throw new _0_errors_js_1.TLError(`Expected ${type} but instead got ${value._}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
120
|
-
}
|
|
121
|
-
const type__ = value;
|
|
122
|
-
const [id, parameters_] = maybeDefinition;
|
|
123
|
-
this.writeInt32(id, false);
|
|
124
|
-
let isFirstPathElementExisting = false;
|
|
125
|
-
for (let [name, type] of parameters_.values()) {
|
|
126
|
-
if ((0, _0_utilities_js_1.isOptionalParam)(type) && type__[name] === undefined) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (type === "#") {
|
|
130
|
-
let flags = 0;
|
|
131
|
-
const flagField_ = name;
|
|
132
|
-
for (const [name, type] of parameters_) {
|
|
133
|
-
if ((0, _0_utilities_js_1.isOptionalParam)(type)) {
|
|
134
|
-
const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(type);
|
|
135
|
-
if (flagField === flagField_) {
|
|
136
|
-
if (type__[name] !== undefined) {
|
|
137
|
-
flags |= 1 << bitIndex;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
this.writeInt32(flags);
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
const pathElement = `[${value._}.]${name}`;
|
|
146
|
-
if (isFirstPathElementExisting) {
|
|
147
|
-
__classPrivateFieldGet(this, _TLWriter_path, "f")[__classPrivateFieldGet(this, _TLWriter_path, "f").length - 1] = pathElement;
|
|
93
|
+
#serialize(type, value, schema) {
|
|
94
|
+
if (this.#serializePrimitive(type, value)) {
|
|
95
|
+
return;
|
|
148
96
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
isFirstPathElementExisting = true;
|
|
97
|
+
if (this.#serializeVector(type, value, schema)) {
|
|
98
|
+
return;
|
|
152
99
|
}
|
|
153
|
-
|
|
154
|
-
|
|
100
|
+
const maybeDefinition = schema.definitions[value._];
|
|
101
|
+
if (!maybeDefinition) {
|
|
102
|
+
throw new _0_errors_js_1.TLError(`Unknown constructor: ${value._}`, this.#path);
|
|
155
103
|
}
|
|
156
|
-
if ((
|
|
157
|
-
|
|
104
|
+
if (type !== "!X" && !this.#isTypeValid(type, value, schema)) {
|
|
105
|
+
throw new _0_errors_js_1.TLError(`Expected ${type} but instead got ${value._}`, this.#path);
|
|
158
106
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
if (!Array.isArray(value)) {
|
|
168
|
-
throw new _0_errors_js_1.TLError(`Expected an array but received ${(0, _0_utilities_js_1.repr)(value)}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
169
|
-
}
|
|
170
|
-
this.writeInt32(_0_utilities_js_1.VECTOR, false);
|
|
171
|
-
this.writeInt32(value.length);
|
|
172
|
-
for (const item of value) {
|
|
173
|
-
__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, itemType, item, schema);
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
}, _TLWriter_serializePrimitive = function _TLWriter_serializePrimitive(type, value) {
|
|
177
|
-
const valueRepr = (0, _0_utilities_js_1.repr)(value);
|
|
178
|
-
switch (type) {
|
|
179
|
-
case "bytes":
|
|
180
|
-
if ((value instanceof Uint8Array)) {
|
|
181
|
-
this.writeBytes(value);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
throw new _0_errors_js_1.TLError(`Expected Uint8Array but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
|
|
107
|
+
const type__ = value;
|
|
108
|
+
const [id, parameters_] = maybeDefinition;
|
|
109
|
+
this.writeInt32(id, false);
|
|
110
|
+
let isFirstPathElementExisting = false;
|
|
111
|
+
for (let [name, type] of parameters_.values()) {
|
|
112
|
+
if ((0, _0_utilities_js_1.isOptionalParam)(type) && type__[name] === undefined) {
|
|
113
|
+
continue;
|
|
185
114
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
115
|
+
if (type === "#") {
|
|
116
|
+
let flags = 0;
|
|
117
|
+
const flagField_ = name;
|
|
118
|
+
for (const [name, type] of parameters_) {
|
|
119
|
+
if ((0, _0_utilities_js_1.isOptionalParam)(type)) {
|
|
120
|
+
const { flagField, bitIndex } = (0, _0_utilities_js_1.analyzeOptionalParam)(type);
|
|
121
|
+
if (flagField === flagField_) {
|
|
122
|
+
if (type__[name] !== undefined) {
|
|
123
|
+
flags |= 1 << bitIndex;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this.writeInt32(flags);
|
|
129
|
+
continue;
|
|
193
130
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.writeInt256(value);
|
|
131
|
+
const pathElement = `[${value._}.]${name}`;
|
|
132
|
+
if (isFirstPathElementExisting) {
|
|
133
|
+
this.#path[this.#path.length - 1] = pathElement;
|
|
198
134
|
}
|
|
199
135
|
else {
|
|
200
|
-
|
|
136
|
+
this.#path.push(pathElement);
|
|
137
|
+
isFirstPathElementExisting = true;
|
|
201
138
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (typeof value === "bigint") {
|
|
205
|
-
this.writeInt64(value);
|
|
139
|
+
if (type__[name] === undefined && !(0, _0_utilities_js_1.isOptionalParam)(type)) {
|
|
140
|
+
throw new _0_errors_js_1.TLError("Missing required field", this.#path);
|
|
206
141
|
}
|
|
207
|
-
|
|
208
|
-
|
|
142
|
+
if ((0, _0_utilities_js_1.isOptionalParam)(type)) {
|
|
143
|
+
type = (0, _0_utilities_js_1.getOptionalParamInnerType)(type);
|
|
209
144
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
145
|
+
this.#serialize(type, type__[name], schema);
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
#serializeVector(type, value, schema) {
|
|
150
|
+
const itemType = (0, _0_utilities_js_1.getVectorItemType)(type);
|
|
151
|
+
if (!itemType) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (!Array.isArray(value)) {
|
|
155
|
+
throw new _0_errors_js_1.TLError(`Expected an array but received ${(0, _0_utilities_js_1.repr)(value)}`, this.#path);
|
|
156
|
+
}
|
|
157
|
+
this.writeInt32(_0_utilities_js_1.VECTOR, false);
|
|
158
|
+
this.writeInt32(value.length);
|
|
159
|
+
for (const item of value) {
|
|
160
|
+
this.#serialize(itemType, item, schema);
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
#serializePrimitive(type, value) {
|
|
165
|
+
const valueRepr = (0, _0_utilities_js_1.repr)(value);
|
|
166
|
+
switch (type) {
|
|
167
|
+
case "bytes":
|
|
168
|
+
if ((value instanceof Uint8Array)) {
|
|
169
|
+
this.writeBytes(value);
|
|
215
170
|
}
|
|
216
171
|
else {
|
|
217
|
-
|
|
172
|
+
throw new _0_errors_js_1.TLError(`Expected Uint8Array but received ${valueRepr}`, this.#path);
|
|
218
173
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return true;
|
|
224
|
-
case "int":
|
|
225
|
-
//
|
|
226
|
-
if (value === null) {
|
|
227
|
-
value = 0;
|
|
228
|
-
}
|
|
229
|
-
//
|
|
230
|
-
if (typeof value === "number") {
|
|
231
|
-
if (value % 1 === 0) {
|
|
232
|
-
this.writeInt32(value);
|
|
174
|
+
return true;
|
|
175
|
+
case "int128":
|
|
176
|
+
if (typeof value === "bigint") {
|
|
177
|
+
this.writeInt128(value);
|
|
233
178
|
}
|
|
234
179
|
else {
|
|
235
|
-
throw new _0_errors_js_1.TLError(
|
|
180
|
+
throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
236
181
|
}
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
182
|
+
return true;
|
|
183
|
+
case "int256":
|
|
184
|
+
if (typeof value === "bigint") {
|
|
185
|
+
this.writeInt256(value);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
case "long":
|
|
192
|
+
if (typeof value === "bigint") {
|
|
193
|
+
this.writeInt64(value);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
throw new _0_errors_js_1.TLError(`Expected bigint but received ${valueRepr}`, this.#path);
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
case "Bool":
|
|
200
|
+
if (typeof value === "boolean") {
|
|
201
|
+
if (value) {
|
|
202
|
+
this.writeInt32(_0_utilities_js_1.BOOL_TRUE);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
this.writeInt32(_0_utilities_js_1.BOOL_FALSE);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw new _0_errors_js_1.TLError(`Expected boolean but received ${valueRepr}`, this.#path);
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
case "int":
|
|
213
|
+
//
|
|
214
|
+
if (value === null) {
|
|
215
|
+
value = 0;
|
|
216
|
+
}
|
|
217
|
+
//
|
|
218
|
+
if (typeof value === "number") {
|
|
219
|
+
if (value % 1 === 0) {
|
|
220
|
+
this.writeInt32(value);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
throw new _0_errors_js_1.TLError("Expected an integer value but received a floating point", this.#path);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
throw new _0_errors_js_1.TLError(`Expected number but received ${valueRepr}`, this.#path);
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
case "double":
|
|
231
|
+
//
|
|
232
|
+
if (value === null) {
|
|
233
|
+
value = 0;
|
|
234
|
+
}
|
|
235
|
+
//
|
|
236
|
+
if (typeof value === "number") {
|
|
237
|
+
this.writeDouble(value);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
throw new _0_errors_js_1.TLError(`Expected number but received ${valueRepr}`, this.#path);
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
case "string":
|
|
244
|
+
if (typeof value === "string") {
|
|
245
|
+
this.writeString(value);
|
|
246
|
+
}
|
|
247
|
+
else if (value instanceof Uint8Array) {
|
|
248
|
+
this.writeBytes(value);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this.writeString("");
|
|
252
|
+
}
|
|
253
|
+
// else {
|
|
254
|
+
// throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
|
|
255
|
+
// }
|
|
256
|
+
return true;
|
|
257
|
+
case "true":
|
|
258
|
+
if (value !== true) {
|
|
259
|
+
throw new _0_errors_js_1.TLError(`Expected \`true\` but received ${valueRepr}`, this.#path);
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
default:
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
276
265
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
266
|
+
#isTypeValid(type, value, schema) {
|
|
267
|
+
if (type === value._) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
return schema.definitions[value._]?.[2] === type;
|
|
280
271
|
}
|
|
281
|
-
|
|
282
|
-
|
|
272
|
+
}
|
|
273
|
+
exports.TLWriter = TLWriter;
|
|
@@ -21,14 +21,7 @@
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.Transport = void 0;
|
|
23
23
|
class Transport {
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(this, "obfuscationParameters", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: null
|
|
30
|
-
});
|
|
31
|
-
}
|
|
24
|
+
obfuscationParameters = null;
|
|
32
25
|
async encrypt(buffer) {
|
|
33
26
|
if (this.obfuscationParameters) {
|
|
34
27
|
return await this.obfuscationParameters.encryptionCTR.call(buffer);
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
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");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
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");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _TransportAbridged_connection, _TransportAbridged_obfuscated;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.TransportAbridged = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -37,40 +25,40 @@ const _1_utilities_js_1 = require("../1_utilities.js");
|
|
|
37
25
|
const _0_obfuscation_js_1 = require("./0_obfuscation.js");
|
|
38
26
|
const _0_transport_js_1 = require("./0_transport.js");
|
|
39
27
|
class TransportAbridged extends _0_transport_js_1.Transport {
|
|
28
|
+
#connection;
|
|
29
|
+
#obfuscated;
|
|
40
30
|
constructor(connection, obfuscated = false) {
|
|
41
31
|
super();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
__classPrivateFieldSet(this, _TransportAbridged_connection, connection, "f");
|
|
45
|
-
__classPrivateFieldSet(this, _TransportAbridged_obfuscated, obfuscated, "f");
|
|
32
|
+
this.#connection = connection;
|
|
33
|
+
this.#obfuscated = obfuscated;
|
|
46
34
|
}
|
|
47
35
|
async initialize() {
|
|
48
|
-
if (
|
|
49
|
-
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEFEFEFEF,
|
|
36
|
+
if (this.#obfuscated) {
|
|
37
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEFEFEFEF, this.#connection);
|
|
50
38
|
}
|
|
51
39
|
else {
|
|
52
|
-
await
|
|
40
|
+
await this.#connection.write(new Uint8Array([0xEF]));
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
async receive() {
|
|
56
44
|
let length;
|
|
57
45
|
{
|
|
58
46
|
let buffer = new Uint8Array(1);
|
|
59
|
-
await
|
|
47
|
+
await this.#connection.read(buffer);
|
|
60
48
|
buffer = await this.decrypt(buffer);
|
|
61
49
|
if (buffer[0] < 0x7F) {
|
|
62
50
|
length = buffer[0];
|
|
63
51
|
}
|
|
64
52
|
else {
|
|
65
53
|
let buffer = new Uint8Array(3);
|
|
66
|
-
await
|
|
54
|
+
await this.#connection.read(buffer);
|
|
67
55
|
buffer = await this.decrypt(buffer);
|
|
68
56
|
length = Number((0, _1_utilities_js_1.intFromBytes)(buffer, { isSigned: false }));
|
|
69
57
|
}
|
|
70
58
|
}
|
|
71
59
|
length *= 4;
|
|
72
60
|
const buffer = new Uint8Array(length);
|
|
73
|
-
await
|
|
61
|
+
await this.#connection.read(buffer);
|
|
74
62
|
return await this.decrypt(buffer);
|
|
75
63
|
}
|
|
76
64
|
async send(buffer) {
|
|
@@ -78,8 +66,7 @@ class TransportAbridged extends _0_transport_js_1.Transport {
|
|
|
78
66
|
const header = new Uint8Array([bufferLength >= 0x7F ? 0x7F : bufferLength]);
|
|
79
67
|
const length = bufferLength >= 0x7F ? (0, _1_utilities_js_1.intToBytes)(bufferLength, 3, { isSigned: false }) : new Uint8Array();
|
|
80
68
|
const data = (0, _0_deps_js_1.concat)([header, length, buffer]);
|
|
81
|
-
await
|
|
69
|
+
await this.#connection.write(await this.encrypt(data));
|
|
82
70
|
}
|
|
83
71
|
}
|
|
84
72
|
exports.TransportAbridged = TransportAbridged;
|
|
85
|
-
_TransportAbridged_connection = new WeakMap(), _TransportAbridged_obfuscated = new WeakMap();
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
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");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
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");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _TransportIntermediate_connection, _TransportIntermediate_obfuscated;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.TransportIntermediate = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -37,39 +25,38 @@ const _1_utilities_js_1 = require("../1_utilities.js");
|
|
|
37
25
|
const _0_obfuscation_js_1 = require("./0_obfuscation.js");
|
|
38
26
|
const _0_transport_js_1 = require("./0_transport.js");
|
|
39
27
|
class TransportIntermediate extends _0_transport_js_1.Transport {
|
|
28
|
+
#connection;
|
|
29
|
+
#obfuscated;
|
|
40
30
|
constructor(connection, obfuscated = false) {
|
|
41
31
|
super();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
__classPrivateFieldSet(this, _TransportIntermediate_connection, connection, "f");
|
|
45
|
-
__classPrivateFieldSet(this, _TransportIntermediate_obfuscated, obfuscated, "f");
|
|
32
|
+
this.#connection = connection;
|
|
33
|
+
this.#obfuscated = obfuscated;
|
|
46
34
|
}
|
|
47
35
|
async initialize() {
|
|
48
|
-
if (
|
|
49
|
-
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEEEEEEEE,
|
|
36
|
+
if (this.#obfuscated) {
|
|
37
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEEEEEEEE, this.#connection);
|
|
50
38
|
}
|
|
51
39
|
else {
|
|
52
|
-
await
|
|
40
|
+
await this.#connection.write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
async receive() {
|
|
56
44
|
let length;
|
|
57
45
|
{
|
|
58
46
|
let buffer = new Uint8Array(4);
|
|
59
|
-
await
|
|
47
|
+
await this.#connection.read(buffer);
|
|
60
48
|
buffer = await this.decrypt(buffer);
|
|
61
49
|
const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
62
50
|
length = dataView.getUint32(0, true);
|
|
63
51
|
}
|
|
64
52
|
const buffer = new Uint8Array(length);
|
|
65
|
-
await
|
|
53
|
+
await this.#connection.read(buffer);
|
|
66
54
|
return await this.decrypt(buffer);
|
|
67
55
|
}
|
|
68
56
|
async send(buffer) {
|
|
69
57
|
const length = (0, _1_utilities_js_1.intToBytes)(buffer.length, 4);
|
|
70
58
|
const data = (0, _0_deps_js_1.concat)([length, buffer]);
|
|
71
|
-
await
|
|
59
|
+
await this.#connection.write(await this.encrypt(data));
|
|
72
60
|
}
|
|
73
61
|
}
|
|
74
62
|
exports.TransportIntermediate = TransportIntermediate;
|
|
75
|
-
_TransportIntermediate_connection = new WeakMap(), _TransportIntermediate_obfuscated = new WeakMap();
|
|
@@ -18,32 +18,17 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
27
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
-
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");
|
|
30
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
31
|
-
};
|
|
32
|
-
var _Mutex_untilUnlock;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.Mutex = void 0;
|
|
35
23
|
class Mutex {
|
|
36
|
-
|
|
37
|
-
_Mutex_untilUnlock.set(this, Promise.resolve());
|
|
38
|
-
}
|
|
24
|
+
#untilUnlock = Promise.resolve();
|
|
39
25
|
async lock() {
|
|
40
|
-
await
|
|
26
|
+
await this.#untilUnlock;
|
|
41
27
|
return new Promise((resolve0) => {
|
|
42
|
-
|
|
28
|
+
this.#untilUnlock = new Promise((resolve1) => {
|
|
43
29
|
resolve0(resolve1);
|
|
44
|
-
})
|
|
30
|
+
});
|
|
45
31
|
});
|
|
46
32
|
}
|
|
47
33
|
}
|
|
48
34
|
exports.Mutex = Mutex;
|
|
49
|
-
_Mutex_untilUnlock = new WeakMap();
|