@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.
Files changed (128) hide show
  1. package/README.md +1 -1
  2. package/esm/0_errors.d.ts.map +1 -1
  3. package/esm/0_errors.js +9 -31
  4. package/esm/3_errors.js +2 -12
  5. package/esm/4_errors.js +2 -12
  6. package/esm/_dnt.polyfills.d.ts +0 -99
  7. package/esm/_dnt.polyfills.d.ts.map +1 -1
  8. package/esm/_dnt.polyfills.js +1 -127
  9. package/esm/client/0_abortable_loop.js +26 -39
  10. package/esm/client/0_storage_operations.js +179 -218
  11. package/esm/client/1_client_plain.js +4 -22
  12. package/esm/client/2_account_manager.js +140 -149
  13. package/esm/client/2_bot_info_manager.js +26 -38
  14. package/esm/client/2_business_connection_manager.js +10 -23
  15. package/esm/client/2_client_encrypted.js +198 -215
  16. package/esm/client/2_file_manager.js +255 -262
  17. package/esm/client/2_network_statistics_manager.js +31 -44
  18. package/esm/client/2_payment_manager.js +7 -20
  19. package/esm/client/2_reaction_manager.js +7 -20
  20. package/esm/client/2_translations_manager.js +101 -111
  21. package/esm/client/2_update_manager.js +750 -745
  22. package/esm/client/3_client_encrypted_pool.js +10 -26
  23. package/esm/client/3_message_manager.js +503 -508
  24. package/esm/client/3_video_chat_manager.js +57 -68
  25. package/esm/client/4_callback_query_manager.js +18 -30
  26. package/esm/client/4_chat_list_manager.js +140 -146
  27. package/esm/client/4_chat_manager.js +161 -169
  28. package/esm/client/4_checklist_manager.js +26 -39
  29. package/esm/client/4_context.js +244 -259
  30. package/esm/client/4_forum_manager.js +67 -73
  31. package/esm/client/4_gift_manager.js +22 -35
  32. package/esm/client/4_inline_query_manager.js +16 -28
  33. package/esm/client/4_link_preview_manager.js +6 -19
  34. package/esm/client/4_poll_manager.js +44 -57
  35. package/esm/client/4_story_manager.js +41 -53
  36. package/esm/client/5_composer.js +13 -26
  37. package/esm/client/6_client.js +866 -896
  38. package/esm/client/6_client_dispatcher.js +308 -325
  39. package/esm/client/7_client_worker.js +16 -29
  40. package/esm/connection/1_connection_tcp.js +55 -82
  41. package/esm/connection/1_connection_web_socket.js +75 -91
  42. package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  43. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  44. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  45. package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  46. package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  47. package/esm/session/0_session_state.js +12 -38
  48. package/esm/session/1_session.js +49 -72
  49. package/esm/session/2_session_encrypted.js +422 -420
  50. package/esm/storage/2_storage_indexed_db.js +26 -44
  51. package/esm/storage/2_storage_local_storage.js +3 -16
  52. package/esm/storage/2_storage_memory.js +24 -41
  53. package/esm/storage/2_storage_session_storage.js +3 -16
  54. package/esm/tl/1_tl_reader.d.ts +1 -1
  55. package/esm/tl/1_tl_reader.d.ts.map +1 -1
  56. package/esm/tl/1_tl_reader.js +95 -103
  57. package/esm/tl/1_tl_writer.js +169 -178
  58. package/esm/transport/0_transport.js +1 -8
  59. package/esm/transport/1_transport_abridged.js +11 -24
  60. package/esm/transport/1_transport_intermediate.js +10 -23
  61. package/esm/utilities/0_mutex.js +4 -19
  62. package/esm/utilities/0_part_stream.js +11 -25
  63. package/esm/utilities/1_crypto.js +42 -53
  64. package/esm/utilities/2_queue.js +29 -47
  65. package/package.json +1 -1
  66. package/script/0_errors.d.ts.map +1 -1
  67. package/script/0_errors.js +9 -31
  68. package/script/3_errors.js +2 -12
  69. package/script/4_errors.js +2 -12
  70. package/script/_dnt.polyfills.d.ts +0 -99
  71. package/script/_dnt.polyfills.d.ts.map +1 -1
  72. package/script/_dnt.polyfills.js +0 -128
  73. package/script/client/0_abortable_loop.js +27 -40
  74. package/script/client/0_storage_operations.js +179 -218
  75. package/script/client/1_client_plain.js +4 -22
  76. package/script/client/2_account_manager.js +140 -149
  77. package/script/client/2_bot_info_manager.js +26 -38
  78. package/script/client/2_business_connection_manager.js +10 -23
  79. package/script/client/2_client_encrypted.js +199 -216
  80. package/script/client/2_file_manager.js +255 -262
  81. package/script/client/2_network_statistics_manager.js +32 -45
  82. package/script/client/2_payment_manager.js +7 -20
  83. package/script/client/2_reaction_manager.js +7 -20
  84. package/script/client/2_translations_manager.js +102 -112
  85. package/script/client/2_update_manager.js +750 -745
  86. package/script/client/3_client_encrypted_pool.js +10 -26
  87. package/script/client/3_message_manager.js +503 -508
  88. package/script/client/3_video_chat_manager.js +57 -68
  89. package/script/client/4_callback_query_manager.js +18 -30
  90. package/script/client/4_chat_list_manager.js +140 -146
  91. package/script/client/4_chat_manager.js +161 -169
  92. package/script/client/4_checklist_manager.js +26 -39
  93. package/script/client/4_context.js +244 -259
  94. package/script/client/4_forum_manager.js +67 -73
  95. package/script/client/4_gift_manager.js +22 -35
  96. package/script/client/4_inline_query_manager.js +16 -28
  97. package/script/client/4_link_preview_manager.js +6 -19
  98. package/script/client/4_poll_manager.js +44 -57
  99. package/script/client/4_story_manager.js +41 -53
  100. package/script/client/5_composer.js +13 -26
  101. package/script/client/6_client.js +866 -896
  102. package/script/client/6_client_dispatcher.js +308 -325
  103. package/script/client/7_client_worker.js +16 -29
  104. package/script/connection/1_connection_tcp.js +55 -82
  105. package/script/connection/1_connection_web_socket.js +75 -91
  106. package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
  107. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
  108. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
  109. package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
  110. package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
  111. package/script/session/0_session_state.js +12 -38
  112. package/script/session/1_session.js +49 -72
  113. package/script/session/2_session_encrypted.js +423 -421
  114. package/script/storage/2_storage_indexed_db.js +26 -44
  115. package/script/storage/2_storage_local_storage.js +3 -16
  116. package/script/storage/2_storage_memory.js +24 -41
  117. package/script/storage/2_storage_session_storage.js +3 -16
  118. package/script/tl/1_tl_reader.d.ts +1 -1
  119. package/script/tl/1_tl_reader.d.ts.map +1 -1
  120. package/script/tl/1_tl_reader.js +96 -104
  121. package/script/tl/1_tl_writer.js +170 -179
  122. package/script/transport/0_transport.js +1 -8
  123. package/script/transport/1_transport_abridged.js +11 -24
  124. package/script/transport/1_transport_intermediate.js +10 -23
  125. package/script/utilities/0_mutex.js +4 -19
  126. package/script/utilities/0_part_stream.js +11 -25
  127. package/script/utilities/1_crypto.js +43 -54
  128. package/script/utilities/2_queue.js +30 -48
