teleproto 1.214.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/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { AuthKey } from "../crypto/AuthKey";
|
|
2
|
+
import type { EntityLike } from "../define";
|
|
3
|
+
import { Api } from "../tl";
|
|
4
|
+
export declare abstract class Session {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a clone of this session file
|
|
7
|
+
* @param toInstance {Session|null}
|
|
8
|
+
* @returns {Session}
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Sets the information of the data center address and port that
|
|
12
|
+
* the library should connect to, as well as the data center ID,
|
|
13
|
+
* which is currently unused.
|
|
14
|
+
* @param dcId {number}
|
|
15
|
+
* @param serverAddress {string}
|
|
16
|
+
* @param port {number}
|
|
17
|
+
*/
|
|
18
|
+
abstract setDC(dcId: number, serverAddress: string, port: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the currently-used data center ID.
|
|
21
|
+
*/
|
|
22
|
+
abstract get dcId(): number;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the server address where the library should connect to.
|
|
25
|
+
*/
|
|
26
|
+
abstract get serverAddress(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the port to which the library should connect to.
|
|
29
|
+
*/
|
|
30
|
+
abstract get port(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Returns an ``AuthKey`` instance associated with the saved
|
|
33
|
+
* data center, or `undefined` if a new one should be generated.
|
|
34
|
+
*/
|
|
35
|
+
abstract get authKey(): AuthKey | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the ``AuthKey`` to be used for the saved data center.
|
|
38
|
+
* @param value
|
|
39
|
+
*/
|
|
40
|
+
abstract set authKey(value: AuthKey | undefined);
|
|
41
|
+
/**
|
|
42
|
+
* Called before using the session
|
|
43
|
+
*/
|
|
44
|
+
abstract load(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* sets auth key for a dc
|
|
47
|
+
*/
|
|
48
|
+
abstract setAuthKey(authKey?: AuthKey, dcId?: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* gets auth key for a dc
|
|
51
|
+
*/
|
|
52
|
+
abstract getAuthKey(dcId?: number): AuthKey | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
|
|
55
|
+
* The library uses this method whenever an ``InputPeer`` is needed
|
|
56
|
+
* to suit several purposes (e.g. user only provided its ID or wishes
|
|
57
|
+
* to use a cached username to avoid extra RPC).
|
|
58
|
+
*/
|
|
59
|
+
abstract getInputEntity(key: EntityLike): Api.TypeInputPeer;
|
|
60
|
+
/**
|
|
61
|
+
* Returns an ID of the takeout process initialized for this session,
|
|
62
|
+
* or `None` if there's no were any unfinished takeout requests.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Sets the ID of the unfinished takeout process for this session.
|
|
66
|
+
* @param value
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Returns the ``UpdateState`` associated with the given `entity_id`.
|
|
70
|
+
* If the `entity_id` is 0, it should return the ``UpdateState`` for
|
|
71
|
+
* no specific channel (the "general" state). If no state is known
|
|
72
|
+
* it should ``return None``.
|
|
73
|
+
* @param entityId
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Sets the given ``UpdateState`` for the specified `entity_id`, which
|
|
77
|
+
* should be 0 if the ``UpdateState`` is the "general" state (and not
|
|
78
|
+
* for any specific channel).
|
|
79
|
+
* @param entityId
|
|
80
|
+
* @param state
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Called on client disconnection. Should be used to
|
|
84
|
+
* free any used resources. Can be left empty if none.
|
|
85
|
+
*/
|
|
86
|
+
abstract close(): void;
|
|
87
|
+
/**
|
|
88
|
+
* called whenever important properties change. It should
|
|
89
|
+
* make persist the relevant session information to disk.
|
|
90
|
+
*/
|
|
91
|
+
abstract save(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Called upon client.log_out(). Should delete the stored
|
|
94
|
+
* information from disk since it's not valid anymore.
|
|
95
|
+
*/
|
|
96
|
+
abstract delete(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Processes the input ``TLObject`` or ``list`` and saves
|
|
99
|
+
* whatever information is relevant (e.g., ID or access hash).
|
|
100
|
+
* @param tlo
|
|
101
|
+
*/
|
|
102
|
+
abstract processEntities(tlo: any): void;
|
|
103
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Session } from "./Abstract";
|
|
2
|
+
import type { AuthKey } from "../crypto/AuthKey";
|
|
3
|
+
import { Api } from "../tl";
|
|
4
|
+
import bigInt from "big-integer";
|
|
5
|
+
import type { EntityLike } from "../define";
|
|
6
|
+
export declare class MemorySession extends Session {
|
|
7
|
+
protected _serverAddress?: string;
|
|
8
|
+
protected _dcId: number;
|
|
9
|
+
protected _port?: number;
|
|
10
|
+
protected _takeoutId: undefined;
|
|
11
|
+
protected _entities: Set<any>;
|
|
12
|
+
protected _updateStates: {};
|
|
13
|
+
protected _authKey?: AuthKey;
|
|
14
|
+
constructor();
|
|
15
|
+
setDC(dcId: number, serverAddress: string, port: number): void;
|
|
16
|
+
get dcId(): number;
|
|
17
|
+
get serverAddress(): string;
|
|
18
|
+
get port(): number;
|
|
19
|
+
get authKey(): AuthKey | undefined;
|
|
20
|
+
set authKey(value: AuthKey | undefined);
|
|
21
|
+
get takeoutId(): undefined;
|
|
22
|
+
set takeoutId(value: undefined);
|
|
23
|
+
getAuthKey(dcId?: number): AuthKey | undefined;
|
|
24
|
+
setAuthKey(authKey?: AuthKey, dcId?: number): undefined;
|
|
25
|
+
close(): void;
|
|
26
|
+
save(): void;
|
|
27
|
+
load(): Promise<void>;
|
|
28
|
+
delete(): void;
|
|
29
|
+
_entityValuesToRow(id: bigInt.BigInteger | string, hash: bigInt.BigInteger | string, username: string, phone: string, name: string): (string | bigInt.BigInteger)[];
|
|
30
|
+
_entityToRow(e: any): (string | bigInt.BigInteger)[] | undefined;
|
|
31
|
+
_entitiesToRows(tlo: any): (string | bigInt.BigInteger)[][];
|
|
32
|
+
processEntities(tlo: any): void;
|
|
33
|
+
getEntityRowsByPhone(phone: string): any[] | undefined;
|
|
34
|
+
getEntityRowsByUsername(username: string): any[] | undefined;
|
|
35
|
+
getEntityRowsByName(name: string): any[] | undefined;
|
|
36
|
+
getEntityRowsById(id: string | bigInt.BigInteger, exact?: boolean): any[] | undefined;
|
|
37
|
+
getInputEntity(key: EntityLike): Api.TypeInputPeer;
|
|
38
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MemorySession = void 0;
|
|
7
|
+
const Abstract_1 = require("./Abstract");
|
|
8
|
+
const tl_1 = require("../tl");
|
|
9
|
+
const big_integer_1 = __importDefault(require("big-integer"));
|
|
10
|
+
const Utils_1 = require("../Utils");
|
|
11
|
+
const Helpers_1 = require("../Helpers");
|
|
12
|
+
const __1 = require("..");
|
|
13
|
+
class MemorySession extends Abstract_1.Session {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this._serverAddress = undefined;
|
|
17
|
+
this._dcId = 0;
|
|
18
|
+
this._port = undefined;
|
|
19
|
+
this._takeoutId = undefined;
|
|
20
|
+
this._entities = new Set();
|
|
21
|
+
this._updateStates = {};
|
|
22
|
+
}
|
|
23
|
+
setDC(dcId, serverAddress, port) {
|
|
24
|
+
this._dcId = dcId | 0;
|
|
25
|
+
this._serverAddress = serverAddress;
|
|
26
|
+
this._port = port;
|
|
27
|
+
}
|
|
28
|
+
get dcId() {
|
|
29
|
+
return this._dcId;
|
|
30
|
+
}
|
|
31
|
+
get serverAddress() {
|
|
32
|
+
return this._serverAddress;
|
|
33
|
+
}
|
|
34
|
+
get port() {
|
|
35
|
+
return this._port;
|
|
36
|
+
}
|
|
37
|
+
get authKey() {
|
|
38
|
+
return this._authKey;
|
|
39
|
+
}
|
|
40
|
+
set authKey(value) {
|
|
41
|
+
this._authKey = value;
|
|
42
|
+
}
|
|
43
|
+
get takeoutId() {
|
|
44
|
+
return this._takeoutId;
|
|
45
|
+
}
|
|
46
|
+
set takeoutId(value) {
|
|
47
|
+
this._takeoutId = value;
|
|
48
|
+
}
|
|
49
|
+
getAuthKey(dcId) {
|
|
50
|
+
if (dcId && dcId !== this.dcId) {
|
|
51
|
+
// Not supported.
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return this.authKey;
|
|
55
|
+
}
|
|
56
|
+
setAuthKey(authKey, dcId) {
|
|
57
|
+
if (dcId && dcId !== this.dcId) {
|
|
58
|
+
// Not supported.
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
this.authKey = authKey;
|
|
62
|
+
}
|
|
63
|
+
close() { }
|
|
64
|
+
save() { }
|
|
65
|
+
async load() { }
|
|
66
|
+
delete() { }
|
|
67
|
+
_entityValuesToRow(id, hash, username, phone, name) {
|
|
68
|
+
// While this is a simple implementation it might be overrode by,
|
|
69
|
+
// other classes so they don't need to implement the plural form
|
|
70
|
+
// of the method. Don't remove.
|
|
71
|
+
return [id, hash, username, phone, name];
|
|
72
|
+
}
|
|
73
|
+
_entityToRow(e) {
|
|
74
|
+
if (!(e.classType === "constructor")) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let p;
|
|
78
|
+
let markedId;
|
|
79
|
+
try {
|
|
80
|
+
p = (0, Utils_1.getInputPeer)(e, false);
|
|
81
|
+
markedId = (0, Utils_1.getPeerId)(p);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let pHash;
|
|
87
|
+
if (p instanceof tl_1.Api.InputPeerUser ||
|
|
88
|
+
p instanceof tl_1.Api.InputPeerChannel) {
|
|
89
|
+
pHash = p.accessHash;
|
|
90
|
+
}
|
|
91
|
+
else if (p instanceof tl_1.Api.InputPeerChat) {
|
|
92
|
+
pHash = big_integer_1.default.zero;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
let username = e.username;
|
|
98
|
+
if (username) {
|
|
99
|
+
username = username.toLowerCase();
|
|
100
|
+
}
|
|
101
|
+
const phone = e.phone;
|
|
102
|
+
const name = (0, Utils_1.getDisplayName)(e);
|
|
103
|
+
return this._entityValuesToRow(markedId, pHash, username, phone, name);
|
|
104
|
+
}
|
|
105
|
+
_entitiesToRows(tlo) {
|
|
106
|
+
let entities = [];
|
|
107
|
+
if (!(tlo.classType === "constructor") && (0, Helpers_1.isArrayLike)(tlo)) {
|
|
108
|
+
// This may be a list of users already for instance
|
|
109
|
+
entities = tlo;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (typeof tlo === "object") {
|
|
113
|
+
if ("user" in tlo) {
|
|
114
|
+
entities.push(tlo.user);
|
|
115
|
+
}
|
|
116
|
+
if ("chat" in tlo) {
|
|
117
|
+
entities.push(tlo.chat);
|
|
118
|
+
}
|
|
119
|
+
if ("channel" in tlo) {
|
|
120
|
+
entities.push(tlo.channel);
|
|
121
|
+
}
|
|
122
|
+
if ("chats" in tlo && (0, Helpers_1.isArrayLike)(tlo.chats)) {
|
|
123
|
+
entities = entities.concat(tlo.chats);
|
|
124
|
+
}
|
|
125
|
+
if ("users" in tlo && (0, Helpers_1.isArrayLike)(tlo.users)) {
|
|
126
|
+
entities = entities.concat(tlo.users);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const rows = []; // Rows to add (id, hash, username, phone, name)
|
|
131
|
+
for (const e of entities) {
|
|
132
|
+
const row = this._entityToRow(e);
|
|
133
|
+
if (row) {
|
|
134
|
+
rows.push(row);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return rows;
|
|
138
|
+
}
|
|
139
|
+
processEntities(tlo) {
|
|
140
|
+
const entitiesSet = this._entitiesToRows(tlo);
|
|
141
|
+
for (const e of entitiesSet) {
|
|
142
|
+
this._entities.add(e);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
getEntityRowsByPhone(phone) {
|
|
146
|
+
for (const e of this._entities) {
|
|
147
|
+
// id, hash, username, phone, name
|
|
148
|
+
if (e[3] === phone) {
|
|
149
|
+
return [e[0], e[1]];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getEntityRowsByUsername(username) {
|
|
154
|
+
for (const e of this._entities) {
|
|
155
|
+
// id, hash, username, phone, name
|
|
156
|
+
if (e[2] === username) {
|
|
157
|
+
return [e[0], e[1]];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getEntityRowsByName(name) {
|
|
162
|
+
for (const e of this._entities) {
|
|
163
|
+
// id, hash, username, phone, name
|
|
164
|
+
if (e[4] === name) {
|
|
165
|
+
return [e[0], e[1]];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
getEntityRowsById(id, exact = true) {
|
|
170
|
+
if (exact) {
|
|
171
|
+
for (const e of this._entities) {
|
|
172
|
+
// id, hash, username, phone, name
|
|
173
|
+
if (e[0] === id) {
|
|
174
|
+
return [e[0], e[1]];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const ids = [
|
|
180
|
+
__1.utils.getPeerId(new tl_1.Api.PeerUser({ userId: (0, Helpers_1.returnBigInt)(id) })),
|
|
181
|
+
__1.utils.getPeerId(new tl_1.Api.PeerChat({ chatId: (0, Helpers_1.returnBigInt)(id) })),
|
|
182
|
+
__1.utils.getPeerId(new tl_1.Api.PeerChannel({ channelId: (0, Helpers_1.returnBigInt)(id) })),
|
|
183
|
+
];
|
|
184
|
+
for (const e of this._entities) {
|
|
185
|
+
// id, hash, username, phone, name
|
|
186
|
+
if (ids.includes(e[0])) {
|
|
187
|
+
return [e[0], e[1]];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
getInputEntity(key) {
|
|
193
|
+
let exact;
|
|
194
|
+
if (typeof key === "object" &&
|
|
195
|
+
!big_integer_1.default.isInstance(key) &&
|
|
196
|
+
key.SUBCLASS_OF_ID) {
|
|
197
|
+
if (key.SUBCLASS_OF_ID == 0xc91c90b6 ||
|
|
198
|
+
key.SUBCLASS_OF_ID == 0xe669bf46 ||
|
|
199
|
+
key.SUBCLASS_OF_ID == 0x40f202fd) {
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
return key;
|
|
202
|
+
}
|
|
203
|
+
// Try to early return if this key can be casted as input peer
|
|
204
|
+
return __1.utils.getInputPeer(key);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Not a TLObject or can't be cast into InputPeer
|
|
208
|
+
if (typeof key === "object") {
|
|
209
|
+
key = __1.utils.getPeerId(key);
|
|
210
|
+
exact = true;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
exact = false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (big_integer_1.default.isInstance(key) ||
|
|
217
|
+
typeof key == "bigint" ||
|
|
218
|
+
typeof key == "number") {
|
|
219
|
+
key = key.toString();
|
|
220
|
+
}
|
|
221
|
+
let result = undefined;
|
|
222
|
+
if (typeof key === "string") {
|
|
223
|
+
const phone = __1.utils.parsePhone(key);
|
|
224
|
+
if (phone) {
|
|
225
|
+
result = this.getEntityRowsByPhone(phone);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
const { username, isInvite } = __1.utils.parseUsername(key);
|
|
229
|
+
if (username && !isInvite) {
|
|
230
|
+
result = this.getEntityRowsByUsername(username);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!result) {
|
|
234
|
+
const id = __1.utils.parseID(key);
|
|
235
|
+
if (id) {
|
|
236
|
+
result = this.getEntityRowsById(id, exact);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (!result) {
|
|
240
|
+
result = this.getEntityRowsByName(key);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (result) {
|
|
244
|
+
let entityId = result[0]; // unpack resulting tuple
|
|
245
|
+
const entityHash = (0, big_integer_1.default)(result[1]);
|
|
246
|
+
const resolved = __1.utils.resolveId((0, Helpers_1.returnBigInt)(entityId));
|
|
247
|
+
entityId = resolved[0];
|
|
248
|
+
const kind = resolved[1];
|
|
249
|
+
// removes the mark and returns type of entity
|
|
250
|
+
if (kind === tl_1.Api.PeerUser) {
|
|
251
|
+
return new tl_1.Api.InputPeerUser({
|
|
252
|
+
userId: entityId,
|
|
253
|
+
accessHash: entityHash,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else if (kind === tl_1.Api.PeerChat) {
|
|
257
|
+
return new tl_1.Api.InputPeerChat({ chatId: entityId });
|
|
258
|
+
}
|
|
259
|
+
else if (kind === tl_1.Api.PeerChannel) {
|
|
260
|
+
return new tl_1.Api.InputPeerChannel({
|
|
261
|
+
channelId: entityId,
|
|
262
|
+
accessHash: entityHash,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
throw new Error("Could not find input entity with key " + key);
|
|
268
|
+
}
|
|
269
|
+
throw new Error("Could not find input entity with key " + key);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.MemorySession = MemorySession;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MemorySession } from "./Memory";
|
|
2
|
+
import { AuthKey } from "../crypto/AuthKey";
|
|
3
|
+
import bigInt from "big-integer";
|
|
4
|
+
export declare class StoreSession extends MemorySession {
|
|
5
|
+
private readonly sessionName;
|
|
6
|
+
private store;
|
|
7
|
+
constructor(sessionName: string, divider?: string);
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
setDC(dcId: number, serverAddress: string, port: number): void;
|
|
10
|
+
set authKey(value: AuthKey | undefined);
|
|
11
|
+
get authKey(): AuthKey | undefined;
|
|
12
|
+
processEntities(tlo: any): void;
|
|
13
|
+
getEntityRowsById(id: string | bigInt.BigInteger, exact?: boolean): any;
|
|
14
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StoreSession = void 0;
|
|
7
|
+
const Memory_1 = require("./Memory");
|
|
8
|
+
const store2_1 = __importDefault(require("store2"));
|
|
9
|
+
const AuthKey_1 = require("../crypto/AuthKey");
|
|
10
|
+
class StoreSession extends Memory_1.MemorySession {
|
|
11
|
+
constructor(sessionName, divider = ":") {
|
|
12
|
+
super();
|
|
13
|
+
if (sessionName === "session") {
|
|
14
|
+
throw new Error("Session name can't be 'session'. Please use a different name.");
|
|
15
|
+
}
|
|
16
|
+
if (typeof localStorage === "undefined" || localStorage === null) {
|
|
17
|
+
const LocalStorage = require("./localStorage").LocalStorage;
|
|
18
|
+
this.store = store2_1.default.area(sessionName, new LocalStorage("./" + sessionName));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.store = store2_1.default.area(sessionName, localStorage);
|
|
22
|
+
}
|
|
23
|
+
if (divider == undefined) {
|
|
24
|
+
divider = ":";
|
|
25
|
+
}
|
|
26
|
+
this.sessionName = sessionName + divider;
|
|
27
|
+
}
|
|
28
|
+
async load() {
|
|
29
|
+
let authKey = this.store.get(this.sessionName + "authKey");
|
|
30
|
+
if (authKey && typeof authKey === "object") {
|
|
31
|
+
this._authKey = new AuthKey_1.AuthKey();
|
|
32
|
+
if ("data" in authKey) {
|
|
33
|
+
authKey = Buffer.from(authKey.data);
|
|
34
|
+
}
|
|
35
|
+
await this._authKey.setKey(authKey);
|
|
36
|
+
}
|
|
37
|
+
const dcId = this.store.get(this.sessionName + "dcId");
|
|
38
|
+
if (dcId) {
|
|
39
|
+
this._dcId = dcId;
|
|
40
|
+
}
|
|
41
|
+
const port = this.store.get(this.sessionName + "port");
|
|
42
|
+
if (port) {
|
|
43
|
+
this._port = port;
|
|
44
|
+
}
|
|
45
|
+
const serverAddress = this.store.get(this.sessionName + "serverAddress");
|
|
46
|
+
if (serverAddress) {
|
|
47
|
+
this._serverAddress = serverAddress;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
setDC(dcId, serverAddress, port) {
|
|
51
|
+
this.store.set(this.sessionName + "dcId", dcId);
|
|
52
|
+
this.store.set(this.sessionName + "port", port);
|
|
53
|
+
this.store.set(this.sessionName + "serverAddress", serverAddress);
|
|
54
|
+
super.setDC(dcId, serverAddress, port);
|
|
55
|
+
}
|
|
56
|
+
set authKey(value) {
|
|
57
|
+
this._authKey = value;
|
|
58
|
+
this.store.set(this.sessionName + "authKey", value === null || value === void 0 ? void 0 : value.getKey());
|
|
59
|
+
}
|
|
60
|
+
get authKey() {
|
|
61
|
+
return this._authKey;
|
|
62
|
+
}
|
|
63
|
+
processEntities(tlo) {
|
|
64
|
+
const rows = this._entitiesToRows(tlo);
|
|
65
|
+
if (!rows) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const row of rows) {
|
|
69
|
+
row.push(new Date().getTime().toString());
|
|
70
|
+
this.store.set(this.sessionName + row[0], row);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getEntityRowsById(id, exact = true) {
|
|
74
|
+
return this.store.get(this.sessionName + id.toString());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.StoreSession = StoreSession;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MemorySession } from "./Memory";
|
|
2
|
+
export declare class StringSession extends MemorySession {
|
|
3
|
+
_key?: Buffer;
|
|
4
|
+
/**
|
|
5
|
+
* This session file can be easily saved and loaded as a string. According
|
|
6
|
+
* to the initial design, it contains only the data that is necessary for
|
|
7
|
+
* successful connection and authentication, so takeout ID is not stored.
|
|
8
|
+
|
|
9
|
+
* It is thought to be used where you don't want to create any on-disk
|
|
10
|
+
* files but would still like to be able to save and load existing sessions
|
|
11
|
+
* by other means.
|
|
12
|
+
|
|
13
|
+
* You can use custom `encode` and `decode` functions, if present:
|
|
14
|
+
|
|
15
|
+
* `encode` definition must be ``function encode(value: Buffer) -> string:``.
|
|
16
|
+
* `decode` definition must be ``function decode(value: string) -> Buffer:``.
|
|
17
|
+
* @param session {string|null}
|
|
18
|
+
*/
|
|
19
|
+
constructor(session?: string);
|
|
20
|
+
/**
|
|
21
|
+
* @param x {Buffer}
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
static encode(x: Buffer): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param x {string}
|
|
27
|
+
* @returns {Buffer}
|
|
28
|
+
*/
|
|
29
|
+
static decode(x: string): Buffer<ArrayBuffer>;
|
|
30
|
+
load(): Promise<void>;
|
|
31
|
+
save(): string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringSession = void 0;
|
|
4
|
+
const Memory_1 = require("./Memory");
|
|
5
|
+
const extensions_1 = require("../extensions");
|
|
6
|
+
const AuthKey_1 = require("../crypto/AuthKey");
|
|
7
|
+
const CURRENT_VERSION = "1";
|
|
8
|
+
class StringSession extends Memory_1.MemorySession {
|
|
9
|
+
/**
|
|
10
|
+
* This session file can be easily saved and loaded as a string. According
|
|
11
|
+
* to the initial design, it contains only the data that is necessary for
|
|
12
|
+
* successful connection and authentication, so takeout ID is not stored.
|
|
13
|
+
|
|
14
|
+
* It is thought to be used where you don't want to create any on-disk
|
|
15
|
+
* files but would still like to be able to save and load existing sessions
|
|
16
|
+
* by other means.
|
|
17
|
+
|
|
18
|
+
* You can use custom `encode` and `decode` functions, if present:
|
|
19
|
+
|
|
20
|
+
* `encode` definition must be ``function encode(value: Buffer) -> string:``.
|
|
21
|
+
* `decode` definition must be ``function decode(value: string) -> Buffer:``.
|
|
22
|
+
* @param session {string|null}
|
|
23
|
+
*/
|
|
24
|
+
constructor(session) {
|
|
25
|
+
super();
|
|
26
|
+
if (session) {
|
|
27
|
+
if (session[0] !== CURRENT_VERSION) {
|
|
28
|
+
throw new Error("Not a valid string");
|
|
29
|
+
}
|
|
30
|
+
session = session.slice(1);
|
|
31
|
+
const r = StringSession.decode(session);
|
|
32
|
+
const reader = new extensions_1.BinaryReader(r);
|
|
33
|
+
this._dcId = reader.read(1).readUInt8(0);
|
|
34
|
+
if (session.length == 352) {
|
|
35
|
+
// Telethon session
|
|
36
|
+
const ip_v4 = reader.read(4);
|
|
37
|
+
// TODO looks ugly smh
|
|
38
|
+
this._serverAddress =
|
|
39
|
+
ip_v4[0].toString() +
|
|
40
|
+
"." +
|
|
41
|
+
ip_v4[1].toString() +
|
|
42
|
+
"." +
|
|
43
|
+
ip_v4[2].toString() +
|
|
44
|
+
"." +
|
|
45
|
+
ip_v4[3].toString();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// TODO find a better of doing this
|
|
49
|
+
const serverAddressLen = reader.read(2).readInt16BE(0);
|
|
50
|
+
if (serverAddressLen > 100) {
|
|
51
|
+
reader.offset -= 2;
|
|
52
|
+
this._serverAddress = reader
|
|
53
|
+
.read(16)
|
|
54
|
+
.toString("hex")
|
|
55
|
+
.match(/.{1,4}/g)
|
|
56
|
+
.map((val) => val.replace(/^0+/, ""))
|
|
57
|
+
.join(":")
|
|
58
|
+
.replace(/0000\:/g, ":")
|
|
59
|
+
.replace(/:{2,}/g, "::");
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this._serverAddress = reader
|
|
63
|
+
.read(serverAddressLen)
|
|
64
|
+
.toString();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
this._port = reader.read(2).readInt16BE(0);
|
|
68
|
+
this._key = reader.read(-1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @param x {Buffer}
|
|
73
|
+
* @returns {string}
|
|
74
|
+
*/
|
|
75
|
+
static encode(x) {
|
|
76
|
+
return x.toString("base64");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @param x {string}
|
|
80
|
+
* @returns {Buffer}
|
|
81
|
+
*/
|
|
82
|
+
static decode(x) {
|
|
83
|
+
return Buffer.from(x, "base64");
|
|
84
|
+
}
|
|
85
|
+
async load() {
|
|
86
|
+
if (this._key) {
|
|
87
|
+
this._authKey = new AuthKey_1.AuthKey();
|
|
88
|
+
await this._authKey.setKey(this._key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
save() {
|
|
92
|
+
if (!this.authKey || !this.serverAddress || !this.port) {
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
// TS is weird
|
|
96
|
+
const key = this.authKey.getKey();
|
|
97
|
+
if (!key) {
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
const dcBuffer = Buffer.from([this.dcId]);
|
|
101
|
+
const addressBuffer = Buffer.from(this.serverAddress);
|
|
102
|
+
const addressLengthBuffer = Buffer.alloc(2);
|
|
103
|
+
addressLengthBuffer.writeInt16BE(addressBuffer.length, 0);
|
|
104
|
+
const portBuffer = Buffer.alloc(2);
|
|
105
|
+
portBuffer.writeInt16BE(this.port, 0);
|
|
106
|
+
return (CURRENT_VERSION +
|
|
107
|
+
StringSession.encode(Buffer.concat([
|
|
108
|
+
dcBuffer,
|
|
109
|
+
addressLengthBuffer,
|
|
110
|
+
addressBuffer,
|
|
111
|
+
portBuffer,
|
|
112
|
+
key,
|
|
113
|
+
])));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.StringSession = StringSession;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Session = exports.StoreSession = exports.StringSession = exports.MemorySession = void 0;
|
|
4
|
+
var Memory_1 = require("./Memory");
|
|
5
|
+
Object.defineProperty(exports, "MemorySession", { enumerable: true, get: function () { return Memory_1.MemorySession; } });
|
|
6
|
+
var StringSession_1 = require("./StringSession");
|
|
7
|
+
Object.defineProperty(exports, "StringSession", { enumerable: true, get: function () { return StringSession_1.StringSession; } });
|
|
8
|
+
var StoreSession_1 = require("./StoreSession");
|
|
9
|
+
Object.defineProperty(exports, "StoreSession", { enumerable: true, get: function () { return StoreSession_1.StoreSession; } });
|
|
10
|
+
var Abstract_1 = require("./Abstract");
|
|
11
|
+
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return Abstract_1.Session; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LocalStorage: any;
|