@mtkruto/browser 0.1.108 → 0.1.110

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 (65) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +1 -1
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/0_html.js +26 -14
  6. package/esm/client/0_utilities.d.ts +1 -1
  7. package/esm/client/0_utilities.js +1 -2
  8. package/esm/client/1_client_abstract.d.ts +1 -1
  9. package/esm/client/1_client_abstract.js +16 -8
  10. package/esm/client/2_client_plain.d.ts +1 -2
  11. package/esm/client/2_client_plain.js +20 -15
  12. package/esm/client/4_client.d.ts +4 -55
  13. package/esm/client/4_client.js +619 -716
  14. package/esm/connection/1_connection_web_socket.d.ts +1 -9
  15. package/esm/connection/1_connection_web_socket.js +92 -114
  16. package/esm/storage/0_storage.d.ts +3 -2
  17. package/esm/storage/0_storage.js +35 -26
  18. package/esm/storage/0_utilities.d.ts +1 -1
  19. package/esm/storage/0_utilities.js +57 -27
  20. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  21. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  22. package/esm/transport/1_transport_abridged.d.ts +1 -2
  23. package/esm/transport/1_transport_abridged.js +24 -19
  24. package/esm/transport/1_transport_intermediate.d.ts +1 -2
  25. package/esm/transport/1_transport_intermediate.js +23 -18
  26. package/esm/types/0_color.d.ts +2 -1
  27. package/esm/types/0_color.js +21 -1
  28. package/esm/types/1_chat.js +5 -5
  29. package/esm/types/1_user.js +2 -2
  30. package/esm/utilities/0_base64.js +3 -3
  31. package/esm/utilities/0_queue.d.ts +2 -4
  32. package/esm/utilities/0_queue.js +39 -36
  33. package/package.json +1 -1
  34. package/script/0_deps.d.ts +1 -1
  35. package/script/0_deps.js +3 -3
  36. package/script/4_constants.d.ts +1 -1
  37. package/script/4_constants.js +1 -1
  38. package/script/client/0_html.js +26 -14
  39. package/script/client/0_utilities.d.ts +1 -1
  40. package/script/client/0_utilities.js +1 -2
  41. package/script/client/1_client_abstract.d.ts +1 -1
  42. package/script/client/1_client_abstract.js +16 -8
  43. package/script/client/2_client_plain.d.ts +1 -2
  44. package/script/client/2_client_plain.js +20 -15
  45. package/script/client/4_client.d.ts +4 -55
  46. package/script/client/4_client.js +619 -716
  47. package/script/connection/1_connection_web_socket.d.ts +1 -9
  48. package/script/connection/1_connection_web_socket.js +93 -115
  49. package/script/storage/0_storage.d.ts +3 -2
  50. package/script/storage/0_storage.js +35 -26
  51. package/script/storage/0_utilities.d.ts +1 -1
  52. package/script/storage/0_utilities.js +56 -26
  53. package/script/storage/1_storage_local_storage.d.ts +1 -1
  54. package/script/storage/1_storage_session_storage.d.ts +1 -1
  55. package/script/transport/1_transport_abridged.d.ts +1 -2
  56. package/script/transport/1_transport_abridged.js +24 -19
  57. package/script/transport/1_transport_intermediate.d.ts +1 -2
  58. package/script/transport/1_transport_intermediate.js +23 -18
  59. package/script/types/0_color.d.ts +2 -1
  60. package/script/types/0_color.js +24 -3
  61. package/script/types/1_chat.js +4 -4
  62. package/script/types/1_user.js +1 -1
  63. package/script/utilities/0_base64.js +2 -2
  64. package/script/utilities/0_queue.d.ts +2 -4
  65. package/script/utilities/0_queue.js +39 -36
@@ -1,17 +1,9 @@
1
1
  import { ConnectionUnframed } from "./0_connection.js";
