@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,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kdf = kdf;
|
|
4
|
+
exports.pack = pack;
|
|
5
|
+
exports.unpack = unpack;
|
|
6
|
+
const platform_node_js_1 = require("../platform.node.js");
|
|
7
|
+
const index_js_1 = require("../errors/index.js");
|
|
8
|
+
const index_js_2 = require("../raw/index.js");
|
|
9
|
+
const helpers_js_1 = require("../helpers.js");
|
|
10
|
+
const Aes_js_1 = require("./Aes.js");
|
|
11
|
+
const index_js_3 = require("../raw/index.js");
|
|
12
|
+
function sha256(data) {
|
|
13
|
+
const hash = platform_node_js_1.crypto.createHash('sha256');
|
|
14
|
+
hash.update(data);
|
|
15
|
+
return hash.digest();
|
|
16
|
+
}
|
|
17
|
+
function sha1(data) {
|
|
18
|
+
const hash = platform_node_js_1.crypto.createHash('sha1');
|
|
19
|
+
hash.update(data);
|
|
20
|
+
return hash.digest();
|
|
21
|
+
}
|
|
22
|
+
function kdf(sharedKey, msgKey, isAdmin, v1 = false) {
|
|
23
|
+
const x = isAdmin ? 0 : 8;
|
|
24
|
+
if (v1) {
|
|
25
|
+
const sha1A = sha1(platform_node_js_1.Buffer.concat([
|
|
26
|
+
msgKey,
|
|
27
|
+
sharedKey.subarray(x, x + 32),
|
|
28
|
+
]));
|
|
29
|
+
const sha1B = sha1(platform_node_js_1.Buffer.concat([
|
|
30
|
+
sharedKey.subarray(x + 32, x + 48),
|
|
31
|
+
msgKey,
|
|
32
|
+
sharedKey.subarray(x + 48, x + 64),
|
|
33
|
+
]));
|
|
34
|
+
const sha1C = sha1(platform_node_js_1.Buffer.concat([
|
|
35
|
+
sharedKey.subarray(x + 64, x + 96),
|
|
36
|
+
msgKey,
|
|
37
|
+
]));
|
|
38
|
+
const sha1D = sha1(platform_node_js_1.Buffer.concat([
|
|
39
|
+
msgKey,
|
|
40
|
+
sharedKey.subarray(x + 96, x + 128),
|
|
41
|
+
]));
|
|
42
|
+
const aesKey = platform_node_js_1.Buffer.concat([
|
|
43
|
+
sha1A.subarray(0, 8),
|
|
44
|
+
sha1B.subarray(8, 20),
|
|
45
|
+
sha1C.subarray(4, 16),
|
|
46
|
+
]);
|
|
47
|
+
const aesIv = platform_node_js_1.Buffer.concat([
|
|
48
|
+
sha1A.subarray(8, 20),
|
|
49
|
+
sha1B.subarray(0, 8),
|
|
50
|
+
sha1C.subarray(16, 20),
|
|
51
|
+
sha1D.subarray(0, 8),
|
|
52
|
+
]);
|
|
53
|
+
return [aesKey, aesIv];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const sha256A = sha256(platform_node_js_1.Buffer.concat([
|
|
57
|
+
msgKey,
|
|
58
|
+
sharedKey.subarray(x, x + 36),
|
|
59
|
+
]));
|
|
60
|
+
const sha256B = sha256(platform_node_js_1.Buffer.concat([
|
|
61
|
+
sharedKey.subarray(x + 40, x + 76),
|
|
62
|
+
msgKey,
|
|
63
|
+
]));
|
|
64
|
+
const aesKey = platform_node_js_1.Buffer.concat([
|
|
65
|
+
sha256A.subarray(0, 8),
|
|
66
|
+
sha256B.subarray(8, 24),
|
|
67
|
+
sha256A.subarray(24, 32),
|
|
68
|
+
]);
|
|
69
|
+
const aesIv = platform_node_js_1.Buffer.concat([
|
|
70
|
+
sha256B.subarray(0, 8),
|
|
71
|
+
sha256A.subarray(8, 24),
|
|
72
|
+
sha256B.subarray(24, 32),
|
|
73
|
+
]);
|
|
74
|
+
return [aesKey, aesIv];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function pack(message, sharedKey, inSeqNo, outSeqNo, isAdmin, layer, mtproto = 2) {
|
|
78
|
+
let msg = message;
|
|
79
|
+
if (layer > 8) {
|
|
80
|
+
msg = new index_js_3.Raw.DecryptedMessageLayer17({
|
|
81
|
+
randomBytes: platform_node_js_1.crypto.randomBytes(15 + 4 * Math.floor(Math.random() * 3)),
|
|
82
|
+
layer: layer,
|
|
83
|
+
inSeqNo: inSeqNo,
|
|
84
|
+
outSeqNo: outSeqNo,
|
|
85
|
+
message: message,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const bytesmsg = msg.write();
|
|
89
|
+
const length = platform_node_js_1.Buffer.alloc(4);
|
|
90
|
+
length.writeUInt32LE(platform_node_js_1.Buffer.byteLength(bytesmsg), 0);
|
|
91
|
+
const data = platform_node_js_1.Buffer.concat([length, bytesmsg]);
|
|
92
|
+
const padding = platform_node_js_1.Buffer.from(platform_node_js_1.crypto.randomBytes((0, helpers_js_1.mod)(-(platform_node_js_1.Buffer.byteLength(data) + 16), 16) + 16));
|
|
93
|
+
const paddedMsg = platform_node_js_1.Buffer.concat([
|
|
94
|
+
data,
|
|
95
|
+
padding,
|
|
96
|
+
]);
|
|
97
|
+
const msgKeyLarge = sha256(platform_node_js_1.Buffer.concat([
|
|
98
|
+
sharedKey.subarray(88 + (isAdmin ? 0 : 8), 88 + (isAdmin ? 0 : 8) + 32),
|
|
99
|
+
paddedMsg,
|
|
100
|
+
]));
|
|
101
|
+
const msgKey = mtproto === 1 ? sha1(data).subarray(-16) : msgKeyLarge.subarray(8, 8 + 16);
|
|
102
|
+
const [aesKey, aesIv] = mtproto === 1 ? kdf(sharedKey, msgKey, isAdmin, true) : kdf(sharedKey, msgKey, isAdmin, false);
|
|
103
|
+
const fingerprintKey = sha1(sharedKey).subarray(-8);
|
|
104
|
+
return platform_node_js_1.Buffer.concat([
|
|
105
|
+
fingerprintKey,
|
|
106
|
+
msgKey,
|
|
107
|
+
(0, Aes_js_1.ige256Encrypt)(paddedMsg, aesKey, aesIv),
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
async function unpack(message, sharedKey, isAdmin, mtproto = 2) {
|
|
111
|
+
const data = new index_js_2.BytesIO(message.bytes);
|
|
112
|
+
const serverFingerprintKey = data.readBigInt64LE();
|
|
113
|
+
const clientFingerprintKey = sha1(sharedKey).subarray(-8).readBigInt64LE();
|
|
114
|
+
if (serverFingerprintKey !== clientFingerprintKey) {
|
|
115
|
+
throw new index_js_1.SecretChatError.FingerprintMismatch();
|
|
116
|
+
}
|
|
117
|
+
const msgKey = data.read(16);
|
|
118
|
+
const encryptedMsg = data.read();
|
|
119
|
+
const [aesKey, aesIv] = mtproto === 1 ? kdf(sharedKey, msgKey, isAdmin, true) : kdf(sharedKey, msgKey, !isAdmin, false);
|
|
120
|
+
const decryptedMsg = new index_js_2.BytesIO((0, Aes_js_1.ige256Decrypt)(encryptedMsg, aesKey, aesIv));
|
|
121
|
+
const msgLength = decryptedMsg.readUInt32LE();
|
|
122
|
+
const payload = decryptedMsg.read();
|
|
123
|
+
const padding = payload.subarray(msgLength);
|
|
124
|
+
const msgKeyLarge = sha256(platform_node_js_1.Buffer.concat([
|
|
125
|
+
sharedKey.subarray(88 + (isAdmin ? 8 : 0), 88 + (isAdmin ? 8 : 0) + 32),
|
|
126
|
+
decryptedMsg.buffer,
|
|
127
|
+
]));
|
|
128
|
+
const clientMsgKey = mtproto === 1
|
|
129
|
+
? sha1(decryptedMsg.buffer.subarray(0, 4 + msgLength)).subarray(-16)
|
|
130
|
+
: msgKeyLarge.subarray(8, 8 + 16);
|
|
131
|
+
index_js_1.SecurityCheckMismatch.check(msgKey.equals(clientMsgKey), 'Given message key is not equal with client side');
|
|
132
|
+
index_js_1.SecurityCheckMismatch.check(platform_node_js_1.Buffer.byteLength(padding) >= 12 && platform_node_js_1.Buffer.byteLength(padding) <= 1024, 'Payload padding is lower than 12 or bigger than 1024');
|
|
133
|
+
index_js_1.SecurityCheckMismatch.check((0, helpers_js_1.mod)(platform_node_js_1.Buffer.byteLength(padding), 4) === 0, 'Mod of padding length with 4 is equal with zero');
|
|
134
|
+
const msg = await index_js_2.TLObject.read(new index_js_2.BytesIO(payload));
|
|
135
|
+
return msg;
|
|
136
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SecretChats = exports.AES = exports.Password = exports.RSA = exports.Prime = exports.Mtproto = void 0;
|
|
37
|
+
exports.Mtproto = __importStar(require("./Mtproto.js"));
|
|
38
|
+
exports.Prime = __importStar(require("./Prime.js"));
|
|
39
|
+
exports.RSA = __importStar(require("./RSA.js"));
|
|
40
|
+
exports.Password = __importStar(require("./Password.js"));
|
|
41
|
+
exports.AES = __importStar(require("./Aes.js"));
|
|
42
|
+
exports.SecretChats = __importStar(require("./SecretChat.js"));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseError = void 0;
|
|
4
|
+
const platform_node_js_1 = require("../platform.node.js");
|
|
5
|
+
class BaseError extends Error {
|
|
6
|
+
message;
|
|
7
|
+
description;
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
}
|
|
11
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
12
|
+
const toPrint = {
|
|
13
|
+
_: this.constructor.name,
|
|
14
|
+
};
|
|
15
|
+
for (const key in this) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
17
|
+
const value = this[key];
|
|
18
|
+
if (!key.startsWith('_')) {
|
|
19
|
+
toPrint[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
Object.setPrototypeOf(toPrint, {
|
|
24
|
+
stack: this.stack,
|
|
25
|
+
});
|
|
26
|
+
return toPrint;
|
|
27
|
+
}
|
|
28
|
+
[Symbol.for('Deno.customInspect')]() {
|
|
29
|
+
return String((0, platform_node_js_1.inspect)(this[Symbol.for('nodejs.util.inspect.custom')](), { colors: true }));
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
const toPrint = {
|
|
33
|
+
_: this.constructor.name,
|
|
34
|
+
stack: this.stack,
|
|
35
|
+
};
|
|
36
|
+
for (const key in this) {
|
|
37
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
38
|
+
const value = this[key];
|
|
39
|
+
if (!key.startsWith('_')) {
|
|
40
|
+
toPrint[key] = typeof value === 'bigint' ? String(value) : value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return toPrint;
|
|
45
|
+
}
|
|
46
|
+
toString() {
|
|
47
|
+
return `[constructor of ${this.constructor.name}] ${JSON.stringify(this, null, 2)}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.BaseError = BaseError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from './Base.js';
|
|
2
|
+
export declare class ClientDisconnected extends BaseError {
|
|
3
|
+
message: string;
|
|
4
|
+
description: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class ClientFailed extends BaseError {
|
|
7
|
+
message: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ClientReady extends BaseError {
|
|
11
|
+
message: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class ClientNotReady extends BaseError {
|
|
15
|
+
message: string;
|
|
16
|
+
description: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class AuthKeyMissing extends BaseError {
|
|
19
|
+
message: string;
|
|
20
|
+
description: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthKeyMissing = exports.ClientNotReady = exports.ClientReady = exports.ClientFailed = exports.ClientDisconnected = void 0;
|
|
4
|
+
const Base_js_1 = require("./Base.js");
|
|
5
|
+
class ClientDisconnected extends Base_js_1.BaseError {
|
|
6
|
+
message = "Can't send request to telegram when client is unconnected.";
|
|
7
|
+
description = 'The provided telegram client is unconnected, make sure to start the telegram client first before sending request.';
|
|
8
|
+
}
|
|
9
|
+
exports.ClientDisconnected = ClientDisconnected;
|
|
10
|
+
class ClientFailed extends Base_js_1.BaseError {
|
|
11
|
+
message = 'Client failed to connect to server.';
|
|
12
|
+
description = 'The provided telegram client failed to connect to the telegram data center server. Attempts to connect to the telegram server have exceeded the specified maximum limit.';
|
|
13
|
+
}
|
|
14
|
+
exports.ClientFailed = ClientFailed;
|
|
15
|
+
class ClientReady extends Base_js_1.BaseError {
|
|
16
|
+
message = 'Client is already connected to server.';
|
|
17
|
+
description = 'The provided telegram client has been already connected to the telegram data center server.';
|
|
18
|
+
}
|
|
19
|
+
exports.ClientReady = ClientReady;
|
|
20
|
+
class ClientNotReady extends Base_js_1.BaseError {
|
|
21
|
+
message = 'Client is already disconnected to server.';
|
|
22
|
+
description = 'The provided telegram client has been already disconnected to the telegram data center server.';
|
|
23
|
+
}
|
|
24
|
+
exports.ClientNotReady = ClientNotReady;
|
|
25
|
+
class AuthKeyMissing extends Base_js_1.BaseError {
|
|
26
|
+
message = 'Auth key unavailable';
|
|
27
|
+
description = 'Auth key is unavailable, this can happen because at when the client is run, the user does not provide information to login.';
|
|
28
|
+
}
|
|
29
|
+
exports.AuthKeyMissing = AuthKeyMissing;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseError } from './Base.js';
|
|
2
|
+
export declare class FileError extends BaseError {
|
|
3
|
+
constructor(message: string, description?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class FileUploadZero extends FileError {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare class FileUploadBigger extends FileError {
|
|
9
|
+
constructor(limit: number, size: number);
|
|
10
|
+
}
|
|
11
|
+
export declare class FileIsNotReadable extends FileError {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileIsNotReadable = exports.FileUploadBigger = exports.FileUploadZero = exports.FileError = void 0;
|
|
4
|
+
const Base_js_1 = require("./Base.js");
|
|
5
|
+
class FileError extends Base_js_1.BaseError {
|
|
6
|
+
constructor(message, description) {
|
|
7
|
+
super();
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.description = description;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.FileError = FileError;
|
|
13
|
+
class FileUploadZero extends FileError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("Can't upload file when it zero bytes.", 'Provided file has zero bytes (0 B) file size.');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.FileUploadZero = FileUploadZero;
|
|
19
|
+
class FileUploadBigger extends FileError {
|
|
20
|
+
constructor(limit, size) {
|
|
21
|
+
super(`File greater than ${limit} B.`, `The provided file has ${size} B file size, it greater than ${limit} B`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FileUploadBigger = FileUploadBigger;
|
|
25
|
+
class FileIsNotReadable extends FileError {
|
|
26
|
+
constructor() {
|
|
27
|
+
super('FILE_IS_NOT_READABLE', 'The argument provided is not a Readable stream.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.FileIsNotReadable = FileIsNotReadable;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Raw, TLObject } from '../raw/index.js';
|
|
2
|
+
export declare class RPCError extends Error {
|
|
3
|
+
id: string;
|
|
4
|
+
code: number;
|
|
5
|
+
message: string;
|
|
6
|
+
name: string;
|
|
7
|
+
value?: number | string | Raw.RpcError;
|
|
8
|
+
_isSigned?: boolean;
|
|
9
|
+
_isUnknown?: boolean;
|
|
10
|
+
_rpcName?: string;
|
|
11
|
+
constructor(value?: number | string | Raw.RpcError, rpcName?: string, isUnknown?: boolean, isSigned?: boolean);
|
|
12
|
+
protected _format(): void;
|
|
13
|
+
static raise(rpcError: Raw.RpcError, rpcType: TLObject): Promise<void>;
|
|
14
|
+
toJSON(): {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
toString(): string;
|
|
18
|
+
}
|
|
19
|
+
export declare class UnknownError extends RPCError {
|
|
20
|
+
code: number;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnknownError = exports.RPCError = void 0;
|
|
4
|
+
const Logger_js_1 = require("../Logger.js");
|
|
5
|
+
const All_js_1 = require("./exceptions/All.js");
|
|
6
|
+
const platform_node_js_1 = require("../platform.node.js");
|
|
7
|
+
const index_js_1 = require("./index.js");
|
|
8
|
+
function getModule(name) {
|
|
9
|
+
const [namespace, mod] = name.split('.');
|
|
10
|
+
if (index_js_1.Exceptions[namespace] &&
|
|
11
|
+
index_js_1.Exceptions[namespace][mod]) {
|
|
12
|
+
return index_js_1.Exceptions[namespace][mod];
|
|
13
|
+
}
|
|
14
|
+
return UnknownError;
|
|
15
|
+
}
|
|
16
|
+
class RPCError extends Error {
|
|
17
|
+
id;
|
|
18
|
+
code;
|
|
19
|
+
message;
|
|
20
|
+
name;
|
|
21
|
+
value;
|
|
22
|
+
_isSigned;
|
|
23
|
+
_isUnknown;
|
|
24
|
+
_rpcName;
|
|
25
|
+
constructor(value, rpcName, isUnknown, isSigned) {
|
|
26
|
+
super();
|
|
27
|
+
Logger_js_1.Logger.debug(`[8] Creating new instance RPCError(${rpcName ?? this.name})`);
|
|
28
|
+
this._isSigned = isSigned;
|
|
29
|
+
this._isUnknown = isUnknown;
|
|
30
|
+
this._rpcName = rpcName;
|
|
31
|
+
if (!Number.isNaN(value)) {
|
|
32
|
+
this.value = Number(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.value = value;
|
|
36
|
+
}
|
|
37
|
+
if (isUnknown) {
|
|
38
|
+
Logger_js_1.Logger.debug(`[9] UnknownError : ${this.name}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_format() {
|
|
42
|
+
this.message = `Telegram Says: [${this._isSigned ? '-' : ''}${this.code} ${this.id || this.name}] - ${(this.message || '').replace(/\{value\}/g, String(this.value))} ${this._rpcName ? `(caused by ${this._rpcName})` : ''}`;
|
|
43
|
+
}
|
|
44
|
+
static async raise(rpcError, rpcType) {
|
|
45
|
+
let code = rpcError.errorCode;
|
|
46
|
+
const message = rpcError.errorMessage;
|
|
47
|
+
const isSigned = code < 0;
|
|
48
|
+
const name = rpcType.className;
|
|
49
|
+
if (isSigned)
|
|
50
|
+
code = -code;
|
|
51
|
+
if (!(code in All_js_1.Exceptions)) {
|
|
52
|
+
throw new UnknownError(`[${code} ${message}]`, name, true, isSigned);
|
|
53
|
+
}
|
|
54
|
+
let id = message.replace(/\_\d+/gm, '_X');
|
|
55
|
+
const regexMatch = message.match(/\_(\d+)/gm);
|
|
56
|
+
let value = '';
|
|
57
|
+
if (regexMatch) {
|
|
58
|
+
value = regexMatch[0].replace(/\_/g, '');
|
|
59
|
+
}
|
|
60
|
+
if (!(id in All_js_1.Exceptions[code])) {
|
|
61
|
+
id = id.split('_').splice(-1, 1, '*').join('_');
|
|
62
|
+
if (!(id in All_js_1.Exceptions[code])) {
|
|
63
|
+
const modules = getModule(All_js_1.Exceptions[code]['_']);
|
|
64
|
+
const _module = new modules(value, name, true, isSigned);
|
|
65
|
+
_module.message = `[${code} ${message}]`;
|
|
66
|
+
_module.id = message.replace(/\_\d+/gm, '_X');
|
|
67
|
+
_module._format();
|
|
68
|
+
throw _module;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const modules = await getModule(All_js_1.Exceptions[code][id]);
|
|
72
|
+
const _module = new modules(value, name, false, isSigned);
|
|
73
|
+
_module._format();
|
|
74
|
+
throw _module;
|
|
75
|
+
}
|
|
76
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
77
|
+
const toPrint = {
|
|
78
|
+
_: this.constructor.name,
|
|
79
|
+
};
|
|
80
|
+
for (const key in this) {
|
|
81
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
82
|
+
const value = this[key];
|
|
83
|
+
if (!key.startsWith('_') && value !== undefined && value !== null) {
|
|
84
|
+
toPrint[key] = value;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Object.setPrototypeOf(toPrint, {
|
|
89
|
+
stack: this.stack,
|
|
90
|
+
});
|
|
91
|
+
return toPrint;
|
|
92
|
+
}
|
|
93
|
+
[Symbol.for('Deno.customInspect')]() {
|
|
94
|
+
return String((0, platform_node_js_1.inspect)(this[Symbol.for('nodejs.util.inspect.custom')](), { colors: true }));
|
|
95
|
+
}
|
|
96
|
+
toJSON() {
|
|
97
|
+
const toPrint = {
|
|
98
|
+
_: this.constructor.name,
|
|
99
|
+
stack: this.stack,
|
|
100
|
+
};
|
|
101
|
+
for (const key in this) {
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
103
|
+
const value = this[key];
|
|
104
|
+
if (!key.startsWith('_')) {
|
|
105
|
+
toPrint[key] = typeof value === 'bigint' ? String(value) : value;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return toPrint;
|
|
110
|
+
}
|
|
111
|
+
toString() {
|
|
112
|
+
return `[constructor of ${this.constructor.name}] ${JSON.stringify(this, null, 2)}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.RPCError = RPCError;
|
|
116
|
+
class UnknownError extends RPCError {
|
|
117
|
+
code = 520;
|
|
118
|
+
name = 'Unknown Error';
|
|
119
|
+
}
|
|
120
|
+
exports.UnknownError = UnknownError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseError } from './Base.js';
|
|
2
|
+
export declare class SecretChatError extends BaseError {
|
|
3
|
+
constructor(message: string, description?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class FingerprintMismatch extends SecretChatError {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare class ChatNotFound extends SecretChatError {
|
|
9
|
+
constructor(chatId: number);
|
|
10
|
+
}
|
|
11
|
+
export declare class AlreadyAccepted extends SecretChatError {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlreadyAccepted = exports.ChatNotFound = exports.FingerprintMismatch = exports.SecretChatError = void 0;
|
|
4
|
+
const Base_js_1 = require("./Base.js");
|
|
5
|
+
class SecretChatError extends Base_js_1.BaseError {
|
|
6
|
+
constructor(message, description) {
|
|
7
|
+
super();
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.description = description;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.SecretChatError = SecretChatError;
|
|
13
|
+
class FingerprintMismatch extends SecretChatError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('Fingerprint key mismatch', 'Given fingerprint key from message is mismatch. So the message is not secure and the secret chat should be closed.');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.FingerprintMismatch = FingerprintMismatch;
|
|
19
|
+
class ChatNotFound extends SecretChatError {
|
|
20
|
+
constructor(chatId) {
|
|
21
|
+
super('Secret chat not found', `Provided chatId (${chatId}) is not found in session. Make sure the chatId is correct and already saved in session.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ChatNotFound = ChatNotFound;
|
|
25
|
+
class AlreadyAccepted extends SecretChatError {
|
|
26
|
+
constructor() {
|
|
27
|
+
super('Secret chat already accepted');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AlreadyAccepted = AlreadyAccepted;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseError } from './Base.js';
|
|
2
|
+
export declare class WebSocketError extends BaseError {
|
|
3
|
+
constructor(message: string, description?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class Disconnected extends WebSocketError {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare class ReadClosed extends WebSocketError {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare class ProxyUnsupported extends WebSocketError {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyUnsupported = exports.ReadClosed = exports.Disconnected = exports.WebSocketError = void 0;
|
|
4
|
+
const Base_js_1 = require("./Base.js");
|
|
5
|
+
class WebSocketError extends Base_js_1.BaseError {
|
|
6
|
+
constructor(message, description) {
|
|
7
|
+
super();
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.description = description;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.WebSocketError = WebSocketError;
|
|
13
|
+
class Disconnected extends WebSocketError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('WebSocket Disconnected', "This happen when you trying to send request or receive update from websocket server hut the websocket client is doesn't ready. Make sure the websocket client is connected to server.");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Disconnected = Disconnected;
|
|
19
|
+
class ReadClosed extends WebSocketError {
|
|
20
|
+
constructor() {
|
|
21
|
+
super('WebSocket connection closed when reading data', 'This happen when suddenly the connection between the websocket client and the server is lost when fetching data updates from the server.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ReadClosed = ReadClosed;
|
|
25
|
+
class ProxyUnsupported extends WebSocketError {
|
|
26
|
+
constructor() {
|
|
27
|
+
super('WebSocket proxy unsupported', 'This is because browser telegram or websocket proxy are not supported by the framework at this time.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ProxyUnsupported = ProxyUnsupported;
|