@@ -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: __classPrivateFieldGet(this, _TLWriter_path, "f") }));
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: __classPrivateFieldGet(this, _TLWriter_path, "f") }));
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: __classPrivateFieldGet(this, _TLWriter_path, "f") }));
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: __classPrivateFieldGet(this, _TLWriter_path, "f") }));
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: __classPrivateFieldGet(this, _TLWriter_path, "f") }));
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
- __classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, value._, value, schema);
87
+ this.#serialize(value._, value, schema);
100
88
  return this;
101
89
  }
102
- }
103
- _TLWriter_path = new WeakMap(), _TLWriter_instances = new WeakSet(), _TLWriter_serialize = function _TLWriter_serialize(type, value, schema) {
104
- if (__classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serializePrimitive).call(this, type, value)) {
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
- let flags = 0;
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 pathElement = `[${value._}.]${name}`;
142
- if (isFirstPathElementExisting) {
143
- __classPrivateFieldGet(this, _TLWriter_path, "f")[__classPrivateFieldGet(this, _TLWriter_path, "f").length - 1] = pathElement;
97
+ const maybeDefinition = schema.definitions[value._];
98
+ if (!maybeDefinition) {
99
+ throw new TLError(`Unknown constructor: ${value._}`, this.#path);
144
100
  }
145
- else {
146
- __classPrivateFieldGet(this, _TLWriter_path, "f").push(pathElement);
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
- if (type__[name] === undefined && !isOptionalParam(type)) {
150
- throw new TLError("Missing required field", __classPrivateFieldGet(this, _TLWriter_path, "f"));
151
- }
152
- if (isOptionalParam(type)) {
153
- type = getOptionalParamInnerType(type);
154
- }
155
- __classPrivateFieldGet(this, _TLWriter_instances, "m", _TLWriter_serialize).call(this, type, type__[name], schema);
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
- else {
180
- throw new TLError(`Expected Uint8Array but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
181
- }
182
- return true;
183
- case "int128":
184
- if (typeof value === "bigint") {
185
- this.writeInt128(value);
186
- }
187
- else {
188
- throw new TLError(`Expected bigint but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
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
- return true;
191
- case "int256":
192
- if (typeof value === "bigint") {
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
- throw new TLError(`Expected bigint but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
133
+ this.#path.push(pathElement);
134
+ isFirstPathElementExisting = true;
197
135
  }
198
- return true;
199
- case "long":
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
- else {
204
- throw new TLError(`Expected bigint but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
139
+ if (isOptionalParam(type)) {
140
+ type = getOptionalParamInnerType(type);
205
141
  }
206
- return true;
207
- case "Bool":
208
- if (typeof value === "boolean") {
209
- if (value) {
210
- this.writeInt32(BOOL_TRUE);
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.writeInt32(BOOL_FALSE);
169
+ throw new TLError(`Expected Uint8Array but received ${valueRepr}`, this.#path);
214
170
  }
215
- }
216
- else {
217
- throw new TLError(`Expected boolean but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
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("Expected an integer value but received a floating point", __classPrivateFieldGet(this, _TLWriter_path, "f"));
177
+ throw new TLError(`Expected bigint but received ${valueRepr}`, this.#path);
232
178
  }
233
- }
234
- else {
235
- throw new TLError(`Expected number but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
236
- }
237
- return true;
238
- case "double":
239
- //
240
- if (value === null) {
241
- value = 0;
242
- }
243
- //
244
- if (typeof value === "number") {
245
- this.writeDouble(value);
246
- }
247
- else {
248
- throw new TLError(`Expected number but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
249
- }
250
- return true;
251
- case "string":
252
- if (typeof value === "string") {
253
- this.writeString(value);
254
- }
255
- else if (value instanceof Uint8Array) {
256
- this.writeBytes(value);
257
- }
258
- else {
259
- this.writeString("");
260
- }
261
- // else {
262
- // throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
263
- // }
264
- return true;
265
- case "true":
266
- if (value !== true) {
267
- throw new TLError(`Expected \`true\` but received ${valueRepr}`, __classPrivateFieldGet(this, _TLWriter_path, "f"));
268
- }
269
- return true;
270
- default:
271
- return false;
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
- }, _TLWriter_isTypeValid = function _TLWriter_isTypeValid(type, value, schema) {
274
- if (type === value._) {
275
- return true;
263
+ #isTypeValid(type, value, schema) {
264
+ if (type === value._) {
265
+ return true;
266
+ }
267
+ return schema.definitions[value._]?.[2] === type;
276
268
  }
277
- return schema.definitions[value._]?.[2] === type;
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
- constructor() {
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
- _TransportAbridged_connection.set(this, void 0);
40
- _TransportAbridged_obfuscated.set(this, void 0);
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 (__classPrivateFieldGet(this, _TransportAbridged_obfuscated, "f")) {
46
- this.obfuscationParameters = await getObfuscationParameters(0xEFEFEFEF, __classPrivateFieldGet(this, _TransportAbridged_connection, "f"));
33
+ if (this.#obfuscated) {
34
+ this.obfuscationParameters = await getObfuscationParameters(0xEFEFEFEF, this.#connection);
47
35
  }
48
36
  else {
49
- await __classPrivateFieldGet(this, _TransportAbridged_connection, "f").write(new Uint8Array([0xEF]));
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 __classPrivateFieldGet(this, _TransportAbridged_connection, "f").read(buffer);
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 __classPrivateFieldGet(this, _TransportAbridged_connection, "f").read(buffer);
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 __classPrivateFieldGet(this, _TransportAbridged_connection, "f").read(buffer);
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 __classPrivateFieldGet(this, _TransportAbridged_connection, "f").write(await this.encrypt(data));
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
- _TransportIntermediate_connection.set(this, void 0);
40
- _TransportIntermediate_obfuscated.set(this, void 0);
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 (__classPrivateFieldGet(this, _TransportIntermediate_obfuscated, "f")) {
46
- this.obfuscationParameters = await getObfuscationParameters(0xEEEEEEEE, __classPrivateFieldGet(this, _TransportIntermediate_connection, "f"));
33
+ if (this.#obfuscated) {
34
+ this.obfuscationParameters = await getObfuscationParameters(0xEEEEEEEE, this.#connection);
47
35
  }
48
36
  else {
49
- await __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
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 __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").read(buffer);
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 __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").read(buffer);
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 __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").write(await this.encrypt(data));
56
+ await this.#connection.write(await this.encrypt(data));
69
57
  }
70
58
  }
71
- _TransportIntermediate_connection = new WeakMap(), _TransportIntermediate_obfuscated = new WeakMap();
@@ -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
- constructor() {
34
- _Mutex_untilUnlock.set(this, Promise.resolve());
35
- }
21
+ #untilUnlock = Promise.resolve();
36
22
  async lock() {
37
- await __classPrivateFieldGet(this, _Mutex_untilUnlock, "f");
23
+ await this.#untilUnlock;
38
24
  return new Promise((resolve0) => {
39
- __classPrivateFieldSet(this, _Mutex_untilUnlock, new Promise((resolve1) => {
25
+ this.#untilUnlock = new Promise((resolve1) => {
40
26
  resolve0(resolve1);
41
- }), "f");
27
+ });
42
28
  });
43
29
  }
44
30
  }
45
- _Mutex_untilUnlock = new WeakMap();