2
2
  export declare class ConnectionWebSocket extends ConnectionUnframed implements ConnectionUnframed {
3
+ #private;
3
4
  private readonly url;
4
- private webSocket;
5
- private rMutex;
6
- private wMutex;
7
- private buffer;
8
- private nextResolve;
9
5
  constructor(url: string | URL);
10
- private initWs;
11
6
  get connected(): boolean;
12
- private wasConnected;
13
- private isConnecting;
14
- private connectionError;
15
7
  open(): Promise<void>;
16
8
  read(p: Uint8Array): Promise<void>;
17
9
  write(p: Uint8Array): Promise<void>;
@@ -1,120 +1,59 @@
1
1
  "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ 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");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _ConnectionWebSocket_instances, _ConnectionWebSocket_webSocket, _ConnectionWebSocket_rMutex, _ConnectionWebSocket_wMutex, _ConnectionWebSocket_buffer, _ConnectionWebSocket_nextResolve, _ConnectionWebSocket_initWs, _ConnectionWebSocket_wasConnected, _ConnectionWebSocket_isConnecting, _ConnectionWebSocket_connectionError, _ConnectionWebSocket_assertConnected, _ConnectionWebSocket_rejectRead;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.ConnectionWebSocket = void 0;
4
16
  const _0_deps_js_1 = require("../0_deps.js");
5
17
  const _1_utilities_js_1 = require("../1_utilities.js");
6
18
  const _0_connection_js_1 = require("./0_connection.js");
7
19
  const d = (0, _0_deps_js_1.debug)("ConnectionWebSocket");
20
+ const errConnectionNotOpen = new Error("Connection not open");
8
21
  class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
9
22
  constructor(url) {
10
23
  super();
24
+ _ConnectionWebSocket_instances.add(this);
11
25
  Object.defineProperty(this, "url", {
12
26
  enumerable: true,
13
27
  configurable: true,
14
28
  writable: true,
15
29
  value: url
16
30
  });
17
- Object.defineProperty(this, "webSocket", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
- Object.defineProperty(this, "rMutex", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: new _0_deps_js_1.Mutex()
28
- });
29
- Object.defineProperty(this, "wMutex", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: new _0_deps_js_1.Mutex()
34
- });
35
- Object.defineProperty(this, "buffer", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: new Array()
40
- });
41
- Object.defineProperty(this, "nextResolve", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: null
46
- });
47
- Object.defineProperty(this, "wasConnected", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: false
52
- });
53
- Object.defineProperty(this, "isConnecting", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: false
58
- });
59
- Object.defineProperty(this, "connectionError", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: null
64
- });
65
- this.webSocket = this.initWs();
66
- }
67
- initWs() {
68
- const webSocket = new WebSocket(this.url, "binary");
69
- const mutex = new _0_deps_js_1.Mutex();
70
- webSocket.addEventListener("close", () => {
71
- this.stateChangeHandler?.(false);
72
- });
73
- webSocket.addEventListener("open", () => {
74
- this.stateChangeHandler?.(true);
75
- });
76
- webSocket.addEventListener("message", async (e) => {
77
- if (typeof e.data === "string") {
78
- return;
79
- }
80
- const release = await mutex.acquire();
81
- const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _1_utilities_js_1.UNREACHABLE)())).arrayBuffer());
82
- for (const byte of data) {
83
- this.buffer.push(byte);
84
- }
85
- if (this.nextResolve != null && this.buffer.length >= this.nextResolve[0]) {
86
- this.nextResolve[1].resolve();
87
- this.nextResolve = null;
88
- }
89
- release();
90
- });
91
- webSocket.addEventListener("error", (err) => {
92
- if (this.isConnecting) {
93
- // @ts-ignore: Node.js
94
- this.connectionError = err;
95
- }
96
- if (this.connected) {
97
- d("WebSocket error: %o", err);
98
- }
99
- });
100
- return webSocket;
31
+ _ConnectionWebSocket_webSocket.set(this, void 0);
32
+ _ConnectionWebSocket_rMutex.set(this, new _0_deps_js_1.Mutex());
33
+ _ConnectionWebSocket_wMutex.set(this, new _0_deps_js_1.Mutex());
34
+ _ConnectionWebSocket_buffer.set(this, new Array());
35
+ _ConnectionWebSocket_nextResolve.set(this, null);
36
+ _ConnectionWebSocket_wasConnected.set(this, false);
37
+ _ConnectionWebSocket_isConnecting.set(this, false);
38
+ _ConnectionWebSocket_connectionError.set(this, null);
39
+ __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_initWs).call(this), "f");
101
40
  }
