@armatofik/tgsnake-core 1.0.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/COPYING +674 -0
- package/COPYING.lesser +165 -0
- package/README.md +88 -0
- package/lib/package.json +46 -0
- package/lib/src/Logger.d.ts +3 -0
- package/lib/src/Logger.js +9 -0
- package/lib/src/Queue.d.ts +19 -0
- package/lib/src/Queue.js +52 -0
- package/lib/src/Timeout.d.ts +9 -0
- package/lib/src/Timeout.js +44 -0
- package/lib/src/Version.node.d.ts +4 -0
- package/lib/src/Version.node.js +26 -0
- package/lib/src/client/Auth.d.ts +40 -0
- package/lib/src/client/Auth.js +317 -0
- package/lib/src/client/Client.d.ts +83 -0
- package/lib/src/client/Client.js +461 -0
- package/lib/src/client/Session.d.ts +9 -0
- package/lib/src/client/Session.js +132 -0
- package/lib/src/client/index.d.ts +3 -0
- package/lib/src/client/index.js +39 -0
- package/lib/src/connection/TCP/TCPAbridged.d.ts +9 -0
- package/lib/src/connection/TCP/TCPAbridged.js +47 -0
- package/lib/src/connection/TCP/TCPAbridgedO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPAbridgedO.js +140 -0
- package/lib/src/connection/TCP/TCPFull.d.ts +10 -0
- package/lib/src/connection/TCP/TCPFull.js +43 -0
- package/lib/src/connection/TCP/TCPIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPIntermediate.js +31 -0
- package/lib/src/connection/TCP/TCPIntermediateO.d.ts +12 -0
- package/lib/src/connection/TCP/TCPIntermediateO.js +123 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.d.ts +9 -0
- package/lib/src/connection/TCP/TCPPaddedIntermediate.js +38 -0
- package/lib/src/connection/TCP/index.d.ts +7 -0
- package/lib/src/connection/TCP/index.js +17 -0
- package/lib/src/connection/TCP/tcp.d.ts +17 -0
- package/lib/src/connection/TCP/tcp.js +98 -0
- package/lib/src/connection/WebSocket.d.ts +21 -0
- package/lib/src/connection/WebSocket.js +279 -0
- package/lib/src/connection/connection.d.ts +53 -0
- package/lib/src/connection/connection.js +189 -0
- package/lib/src/connection/index.d.ts +4 -0
- package/lib/src/connection/index.js +41 -0
- package/lib/src/crypto/Aes.d.ts +10 -0
- package/lib/src/crypto/Aes.js +135 -0
- package/lib/src/crypto/Mtproto.d.ts +5 -0
- package/lib/src/crypto/Mtproto.js +123 -0
- package/lib/src/crypto/Password.d.ts +5 -0
- package/lib/src/crypto/Password.js +92 -0
- package/lib/src/crypto/Prime.d.ts +4 -0
- package/lib/src/crypto/Prime.js +64 -0
- package/lib/src/crypto/RSA.d.ts +7 -0
- package/lib/src/crypto/RSA.js +99 -0
- package/lib/src/crypto/SecretChat.d.ts +5 -0
- package/lib/src/crypto/SecretChat.js +136 -0
- package/lib/src/crypto/index.d.ts +6 -0
- package/lib/src/crypto/index.js +42 -0
- package/lib/src/errors/Base.d.ts +9 -0
- package/lib/src/errors/Base.js +50 -0
- package/lib/src/errors/Client.d.ts +21 -0
- package/lib/src/errors/Client.js +29 -0
- package/lib/src/errors/File.d.ts +13 -0
- package/lib/src/errors/File.js +30 -0
- package/lib/src/errors/RpcError.d.ts +22 -0
- package/lib/src/errors/RpcError.js +120 -0
- package/lib/src/errors/SecretChat.d.ts +13 -0
- package/lib/src/errors/SecretChat.js +30 -0
- package/lib/src/errors/WebSocket.d.ts +13 -0
- package/lib/src/errors/WebSocket.js +30 -0
- package/lib/src/errors/exceptions/All.d.ts +774 -0
- package/lib/src/errors/exceptions/All.js +778 -0
- package/lib/src/errors/exceptions/BadRequest400.d.ts +2345 -0
- package/lib/src/errors/exceptions/BadRequest400.js +2945 -0
- package/lib/src/errors/exceptions/Flood420.d.ts +37 -0
- package/lib/src/errors/exceptions/Flood420.js +49 -0
- package/lib/src/errors/exceptions/Forbidden403.d.ts +205 -0
- package/lib/src/errors/exceptions/Forbidden403.js +260 -0
- package/lib/src/errors/exceptions/InternalServerError500.d.ts +221 -0
- package/lib/src/errors/exceptions/InternalServerError500.js +280 -0
- package/lib/src/errors/exceptions/NotAcceptable406.d.ts +117 -0
- package/lib/src/errors/exceptions/NotAcceptable406.js +149 -0
- package/lib/src/errors/exceptions/NotFound404.d.ts +9 -0
- package/lib/src/errors/exceptions/NotFound404.js +14 -0
- package/lib/src/errors/exceptions/SeeOther303.d.ts +25 -0
- package/lib/src/errors/exceptions/SeeOther303.js +34 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.d.ts +17 -0
- package/lib/src/errors/exceptions/ServiceUnavailable503.js +24 -0
- package/lib/src/errors/exceptions/Unauthorized401.d.ts +41 -0
- package/lib/src/errors/exceptions/Unauthorized401.js +54 -0
- package/lib/src/errors/exceptions/index.d.ts +10 -0
- package/lib/src/errors/exceptions/index.js +48 -0
- package/lib/src/errors/index.d.ts +31 -0
- package/lib/src/errors/index.js +111 -0
- package/lib/src/file/Download.d.ts +11 -0
- package/lib/src/file/Download.js +118 -0
- package/lib/src/file/File.d.ts +20 -0
- package/lib/src/file/File.js +82 -0
- package/lib/src/file/Upload.d.ts +19 -0
- package/lib/src/file/Upload.js +250 -0
- package/lib/src/file/index.d.ts +3 -0
- package/lib/src/file/index.js +11 -0
- package/lib/src/helpers.d.ts +34 -0
- package/lib/src/helpers.js +358 -0
- package/lib/src/index.d.ts +16 -0
- package/lib/src/index.js +56 -0
- package/lib/src/platform.node.d.ts +36 -0
- package/lib/src/platform.node.js +109 -0
- package/lib/src/raw/All.d.ts +2400 -0
- package/lib/src/raw/All.js +2403 -0
- package/lib/src/raw/Raw.d.ts +29195 -0
- package/lib/src/raw/Raw.js +97277 -0
- package/lib/src/raw/core/BytesIO.d.ts +33 -0
- package/lib/src/raw/core/BytesIO.js +145 -0
- package/lib/src/raw/core/GzipPacked.d.ts +10 -0
- package/lib/src/raw/core/GzipPacked.js +60 -0
- package/lib/src/raw/core/Message.d.ts +13 -0
- package/lib/src/raw/core/Message.js +81 -0
- package/lib/src/raw/core/MsgContainer.d.ts +11 -0
- package/lib/src/raw/core/MsgContainer.js +69 -0
- package/lib/src/raw/core/TLObject.d.ts +19 -0
- package/lib/src/raw/core/TLObject.js +108 -0
- package/lib/src/raw/core/UpdateSecretChat.d.ts +40 -0
- package/lib/src/raw/core/UpdateSecretChat.js +88 -0
- package/lib/src/raw/core/index.d.ts +8 -0
- package/lib/src/raw/core/index.js +52 -0
- package/lib/src/raw/core/primitive/Bool.d.ts +20 -0
- package/lib/src/raw/core/primitive/Bool.js +41 -0
- package/lib/src/raw/core/primitive/Bytes.d.ts +7 -0
- package/lib/src/raw/core/primitive/Bytes.js +41 -0
- package/lib/src/raw/core/primitive/Double.d.ts +7 -0
- package/lib/src/raw/core/primitive/Double.js +24 -0
- package/lib/src/raw/core/primitive/Float.d.ts +7 -0
- package/lib/src/raw/core/primitive/Float.js +24 -0
- package/lib/src/raw/core/primitive/Int.d.ts +23 -0
- package/lib/src/raw/core/primitive/Int.js +122 -0
- package/lib/src/raw/core/primitive/String.d.ts +7 -0
- package/lib/src/raw/core/primitive/String.js +15 -0
- package/lib/src/raw/core/primitive/Vector.d.ts +9 -0
- package/lib/src/raw/core/primitive/Vector.js +50 -0
- package/lib/src/raw/core/primitive/index.d.ts +7 -0
- package/lib/src/raw/core/primitive/index.js +22 -0
- package/lib/src/raw/index.d.ts +3 -0
- package/lib/src/raw/index.js +17 -0
- package/lib/src/session/Auth.d.ts +15 -0
- package/lib/src/session/Auth.js +254 -0
- package/lib/src/session/Session.d.ts +58 -0
- package/lib/src/session/Session.js +571 -0
- package/lib/src/session/index.d.ts +7 -0
- package/lib/src/session/index.js +49 -0
- package/lib/src/session/internals/DataCenter.d.ts +42 -0
- package/lib/src/session/internals/DataCenter.js +80 -0
- package/lib/src/session/internals/MsgFactory.d.ts +3 -0
- package/lib/src/session/internals/MsgFactory.js +23 -0
- package/lib/src/session/internals/MsgId.d.ts +9 -0
- package/lib/src/session/internals/MsgId.js +24 -0
- package/lib/src/session/internals/SeqNo.d.ts +6 -0
- package/lib/src/session/internals/SeqNo.js +18 -0
- package/lib/src/session/secretChats/SecretChat.d.ts +29 -0
- package/lib/src/session/secretChats/SecretChat.js +527 -0
- package/lib/src/session/secretChats/index.d.ts +1 -0
- package/lib/src/session/secretChats/index.js +5 -0
- package/lib/src/storage/Abstract.d.ts +68 -0
- package/lib/src/storage/Abstract.js +6 -0
- package/lib/src/storage/SecretChat.d.ts +42 -0
- package/lib/src/storage/SecretChat.js +99 -0
- package/lib/src/storage/Session.d.ts +63 -0
- package/lib/src/storage/Session.js +245 -0
- package/lib/src/storage/StringSession.d.ts +4 -0
- package/lib/src/storage/StringSession.js +77 -0
- package/lib/src/storage/index.d.ts +4 -0
- package/lib/src/storage/index.js +12 -0
- package/package.json +46 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DCProdMediaIPV6 = exports.DCProdIPV6 = exports.DCTestIPV6 = exports.DCProdMedia = exports.WebDC = exports.DCProd = exports.DCTest = void 0;
|
|
4
|
+
exports.DataCenter = DataCenter;
|
|
5
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
6
|
+
exports.DCTest = {
|
|
7
|
+
1: '149.154.175.10',
|
|
8
|
+
2: '149.154.167.40',
|
|
9
|
+
3: '149.154.175.117',
|
|
10
|
+
};
|
|
11
|
+
exports.DCProd = {
|
|
12
|
+
1: '149.154.175.53',
|
|
13
|
+
2: '149.154.167.51',
|
|
14
|
+
3: '149.154.175.100',
|
|
15
|
+
4: '149.154.167.91',
|
|
16
|
+
5: '91.108.56.130',
|
|
17
|
+
203: '91.105.192.100',
|
|
18
|
+
};
|
|
19
|
+
exports.WebDC = {
|
|
20
|
+
1: 'pluto.web.telegram.org',
|
|
21
|
+
2: 'venus.web.telegram.org',
|
|
22
|
+
3: 'aurora.web.telegram.org',
|
|
23
|
+
4: 'vesta.web.telegram.org',
|
|
24
|
+
5: 'flora.web.telegram.org',
|
|
25
|
+
};
|
|
26
|
+
exports.DCProdMedia = {
|
|
27
|
+
2: '149.154.167.151',
|
|
28
|
+
4: '149.154.164.250',
|
|
29
|
+
};
|
|
30
|
+
exports.DCTestIPV6 = {
|
|
31
|
+
1: '2001:b28:f23d:f001::e',
|
|
32
|
+
2: '2001:67c:4e8:f002::e',
|
|
33
|
+
3: '2001:b28:f23d:f003::e',
|
|
34
|
+
};
|
|
35
|
+
exports.DCProdIPV6 = {
|
|
36
|
+
1: '2001:b28:f23d:f001::a',
|
|
37
|
+
2: '2001:67c:4e8:f002::a',
|
|
38
|
+
3: '2001:b28:f23d:f003::a',
|
|
39
|
+
4: '2001:67c:4e8:f004::a',
|
|
40
|
+
5: '2001:b28:f23f:f005::a',
|
|
41
|
+
203: '2a0a:f280:0203:000a:5000:0000:0000:0100',
|
|
42
|
+
};
|
|
43
|
+
exports.DCProdMediaIPV6 = {
|
|
44
|
+
2: '2001:067c:04e8:f002:0000:0000:0000:000b',
|
|
45
|
+
4: '2001:067c:04e8:f004:0000:0000:0000:000b',
|
|
46
|
+
};
|
|
47
|
+
function DataCenter(dcId, testMode, ipv6, media) {
|
|
48
|
+
if (platform_node_js_1.isBrowser) {
|
|
49
|
+
return [
|
|
50
|
+
`${exports.WebDC[dcId]}:$PORT/apiws${testMode ? '_test' : ''}`,
|
|
51
|
+
443,
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (testMode) {
|
|
56
|
+
return [
|
|
57
|
+
ipv6 ? exports.DCTestIPV6[dcId] : exports.DCTest[dcId],
|
|
58
|
+
80,
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (media) {
|
|
63
|
+
return [
|
|
64
|
+
ipv6
|
|
65
|
+
? (exports.DCProdMediaIPV6[dcId] ??
|
|
66
|
+
exports.DCProdIPV6[dcId])
|
|
67
|
+
: (exports.DCProdMedia[dcId] ??
|
|
68
|
+
exports.DCProd[dcId]),
|
|
69
|
+
443,
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return [
|
|
74
|
+
ipv6 ? exports.DCProdIPV6[dcId] : exports.DCProd[dcId],
|
|
75
|
+
443,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsgFactory = MsgFactory;
|
|
4
|
+
const SeqNo_js_1 = require("./SeqNo.js");
|
|
5
|
+
const index_js_1 = require("../../raw/index.js");
|
|
6
|
+
const platform_node_js_1 = require("../../platform.node.js");
|
|
7
|
+
function MsgFactory() {
|
|
8
|
+
const seqNo = new SeqNo_js_1.SeqNo();
|
|
9
|
+
const notRelatedContent = (content) => {
|
|
10
|
+
if (content instanceof index_js_1.Raw.Ping)
|
|
11
|
+
return true;
|
|
12
|
+
if (content instanceof index_js_1.Raw.HttpWait)
|
|
13
|
+
return true;
|
|
14
|
+
if (content instanceof index_js_1.Raw.MsgsAck)
|
|
15
|
+
return true;
|
|
16
|
+
if (content instanceof index_js_1.MsgContainer)
|
|
17
|
+
return true;
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
return (body, msgId) => {
|
|
21
|
+
return new index_js_1.Message(body, BigInt(msgId.getMsgId()), seqNo.getSeqNo(!notRelatedContent(body)), platform_node_js_1.Buffer.byteLength(body.write()));
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsgId = void 0;
|
|
4
|
+
class MsgId {
|
|
5
|
+
referenceClock = BigInt(0);
|
|
6
|
+
lastTime = BigInt(0);
|
|
7
|
+
msgIdOffset = BigInt(0);
|
|
8
|
+
serverTime = BigInt(0);
|
|
9
|
+
constructor() { }
|
|
10
|
+
getMsgId() {
|
|
11
|
+
const now = BigInt(Math.floor(Date.now() / 1000)) - this.referenceClock + this.serverTime;
|
|
12
|
+
this.msgIdOffset = now === this.lastTime ? this.msgIdOffset + BigInt(4) : BigInt(0);
|
|
13
|
+
const msgId = now * BigInt(2 ** 32) + this.msgIdOffset;
|
|
14
|
+
this.lastTime = now;
|
|
15
|
+
return msgId;
|
|
16
|
+
}
|
|
17
|
+
setServerTime(serverTime) {
|
|
18
|
+
if (!this.serverTime) {
|
|
19
|
+
this.referenceClock = BigInt(Math.floor(Date.now() / 1000));
|
|
20
|
+
this.serverTime = serverTime;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MsgId = MsgId;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeqNo = void 0;
|
|
4
|
+
class SeqNo {
|
|
5
|
+
contentRMsgSend;
|
|
6
|
+
seqNo;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.contentRMsgSend = 0;
|
|
9
|
+
this.seqNo = 0;
|
|
10
|
+
}
|
|
11
|
+
getSeqNo(isContentRelated) {
|
|
12
|
+
this.seqNo = this.contentRMsgSend * 2 + (isContentRelated ? 1 : 0);
|
|
13
|
+
if (isContentRelated)
|
|
14
|
+
this.contentRMsgSend += 1;
|
|
15
|
+
return this.seqNo;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.SeqNo = SeqNo;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Raw } from '../../raw/index.js';
|
|
2
|
+
import { type AbstractSession } from '../../storage/index.js';
|
|
3
|
+
import { Buffer } from '../../platform.node.js';
|
|
4
|
+
import type { Client } from '../../client/Client.js';
|
|
5
|
+
export declare class SecretChat {
|
|
6
|
+
private _storage;
|
|
7
|
+
private _client;
|
|
8
|
+
private _dhConfig;
|
|
9
|
+
private _mutex;
|
|
10
|
+
private _tempAuthKey;
|
|
11
|
+
private _waiting;
|
|
12
|
+
constructor(storage: AbstractSession, client: Client);
|
|
13
|
+
private reqDHConfig;
|
|
14
|
+
start(userId: bigint | string): Promise<Raw.TypeEncryptedChat>;
|
|
15
|
+
accept(request: Raw.EncryptedChatRequested): Promise<Raw.TypeEncryptedChat>;
|
|
16
|
+
finish(chat: Raw.EncryptedChat): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
|
|
17
|
+
notifyLayer(chatId: number): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
|
|
18
|
+
destroy(chatId: number): Promise<boolean>;
|
|
19
|
+
rekeying(chatId: number): Promise<Raw.messages.TypeSentEncryptedMessage>;
|
|
20
|
+
acceptRekeying(chatId: number, action: Raw.DecryptedMessageActionRequestKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
|
|
21
|
+
commitRekeying(chatId: number, action: Raw.DecryptedMessageActionAcceptKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
|
|
22
|
+
finalRekeying(chatId: number, action: Raw.DecryptedMessageActionCommitKey20): Promise<Raw.messages.TypeSentEncryptedMessage | undefined>;
|
|
23
|
+
decrypt(message: Raw.TypeEncryptedMessage): Promise<any>;
|
|
24
|
+
encrypt(chatId: number, message: Raw.TypeDecryptedMessage): Promise<Buffer<ArrayBufferLike>>;
|
|
25
|
+
toJSON(): {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
toString(): string;
|
|
29
|
+
}
|