@mtkruto/node 0.0.825 → 0.0.830
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/client.d.ts +0 -4
- package/esm/client/client.js +2 -114
- package/esm/constants.d.ts +0 -4
- package/esm/constants.js +0 -4
- package/esm/storage/storage.d.ts +0 -9
- package/esm/storage/storage.js +0 -59
- package/package.json +1 -1
- package/script/client/client.d.ts +0 -4
- package/script/client/client.js +1 -113
- package/script/constants.d.ts +0 -4
- package/script/constants.js +1 -5
- package/script/storage/storage.d.ts +0 -9
- package/script/storage/storage.js +0 -59
package/esm/client/client.d.ts
CHANGED
|
@@ -113,8 +113,4 @@ export declare class Client extends ClientAbstract {
|
|
|
113
113
|
* Alias for `invoke` with its second parameter being `true`.
|
|
114
114
|
*/
|
|
115
115
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
116
|
-
private processChats;
|
|
117
|
-
private processUsers;
|
|
118
|
-
private processUpdates;
|
|
119
|
-
getInputPeer(id: string | number): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
|
|
120
116
|
}
|
package/esm/client/client.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { gunzip } from "../deps.js";
|
|
2
|
-
import { ackThreshold, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER
|
|
2
|
+
import { ackThreshold, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "../constants.js";
|
|
3
3
|
import { bigIntFromBuffer, getRandomBigInt } from "../utilities/0_bigint.js";
|
|
4
4
|
import { decryptMessage, encryptMessage, getMessageId } from "../utilities/1_message.js";
|
|
5
5
|
import { checkPassword } from "../utilities/1_password.js";
|
|
6
|
-
import { as } from "../tl/1_tl_object.js";
|
|
7
6
|
import * as types from "../tl/2_types.js";
|
|
8
7
|
import * as functions from "../tl/3_functions.js";
|
|
9
8
|
import { TLReader } from "../tl/3_tl_reader.js";
|
|
@@ -392,7 +391,7 @@ export class Client extends ClientAbstract {
|
|
|
392
391
|
}
|
|
393
392
|
// logger().debug(`Received ${body.constructor.name}`);
|
|
394
393
|
if (body instanceof types.Updates) {
|
|
395
|
-
this.
|
|
394
|
+
this.updatesHandler?.(this, body);
|
|
396
395
|
}
|
|
397
396
|
else if (message.body instanceof RPCResult) {
|
|
398
397
|
let result = message.body.result;
|
|
@@ -405,10 +404,6 @@ export class Client extends ClientAbstract {
|
|
|
405
404
|
promise.reject(result);
|
|
406
405
|
}
|
|
407
406
|
else {
|
|
408
|
-
if (result instanceof types.Updates) {
|
|
409
|
-
await this.processChats(result.chats);
|
|
410
|
-
await this.processUsers(result.users);
|
|
411
|
-
}
|
|
412
407
|
promise.resolve(result);
|
|
413
408
|
}
|
|
414
409
|
this.promises.delete(message.body.messageId);
|
|
@@ -477,111 +472,4 @@ export class Client extends ClientAbstract {
|
|
|
477
472
|
send(function_) {
|
|
478
473
|
return this.invoke(function_, true);
|
|
479
474
|
}
|
|
480
|
-
async processChats(chats) {
|
|
481
|
-
for (const chat of chats) {
|
|
482
|
-
if (chat instanceof types.Channel && chat.accessHash) {
|
|
483
|
-
await this.storage.setChannelAccessHash(chat.id, chat.accessHash);
|
|
484
|
-
if (chat.username) {
|
|
485
|
-
await this.storage.updateUsernames("channel", chat.id, [chat.username]);
|
|
486
|
-
}
|
|
487
|
-
if (chat.usernames) {
|
|
488
|
-
await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v[as](types.Username)).map((v) => v.username));
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async processUsers(users) {
|
|
494
|
-
for (const user of users) {
|
|
495
|
-
if (user instanceof types.User && user.accessHash) {
|
|
496
|
-
await this.storage.setUserAccessHash(user.id, user.accessHash);
|
|
497
|
-
if (user.username) {
|
|
498
|
-
await this.storage.updateUsernames("user", user.id, [user.username]);
|
|
499
|
-
}
|
|
500
|
-
if (user.usernames) {
|
|
501
|
-
await this.storage.updateUsernames("user", user.id, user.usernames.map((v) => v[as](types.Username)).map((v) => v.username));
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
async processUpdates(updates) {
|
|
507
|
-
try {
|
|
508
|
-
await this.processChats(updates.chats);
|
|
509
|
-
await this.processUsers(updates.users);
|
|
510
|
-
for (const update of updates.updates) {
|
|
511
|
-
if (update instanceof types.UpdateUserName) {
|
|
512
|
-
await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v[as](types.Username)).map((v) => v.username));
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
await this.updatesHandler?.(this, updates);
|
|
516
|
-
}
|
|
517
|
-
catch (err) {
|
|
518
|
-
console.error("Error processing updates:", err);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
async getInputPeer(id) {
|
|
522
|
-
if (typeof id === "string") {
|
|
523
|
-
if (!id.startsWith("@")) {
|
|
524
|
-
throw new Error("Expected username to start with @");
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
id = id.slice(1);
|
|
528
|
-
if (!id) {
|
|
529
|
-
throw new Error("Empty username");
|
|
530
|
-
}
|
|
531
|
-
let userId = 0n;
|
|
532
|
-
let channelId = 0n;
|
|
533
|
-
const maybeUsername = await this.storage.getUsername(id);
|
|
534
|
-
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() < USERNAME_TTL) {
|
|
535
|
-
const [type, id] = maybeUsername;
|
|
536
|
-
if (type == "user") {
|
|
537
|
-
userId = id;
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
channelId = id;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
const resolved = await this.invoke(new functions.ContactsResolveUsername({ username: id }));
|
|
545
|
-
await this.processChats(resolved.chats);
|
|
546
|
-
await this.processUsers(resolved.users);
|
|
547
|
-
if (resolved.peer instanceof types.PeerUser) {
|
|
548
|
-
userId = resolved.peer.userId;
|
|
549
|
-
}
|
|
550
|
-
else if (resolved.peer instanceof types.PeerChannel) {
|
|
551
|
-
channelId = resolved.peer.channelId;
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
throw new Error("Unreachable");
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (userId) {
|
|
558
|
-
const accessHash = await this.storage.getUserAccessHash(userId);
|
|
559
|
-
return new types.InputPeerUser({ userId, accessHash: accessHash ?? 0n });
|
|
560
|
-
}
|
|
561
|
-
else if (channelId) {
|
|
562
|
-
const accessHash = await this.storage.getChannelAccessHash(channelId);
|
|
563
|
-
return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
throw new Error("Unreachable");
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
else if (id > 0) {
|
|
571
|
-
const id_ = BigInt(id);
|
|
572
|
-
const accessHash = await this.storage.getUserAccessHash(id_);
|
|
573
|
-
return new types.InputPeerUser({ userId: id_, accessHash: accessHash ?? 0n });
|
|
574
|
-
}
|
|
575
|
-
else if (-MAX_CHAT_ID <= id) {
|
|
576
|
-
return new types.InputPeerChat({ chatId: BigInt(Math.abs(id)) });
|
|
577
|
-
}
|
|
578
|
-
else if (ZERO_CHANNEL_ID - MAX_CHANNEL_ID <= id && id != ZERO_CHANNEL_ID) {
|
|
579
|
-
const id_ = BigInt(Math.abs(id - ZERO_CHANNEL_ID));
|
|
580
|
-
const accessHash = await this.storage.getChannelAccessHash(id_);
|
|
581
|
-
return new types.InputPeerChannel({ channelId: id_, accessHash: accessHash ?? 0n });
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
throw new Error("ID format unknown or not implemented");
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
475
|
}
|
package/esm/constants.d.ts
CHANGED
|
@@ -10,7 +10,3 @@ export declare const DEFAULT_LANG_CODE = "en";
|
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
|
11
11
|
export declare const DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
12
12
|
export declare const DEFAULT_SYSTEM_VERSION = "1.0";
|
|
13
|
-
export declare const USERNAME_TTL = 86400;
|
|
14
|
-
export declare const MAX_CHAT_ID = 999999999999;
|
|
15
|
-
export declare const MAX_CHANNEL_ID = 997852516352;
|
|
16
|
-
export declare const ZERO_CHANNEL_ID = -1000000000000;
|
package/esm/constants.js
CHANGED
|
@@ -68,7 +68,3 @@ export const DEFAULT_LANG_CODE = "en";
|
|
|
68
68
|
export const DEFAULT_LANG_PACK = "";
|
|
69
69
|
export const DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
70
70
|
export const DEFAULT_SYSTEM_VERSION = "1.0";
|
|
71
|
-
export const USERNAME_TTL = 86400;
|
|
72
|
-
export const MAX_CHAT_ID = 999999999999;
|
|
73
|
-
export const MAX_CHANNEL_ID = 997852516352;
|
|
74
|
-
export const ZERO_CHANNEL_ID = -1000000000000;
|
package/esm/storage/storage.d.ts
CHANGED
|
@@ -11,13 +11,4 @@ export declare abstract class Storage {
|
|
|
11
11
|
getAuthKey(): Promise<Uint8Array | null>;
|
|
12
12
|
setAuthKey(authKey: Uint8Array | null): Promise<void>;
|
|
13
13
|
get authKeyId(): bigint | null;
|
|
14
|
-
private readonly channelAccessHash__;
|
|
15
|
-
setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
16
|
-
getChannelAccessHash(id: bigint): Promise<bigint | null>;
|
|
17
|
-
private readonly userAccessHash__;
|
|
18
|
-
setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
19
|
-
getUserAccessHash(id: bigint): Promise<bigint | null>;
|
|
20
|
-
private readonly username__;
|
|
21
|
-
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
22
|
-
getUsername(username: string): Promise<readonly ["user" | "channel", bigint, Date] | null>;
|
|
23
14
|
}
|
package/esm/storage/storage.js
CHANGED
|
@@ -8,24 +8,6 @@ export class Storage {
|
|
|
8
8
|
writable: true,
|
|
9
9
|
value: null
|
|
10
10
|
});
|
|
11
|
-
Object.defineProperty(this, "channelAccessHash__", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: "channelAccessHash__"
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "userAccessHash__", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: "userAccessHash__"
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "username__", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: "username__"
|
|
28
|
-
});
|
|
29
11
|
}
|
|
30
12
|
setDc(dc) {
|
|
31
13
|
return this.set("dc", dc);
|
|
@@ -54,45 +36,4 @@ export class Storage {
|
|
|
54
36
|
get authKeyId() {
|
|
55
37
|
return this._authKeyId;
|
|
56
38
|
}
|
|
57
|
-
setChannelAccessHash(id, accessHash) {
|
|
58
|
-
return this.set(`${this.channelAccessHash__}${id}`, String(accessHash));
|
|
59
|
-
}
|
|
60
|
-
async getChannelAccessHash(id) {
|
|
61
|
-
const accessHash = await this.get(`${this.channelAccessHash__}${id}`);
|
|
62
|
-
if (accessHash != null) {
|
|
63
|
-
return BigInt(accessHash);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
setUserAccessHash(id, accessHash) {
|
|
70
|
-
return this.set(`${this.userAccessHash__}${id}`, String(accessHash));
|
|
71
|
-
}
|
|
72
|
-
async getUserAccessHash(id) {
|
|
73
|
-
const accessHash = await this.get(`${this.userAccessHash__}${id}`);
|
|
74
|
-
if (accessHash != null) {
|
|
75
|
-
return BigInt(accessHash);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async updateUsernames(type, id, usernames) {
|
|
82
|
-
for (let username of usernames) {
|
|
83
|
-
username = username.toLowerCase();
|
|
84
|
-
await this.set(`${this.username__}${username}`, JSON.stringify([type, String(id), new Date()]));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async getUsername(username) {
|
|
88
|
-
username = username.toLowerCase();
|
|
89
|
-
const username_ = await this.get(`${this.username__}${username}`);
|
|
90
|
-
if (username_ != null) {
|
|
91
|
-
const [type, id, updatedAt] = JSON.parse(username_);
|
|
92
|
-
return [type, BigInt(id), new Date(updatedAt)];
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
39
|
}
|
package/package.json
CHANGED
|
@@ -113,8 +113,4 @@ export declare class Client extends ClientAbstract {
|
|
|
113
113
|
* Alias for `invoke` with its second parameter being `true`.
|
|
114
114
|
*/
|
|
115
115
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
116
|
-
private processChats;
|
|
117
|
-
private processUsers;
|
|
118
|
-
private processUpdates;
|
|
119
|
-
getInputPeer(id: string | number): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
|
|
120
116
|
}
|
package/script/client/client.js
CHANGED
|
@@ -29,7 +29,6 @@ const constants_js_1 = require("../constants.js");
|
|
|
29
29
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
30
30
|
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
31
31
|
const _1_password_js_1 = require("../utilities/1_password.js");
|
|
32
|
-
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
33
32
|
const types = __importStar(require("../tl/2_types.js"));
|
|
34
33
|
const functions = __importStar(require("../tl/3_functions.js"));
|
|
35
34
|
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
@@ -418,7 +417,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
418
417
|
}
|
|
419
418
|
// logger().debug(`Received ${body.constructor.name}`);
|
|
420
419
|
if (body instanceof types.Updates) {
|
|
421
|
-
this.
|
|
420
|
+
this.updatesHandler?.(this, body);
|
|
422
421
|
}
|
|
423
422
|
else if (message.body instanceof _4_rpc_result_js_1.RPCResult) {
|
|
424
423
|
let result = message.body.result;
|
|
@@ -431,10 +430,6 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
431
430
|
promise.reject(result);
|
|
432
431
|
}
|
|
433
432
|
else {
|
|
434
|
-
if (result instanceof types.Updates) {
|
|
435
|
-
await this.processChats(result.chats);
|
|
436
|
-
await this.processUsers(result.users);
|
|
437
|
-
}
|
|
438
433
|
promise.resolve(result);
|
|
439
434
|
}
|
|
440
435
|
this.promises.delete(message.body.messageId);
|
|
@@ -503,112 +498,5 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
503
498
|
send(function_) {
|
|
504
499
|
return this.invoke(function_, true);
|
|
505
500
|
}
|
|
506
|
-
async processChats(chats) {
|
|
507
|
-
for (const chat of chats) {
|
|
508
|
-
if (chat instanceof types.Channel && chat.accessHash) {
|
|
509
|
-
await this.storage.setChannelAccessHash(chat.id, chat.accessHash);
|
|
510
|
-
if (chat.username) {
|
|
511
|
-
await this.storage.updateUsernames("channel", chat.id, [chat.username]);
|
|
512
|
-
}
|
|
513
|
-
if (chat.usernames) {
|
|
514
|
-
await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
async processUsers(users) {
|
|
520
|
-
for (const user of users) {
|
|
521
|
-
if (user instanceof types.User && user.accessHash) {
|
|
522
|
-
await this.storage.setUserAccessHash(user.id, user.accessHash);
|
|
523
|
-
if (user.username) {
|
|
524
|
-
await this.storage.updateUsernames("user", user.id, [user.username]);
|
|
525
|
-
}
|
|
526
|
-
if (user.usernames) {
|
|
527
|
-
await this.storage.updateUsernames("user", user.id, user.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
async processUpdates(updates) {
|
|
533
|
-
try {
|
|
534
|
-
await this.processChats(updates.chats);
|
|
535
|
-
await this.processUsers(updates.users);
|
|
536
|
-
for (const update of updates.updates) {
|
|
537
|
-
if (update instanceof types.UpdateUserName) {
|
|
538
|
-
await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
await this.updatesHandler?.(this, updates);
|
|
542
|
-
}
|
|
543
|
-
catch (err) {
|
|
544
|
-
console.error("Error processing updates:", err);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
async getInputPeer(id) {
|
|
548
|
-
if (typeof id === "string") {
|
|
549
|
-
if (!id.startsWith("@")) {
|
|
550
|
-
throw new Error("Expected username to start with @");
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
id = id.slice(1);
|
|
554
|
-
if (!id) {
|
|
555
|
-
throw new Error("Empty username");
|
|
556
|
-
}
|
|
557
|
-
let userId = 0n;
|
|
558
|
-
let channelId = 0n;
|
|
559
|
-
const maybeUsername = await this.storage.getUsername(id);
|
|
560
|
-
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() < constants_js_1.USERNAME_TTL) {
|
|
561
|
-
const [type, id] = maybeUsername;
|
|
562
|
-
if (type == "user") {
|
|
563
|
-
userId = id;
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
channelId = id;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
const resolved = await this.invoke(new functions.ContactsResolveUsername({ username: id }));
|
|
571
|
-
await this.processChats(resolved.chats);
|
|
572
|
-
await this.processUsers(resolved.users);
|
|
573
|
-
if (resolved.peer instanceof types.PeerUser) {
|
|
574
|
-
userId = resolved.peer.userId;
|
|
575
|
-
}
|
|
576
|
-
else if (resolved.peer instanceof types.PeerChannel) {
|
|
577
|
-
channelId = resolved.peer.channelId;
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
throw new Error("Unreachable");
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
if (userId) {
|
|
584
|
-
const accessHash = await this.storage.getUserAccessHash(userId);
|
|
585
|
-
return new types.InputPeerUser({ userId, accessHash: accessHash ?? 0n });
|
|
586
|
-
}
|
|
587
|
-
else if (channelId) {
|
|
588
|
-
const accessHash = await this.storage.getChannelAccessHash(channelId);
|
|
589
|
-
return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
throw new Error("Unreachable");
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
else if (id > 0) {
|
|
597
|
-
const id_ = BigInt(id);
|
|
598
|
-
const accessHash = await this.storage.getUserAccessHash(id_);
|
|
599
|
-
return new types.InputPeerUser({ userId: id_, accessHash: accessHash ?? 0n });
|
|
600
|
-
}
|
|
601
|
-
else if (-constants_js_1.MAX_CHAT_ID <= id) {
|
|
602
|
-
return new types.InputPeerChat({ chatId: BigInt(Math.abs(id)) });
|
|
603
|
-
}
|
|
604
|
-
else if (constants_js_1.ZERO_CHANNEL_ID - constants_js_1.MAX_CHANNEL_ID <= id && id != constants_js_1.ZERO_CHANNEL_ID) {
|
|
605
|
-
const id_ = BigInt(Math.abs(id - constants_js_1.ZERO_CHANNEL_ID));
|
|
606
|
-
const accessHash = await this.storage.getChannelAccessHash(id_);
|
|
607
|
-
return new types.InputPeerChannel({ channelId: id_, accessHash: accessHash ?? 0n });
|
|
608
|
-
}
|
|
609
|
-
else {
|
|
610
|
-
throw new Error("ID format unknown or not implemented");
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
501
|
}
|
|
614
502
|
exports.Client = Client;
|
package/script/constants.d.ts
CHANGED
|
@@ -10,7 +10,3 @@ export declare const DEFAULT_LANG_CODE = "en";
|
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
|
11
11
|
export declare const DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
12
12
|
export declare const DEFAULT_SYSTEM_VERSION = "1.0";
|
|
13
|
-
export declare const USERNAME_TTL = 86400;
|
|
14
|
-
export declare const MAX_CHAT_ID = 999999999999;
|
|
15
|
-
export declare const MAX_CHANNEL_ID = 997852516352;
|
|
16
|
-
export declare const ZERO_CHANNEL_ID = -1000000000000;
|
package/script/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DEFAULT_SYSTEM_VERSION = exports.DEFAULT_SYSTEM_LANG_CODE = exports.DEFAULT_LANG_PACK = exports.DEFAULT_LANG_CODE = exports.DEFAULT_DEVICE_MODEL = exports.DEFAULT_APP_VERSION = exports.LAYER = exports.DEFAULT_INITIAL_DC = exports.VECTOR_CONSTRUCTOR = exports.publicKeys = exports.ackThreshold = void 0;
|
|
4
4
|
exports.ackThreshold = 10;
|
|
5
5
|
exports.publicKeys = new Map([
|
|
6
6
|
[
|
|
@@ -71,7 +71,3 @@ exports.DEFAULT_LANG_CODE = "en";
|
|
|
71
71
|
exports.DEFAULT_LANG_PACK = "";
|
|
72
72
|
exports.DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
73
73
|
exports.DEFAULT_SYSTEM_VERSION = "1.0";
|
|
74
|
-
exports.USERNAME_TTL = 86400;
|
|
75
|
-
exports.MAX_CHAT_ID = 999999999999;
|
|
76
|
-
exports.MAX_CHANNEL_ID = 997852516352;
|
|
77
|
-
exports.ZERO_CHANNEL_ID = -1000000000000;
|
|
@@ -11,13 +11,4 @@ export declare abstract class Storage {
|
|
|
11
11
|
getAuthKey(): Promise<Uint8Array | null>;
|
|
12
12
|
setAuthKey(authKey: Uint8Array | null): Promise<void>;
|
|
13
13
|
get authKeyId(): bigint | null;
|
|
14
|
-
private readonly channelAccessHash__;
|
|
15
|
-
setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
16
|
-
getChannelAccessHash(id: bigint): Promise<bigint | null>;
|
|
17
|
-
private readonly userAccessHash__;
|
|
18
|
-
setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
19
|
-
getUserAccessHash(id: bigint): Promise<bigint | null>;
|
|
20
|
-
private readonly username__;
|
|
21
|
-
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
22
|
-
getUsername(username: string): Promise<readonly ["user" | "channel", bigint, Date] | null>;
|
|
23
14
|
}
|
|
@@ -11,24 +11,6 @@ class Storage {
|
|
|
11
11
|
writable: true,
|
|
12
12
|
value: null
|
|
13
13
|
});
|
|
14
|
-
Object.defineProperty(this, "channelAccessHash__", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: "channelAccessHash__"
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(this, "userAccessHash__", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: "userAccessHash__"
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(this, "username__", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: "username__"
|
|
31
|
-
});
|
|
32
14
|
}
|
|
33
15
|
setDc(dc) {
|
|
34
16
|
return this.set("dc", dc);
|
|
@@ -57,46 +39,5 @@ class Storage {
|
|
|
57
39
|
get authKeyId() {
|
|
58
40
|
return this._authKeyId;
|
|
59
41
|
}
|
|
60
|
-
setChannelAccessHash(id, accessHash) {
|
|
61
|
-
return this.set(`${this.channelAccessHash__}${id}`, String(accessHash));
|
|
62
|
-
}
|
|
63
|
-
async getChannelAccessHash(id) {
|
|
64
|
-
const accessHash = await this.get(`${this.channelAccessHash__}${id}`);
|
|
65
|
-
if (accessHash != null) {
|
|
66
|
-
return BigInt(accessHash);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
setUserAccessHash(id, accessHash) {
|
|
73
|
-
return this.set(`${this.userAccessHash__}${id}`, String(accessHash));
|
|
74
|
-
}
|
|
75
|
-
async getUserAccessHash(id) {
|
|
76
|
-
const accessHash = await this.get(`${this.userAccessHash__}${id}`);
|
|
77
|
-
if (accessHash != null) {
|
|
78
|
-
return BigInt(accessHash);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async updateUsernames(type, id, usernames) {
|
|
85
|
-
for (let username of usernames) {
|
|
86
|
-
username = username.toLowerCase();
|
|
87
|
-
await this.set(`${this.username__}${username}`, JSON.stringify([type, String(id), new Date()]));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async getUsername(username) {
|
|
91
|
-
username = username.toLowerCase();
|
|
92
|
-
const username_ = await this.get(`${this.username__}${username}`);
|
|
93
|
-
if (username_ != null) {
|
|
94
|
-
const [type, id, updatedAt] = JSON.parse(username_);
|
|
95
|
-
return [type, BigInt(id), new Date(updatedAt)];
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
42
|
}
|
|
102
43
|
exports.Storage = Storage;
|