102
41
  get connected() {
103
- return this.webSocket.readyState == WebSocket.OPEN;
42
+ return __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == WebSocket.OPEN;
104
43
  }
105
44
  async open() {
106
- if (this.isConnecting) {
45
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
107
46
  throw new Error("Already connecting");
108
47
  }
109
- this.isConnecting = true;
110
- if (!this.connected && this.wasConnected) {
111
- this.webSocket = this.initWs();
48
+ __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, true, "f");
49
+ if (!this.connected && __classPrivateFieldGet(this, _ConnectionWebSocket_wasConnected, "f")) {
50
+ __classPrivateFieldSet(this, _ConnectionWebSocket_webSocket, __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_initWs).call(this), "f");
112
51
  }
113
52
  try {
114
- while (this.webSocket.readyState != WebSocket.OPEN) {
115
- if (this.webSocket.readyState == WebSocket.CLOSED) {
116
- if (this.connectionError instanceof ErrorEvent) {
117
- throw new Error(this.connectionError.message);
53
+ while (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState != WebSocket.OPEN) {
54
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == WebSocket.CLOSED) {
55
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f") instanceof ErrorEvent) {
56
+ throw new Error(__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f").message);
118
57
  }
119
58
  else {
120
59
  throw new Error("Connection was closed");
@@ -124,48 +63,87 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
124
63
  await new Promise((r) => setTimeout(r, 5));
125
64
  }
126
65
  }
127
- this.wasConnected = true;
66
+ __classPrivateFieldSet(this, _ConnectionWebSocket_wasConnected, true, "f");
128
67
  }
129
68
  finally {
130
- this.isConnecting = false;
131
- this.connectionError = null;
69
+ __classPrivateFieldSet(this, _ConnectionWebSocket_isConnecting, false, "f");
70
+ __classPrivateFieldSet(this, _ConnectionWebSocket_connectionError, null, "f");
132
71
  }
133
72
  }
134
73
  async read(p) {
135
- if (this.webSocket.readyState != WebSocket.OPEN) {
136
- throw new Error("Connection not open");
137
- }
138
- const release = await this.rMutex.acquire();
74
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
75
+ const release = await __classPrivateFieldGet(this, _ConnectionWebSocket_rMutex, "f").acquire();
139
76
  try {
140
- if (this.buffer.length < p.length) {
141
- await new Promise((resolve, reject) => this.nextResolve = [p.length, { resolve, reject }]);
77
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
78
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length < p.length) {
79
+ await new Promise((resolve, reject) => __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, [p.length, { resolve, reject }], "f"));
142
80
  }
143
- p.set(this.buffer.splice(0, p.length));
81
+ p.set(__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").splice(0, p.length));
144
82
  }
145
83
  finally {
146
84
  release();
147
85
  }
148
86
  }
149
87
  async write(p) {
150
- if (this.webSocket.readyState == WebSocket.CLOSED) {
151
- throw new Error("Connection not open");
152
- }
153
- const release = await this.wMutex.acquire();
88
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
89
+ const release = await __classPrivateFieldGet(this, _ConnectionWebSocket_wMutex, "f").acquire();
154
90
  try {
155
- this.webSocket.send(p);
91
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
92
+ __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").send(p);
156
93
  }
157
94
  finally {
158
95
  release();
159
96
  }
160
97
  }
161
98
  close() {
162
- if (this.webSocket.readyState == WebSocket.CLOSED) {
163
- throw new Error("Connection not open");
164
- }
165
- this.webSocket.close(1000, "method");
166
- if (this.nextResolve != null) {
167
- this.nextResolve[1].reject(new Error("Connection not open"));
168
- }
99
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_assertConnected).call(this);
100
+ __classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").close(1000, "method");
101
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_rejectRead).call(this);
169
102
  }
170
103
  }
171
104
  exports.ConnectionWebSocket = ConnectionWebSocket;
105
+ _ConnectionWebSocket_webSocket = new WeakMap(), _ConnectionWebSocket_rMutex = new WeakMap(), _ConnectionWebSocket_wMutex = new WeakMap(), _ConnectionWebSocket_buffer = new WeakMap(), _ConnectionWebSocket_nextResolve = new WeakMap(), _ConnectionWebSocket_wasConnected = new WeakMap(), _ConnectionWebSocket_isConnecting = new WeakMap(), _ConnectionWebSocket_connectionError = new WeakMap(), _ConnectionWebSocket_instances = new WeakSet(), _ConnectionWebSocket_initWs = function _ConnectionWebSocket_initWs() {
106
+ const webSocket = new WebSocket(this.url, "binary");
107
+ const mutex = new _0_deps_js_1.Mutex();
108
+ webSocket.addEventListener("close", () => {
109
+ __classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_rejectRead).call(this);
110
+ this.stateChangeHandler?.(false);
111
+ });
112
+ webSocket.addEventListener("open", () => {
113
+ this.stateChangeHandler?.(true);
114
+ });
115
+ webSocket.addEventListener("message", async (e) => {
116
+ if (typeof e.data === "string") {
117
+ return;
118
+ }
119
+ const release = await mutex.acquire();
120
+ const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _1_utilities_js_1.UNREACHABLE)())).arrayBuffer());
121
+ for (const byte of data) {
122
+ __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").push(byte);
123
+ }
124
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") != null && __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[0]) {
125
+ __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].resolve();
126
+ __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
127
+ }
128
+ release();
129
+ });
130
+ webSocket.addEventListener("error", (err) => {
131
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
132
+ // @ts-ignore: Node.js
133
+ __classPrivateFieldSet(this, _ConnectionWebSocket_connectionError, err, "f");
134
+ }
135
+ if (this.connected) {
136
+ d("WebSocket error: %o", err);
137
+ }
138
+ });
139
+ return webSocket;
140
+ }, _ConnectionWebSocket_assertConnected = function _ConnectionWebSocket_assertConnected() {
141
+ if (!this.connected) {
142
+ throw errConnectionNotOpen;
143
+ }
144
+ }, _ConnectionWebSocket_rejectRead = function _ConnectionWebSocket_rejectRead() {
145
+ if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") != null) {
146
+ __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].reject(errConnectionNotOpen);
147
+ __classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
148
+ }
149
+ };
@@ -3,14 +3,13 @@ import { TLObject, types } from "../2_tl.js";
3
3
  import { DC } from "../3_transport.js";
4
4
  export type StorageKeyPart = string | number | bigint;
5
5
  export declare abstract class Storage {
6
- private _authKeyId;
6
+ #private;
7
7
  abstract init(): MaybePromise<void>;
8
8
  abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
9
9
  abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
10
10
  abstract getMany<T>(prefix: readonly StorageKeyPart[]): MaybePromise<Generator<[readonly StorageKeyPart[], T]> | AsyncGenerator<[readonly StorageKeyPart[], T]>>;
11
11
  setDc(dc: DC | null): MaybePromise<void>;
12
12
  getDc(): MaybePromise<DC | null>;
13
- private resetAuthKeyId;
14
13
  getAuthKey(): Promise<Uint8Array | null>;
15
14
  setAuthKey(authKey: Uint8Array | null): Promise<void>;
16
15
  get authKeyId(): bigint | null;
@@ -41,4 +40,6 @@ export declare abstract class Storage {
41
40
  getAccountType(): MaybePromise<"bot" | "user" | null>;
42
41
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
42
  getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
43
+ setServerSalt(serverSalt: bigint): Promise<void>;
44
+ getServerSalt(): MaybePromise<bigint | null>;
44
45
  }
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.Storage = void 0;
4
16
  const _1_utilities_js_1 = require("../1_utilities.js");
@@ -18,12 +30,8 @@ const KPARTS_MESSAGE = (chatId, messageId) => ["messages", chatId, messageId];
18
30
  const KPARTS_MESSAGE_REF = (messageId) => ["messageRefs", messageId];
19
31
  class Storage {
20
32
  constructor() {
21
- Object.defineProperty(this, "_authKeyId", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: null
26
- });
33
+ _Storage_instances.add(this);
34
+ _Storage__authKeyId.set(this, null);
27
35
  }
28
36
  setDc(dc) {
29
37
  return this.set(KPARTS__DC, dc);
@@ -31,25 +39,17 @@ class Storage {
31
39
  getDc() {
32
40
  return this.get(KPARTS__DC);
33
41
  }
34
- async resetAuthKeyId(authKey) {
35
- if (authKey != null) {
36
- this._authKeyId = await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false));
37
- }
38
- else {
39
- this._authKeyId = null;
40
- }
41
- }
42
42
  async getAuthKey() {
43
43
  const authKey = await this.get(KPARTS__AUTH_KEY);
44
- await this.resetAuthKeyId(authKey);
44
+ await __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_resetAuthKeyId).call(this, authKey);
45
45
  return authKey;
46
46
  }
47
47
  async setAuthKey(authKey) {
48
48
  await this.set(KPARTS__AUTH_KEY, authKey);
49
- await this.resetAuthKeyId(authKey);
49
+ await __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_resetAuthKeyId).call(this, authKey);
50
50
  }
51
51
  get authKeyId() {
52
- return this._authKeyId;
52
+ return __classPrivateFieldGet(this, _Storage__authKeyId, "f");
53
53
  }
54
54
  setChannelAccessHash(id, accessHash) {
55
55
  return this.set(KPARTS__CHANNEL_ACCESS_HASH(id), accessHash);
@@ -66,17 +66,12 @@ class Storage {
66
66
  async updateUsernames(type, id, usernames) {
67
67
  for (let username of usernames) {
68
68
  username = username.toLowerCase();
69
- await this.set(KPARTS__USERNAME(username), [type, String(id), new Date()]);
69
+ await this.set(KPARTS__USERNAME(username), [type, id, new Date()]);
70
70
  }
71
71
  }
72
72
  async getUsername(username) {
73
73
  username = username.toLowerCase();
74
- const v = await this.get(KPARTS__USERNAME(username));
75
- if (v != null) {
76
- v[1] = BigInt(v[1]);
77
- v[2] = new Date(v[2]);
78
- }
79
- return v;
74
+ return await this.get(KPARTS__USERNAME(username));
80
75
  }
81
76
  async setTlObject(key, value) {
82
77
  if (value == null) {
@@ -128,12 +123,12 @@ class Storage {
128
123
  }
129
124
  async setEntity(peer) {
130
125
  const type = peer instanceof _2_tl_js_1.types.Channel ? "channel" : peer instanceof _2_tl_js_1.types.Chat ? "chat" : peer instanceof _2_tl_js_1.types.User ? "user" : (0, _1_utilities_js_1.UNREACHABLE)();
131
- await this.set(KPARTS__PEER(type, peer.id), peer[_2_tl_js_1.serialize]());
126
+ await this.set(KPARTS__PEER(type, peer.id), (0, _1_utilities_js_1.rleEncode)(peer[_2_tl_js_1.serialize]()));
132
127
  }
133
128
  async getEntity(type, id) {
134
129
  const peer_ = await this.get(KPARTS__PEER(type, id));
135
130
  if (peer_ != null) {
136
- return new _2_tl_js_1.TLReader(peer_).readObject();
131
+ return new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)(peer_)).readObject();
137
132
  }
138
133
  else {
139
134
  return null;
@@ -162,5 +157,19 @@ class Storage {
162
157
  getStickerSetName(id, accessHash) {
163
158
  return this.get(KPARTS__STICKER_SET_NAME(id, accessHash));
164
159
  }
160
+ async setServerSalt(serverSalt) {
161
+ await this.set(["serverSalt"], serverSalt);
162
+ }
163
+ getServerSalt() {
164
+ return this.get(["serverSalt"]);
165
+ }
165
166
  }
166
167
  exports.Storage = Storage;
168
+ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
169
+ if (authKey != null) {
170
+ __classPrivateFieldSet(this, _Storage__authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false)), "f");
171
+ }
172
+ else {
173
+ __classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
174
+ }
175
+ };
@@ -9,6 +9,6 @@ export declare enum ValueType {
9
9
  Array = 6
10
10
  }
11
11
  export declare function toString(value: unknown): string;
12
- export declare function fromString<T>(string: string): any;
12
+ export declare function fromString<T>(string: string): T;
13
13
  export declare function fixKey(key: readonly StorageKeyPart[]): (string | number)[];
14
14
  export declare function getPrefixKeyRange(prefix: any): IDBKeyRange;
@@ -15,25 +15,34 @@ var ValueType;
15
15
  })(ValueType = exports.ValueType || (exports.ValueType = {}));
16
16
  function toString(value) {
17
17
  if (typeof value === "boolean") {
18
- return JSON.stringify([ValueType.Boolean, value]);
18
+ return `${ValueType.Boolean}${Number(value)}`;
19
19
  }
20
20
  else if (typeof value === "number") {
21
- return JSON.stringify([ValueType.Number, value]);
21
+ return `${ValueType.Number}${value}`;
22
22
  }
23
23
  else if (typeof value === "string") {
24
- return JSON.stringify([ValueType.String, value]);
24
+ return `${ValueType.String}${value}`;
25
25
  }
26
26
  else if (typeof value == "bigint") {
27
- return JSON.stringify([ValueType.BigInt, String(value)]);
27
+ return `${ValueType.BigInt}${value}`;
28
28
  }
29
29
  else if (value instanceof Date) {
30
- return JSON.stringify([ValueType.Date, value.getTime()]);
30
+ return `${ValueType.Date}${value.getTime()}`;
31
31
  }
32
32
  else if (value instanceof Uint8Array) {
33
- return JSON.stringify([ValueType.Uint8Array, (0, _0_deps_js_1.base64Encode)(value)]);
33
+ return `${ValueType.Uint8Array}${(0, _0_deps_js_1.encodeBase64)(value)}`;
34
34
  }
35
35
  else if (Array.isArray(value)) {
36
- return JSON.stringify([ValueType.Array, value.map(toString)]);
36
+ const items = value.map((v) => {
37
+ if (typeof v === "string" || v instanceof Uint8Array || Array.isArray(v)) {
38
+ const s = toString(v).slice(1);
39
+ return String(typeof v === "string" ? ValueType.String : v instanceof Uint8Array ? ValueType.Uint8Array : ValueType.Array) + toString(s.length).slice(1) + "\n" + s;
40
+ }
41
+ else {
42
+ return toString(v);
43
+ }
44
+ });
45
+ return `${ValueType.Array}${items.join("\n")}`;
37
46
  }
38
47
  else {
39
48
  (0, _1_utilities_js_1.UNREACHABLE)();
@@ -41,29 +50,50 @@ function toString(value) {
41
50
  }
42
51
  exports.toString = toString;
43
52
  function fromString(string) {
44
- const [type, value] = JSON.parse(string);
45
- if (type == ValueType.Boolean || type == ValueType.Number || type == ValueType.String) {
46
- return value;
47
- }
48
- else if (type == ValueType.BigInt) {
49
- return BigInt(value);
50
- }
51
- else if (type == ValueType.Date) {
52
- return new Date(value);
53
- }
54
- else if (type == ValueType.Uint8Array) {
55
- return (0, _0_deps_js_1.base64Decode)(value);
56
- }
57
- else if (type == ValueType.Array) {
58
- return value.map(fromString);
59
- }
60
- else {
61
- (0, _1_utilities_js_1.UNREACHABLE)();
53
+ const [type, value] = [Number(string[0]), string.slice(1)];
54
+ switch (type) {
55
+ case ValueType.Boolean:
56
+ return Boolean(Number(value));
57
+ case ValueType.Number:
58
+ return Number(value);
59
+ case ValueType.String:
60
+ return value;
61
+ case ValueType.BigInt:
62
+ return BigInt(value);
63
+ case ValueType.Date:
64
+ return new Date(Number(value));
65
+ case ValueType.Uint8Array:
66
+ return (0, _0_deps_js_1.decodeBase64)(value);
67
+ case ValueType.Array: {
68
+ const arr = [];
69
+ for (let i = 0; i < value.length; ++i) {
70
+ const type = Number(value[i]);
71
+ let value_ = "";
72
+ while (value[++i] != "\n") {
73
+ value_ += value[i];
74
+ if (i == value.length - 1) {
75
+ break;
76
+ }
77
+ }
78
+ switch (type) {
79
+ case ValueType.String:
80
+ case ValueType.Uint8Array:
81
+ case ValueType.Array: {
82
+ const len = Number(value_);
83
+ ++i;
84
+ value_ = value.slice(i, i + Number(value_));
85
+ i += len;
86
+ }
87
+ }
88
+ arr.push(fromString(`${type}${value_}`));
89
+ }
90
+ return arr;
91
+ }
62
92
  }
63
93
  }
64
94
  exports.fromString = fromString;
65
95
  function fixKey(key) {
66
- return key.map((v) => typeof v === "bigint" ? String(v) : v);
96
+ return key.map((v) => typeof v === "bigint" ? String(ValueType.BigInt) + String(v) : typeof v === "string" ? String(ValueType.String) + v : v);
67
97
  }
68
98
  exports.fixKey = fixKey;
69
99
  // Source: https://gist.github.com/inexorabletash/5462871
@@ -4,7 +4,7 @@ export declare class StorageLocalStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
6
6
  init(): void;
7
- get(key_: readonly StorageKeyPart[]): any;
7
+ get<T>(key_: readonly StorageKeyPart[]): T | null;
8
8
  getMany<T>(prefix: readonly StorageKeyPart[]): Generator<[readonly StorageKeyPart[], T], void, unknown>;
9
9
  set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
10
10
  }
@@ -4,7 +4,7 @@ export declare class StorageSessionStorage extends Storage implements Storage {
4
4
  private readonly prefix;
5
5
  constructor(prefix: string);
6
6
  init(): void;
7
- get(key_: readonly StorageKeyPart[]): any;
7
+ get<T>(key_: readonly StorageKeyPart[]): T | null;
8
8
  getMany<T>(prefix: readonly StorageKeyPart[]): Generator<[readonly StorageKeyPart[], T], void, unknown>;
9
9
  set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
10
10
  }
@@ -1,8 +1,7 @@
1
1
  import { Connection } from "../2_connection.js";
2
2
  import { Transport } from "./0_transport.js";
3
3
  export declare class TransportAbridged extends Transport implements Transport {
4
- private readonly connection;
5
- private readonly obfuscated;
4
+ #private;
6
5
  constructor(connection: Connection, obfuscated?: boolean);
7
6
  initialize(): Promise<void>;
8
7
  receive(): Promise<Uint8Array>;