@mtkruto/node 0.0.6
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/LICENSE +165 -0
- package/README.md +1 -0
- package/esm/_dnt.shims.js +68 -0
- package/esm/client/client.js +169 -0
- package/esm/client/client_abstract.js +51 -0
- package/esm/client/client_plain.js +112 -0
- package/esm/connection/connection.js +2 -0
- package/esm/connection/connection_web_socket.js +90 -0
- package/esm/constants.js +60 -0
- package/esm/deps/deno.land/std@0.186.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.186.0/testing/_diff.js +311 -0
- package/esm/deps/deno.land/std@0.186.0/testing/_format.js +23 -0
- package/esm/deps/deno.land/std@0.186.0/testing/asserts.js +633 -0
- package/esm/deps/deno.land/x/crc32@v0.2.0/mod.js +105 -0
- package/esm/deps/deno.land/x/tgcrypto@0.1.1/mod.js +68 -0
- package/esm/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1127 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +239 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +10 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +139 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +176 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +2 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +19 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +25 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1941 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +85 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +321 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1658 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +355 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +11 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +42 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1107 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +86 -0
- package/esm/deps.js +4 -0
- package/esm/mod.js +4 -0
- package/esm/package.json +3 -0
- package/esm/tl/0_tl_raw_reader.js +62 -0
- package/esm/tl/0_tl_raw_writer.js +60 -0
- package/esm/tl/1_tl_object.js +149 -0
- package/esm/tl/2_types.js +48220 -0
- package/esm/tl/3_functions.js +19856 -0
- package/esm/tl/3_tl_object_deserializer.js +72 -0
- package/esm/tl/3_tl_reader.js +16 -0
- package/esm/tl/3_tl_writer.js +7 -0
- package/esm/tl/4_rpc_result.js +27 -0
- package/esm/tl/5_message.js +54 -0
- package/esm/tl/6_message_container.js +35 -0
- package/esm/transport/transport.js +32 -0
- package/esm/transport/transport_intermediate.js +56 -0
- package/esm/transport/transport_provider.js +23 -0
- package/esm/types.js +1 -0
- package/esm/utilities/0_bigint.js +37 -0
- package/esm/utilities/0_buffer.js +33 -0
- package/esm/utilities/0_crypto.js +35 -0
- package/esm/utilities/0_hash.js +7 -0
- package/esm/utilities/1_auth.js +29 -0
- package/esm/utilities/1_message.js +94 -0
- package/esm/utilities/1_obfuscation.js +33 -0
- package/package.json +40 -0
- package/script/_dnt.shims.js +77 -0
- package/script/client/client.js +173 -0
- package/script/client/client_abstract.js +55 -0
- package/script/client/client_plain.js +116 -0
- package/script/connection/connection.js +6 -0
- package/script/connection/connection_web_socket.js +117 -0
- package/script/constants.js +63 -0
- package/script/deps/deno.land/std@0.186.0/fmt/colors.js +548 -0
- package/script/deps/deno.land/std@0.186.0/testing/_diff.js +317 -0
- package/script/deps/deno.land/std@0.186.0/testing/_format.js +50 -0
- package/script/deps/deno.land/std@0.186.0/testing/asserts.js +659 -0
- package/script/deps/deno.land/x/crc32@v0.2.0/mod.js +113 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.1/mod.js +82 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1152 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +271 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +14 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +172 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +208 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +18 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +22 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +30 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1976 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +88 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +324 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1674 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +358 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +14 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +44 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1115 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +89 -0
- package/script/deps.js +30 -0
- package/script/mod.js +32 -0
- package/script/package.json +3 -0
- package/script/tl/0_tl_raw_reader.js +66 -0
- package/script/tl/0_tl_raw_writer.js +64 -0
- package/script/tl/1_tl_object.js +156 -0
- package/script/tl/2_types.js +49824 -0
- package/script/tl/3_functions.js +20413 -0
- package/script/tl/3_tl_object_deserializer.js +76 -0
- package/script/tl/3_tl_reader.js +20 -0
- package/script/tl/3_tl_writer.js +11 -0
- package/script/tl/4_rpc_result.js +31 -0
- package/script/tl/5_message.js +58 -0
- package/script/tl/6_message_container.js +39 -0
- package/script/transport/transport.js +36 -0
- package/script/transport/transport_intermediate.js +60 -0
- package/script/transport/transport_provider.js +27 -0
- package/script/types.js +2 -0
- package/script/utilities/0_bigint.js +67 -0
- package/script/utilities/0_buffer.js +38 -0
- package/script/utilities/0_crypto.js +39 -0
- package/script/utilities/0_hash.js +35 -0
- package/script/utilities/1_auth.js +56 -0
- package/script/utilities/1_message.js +102 -0
- package/script/utilities/1_obfuscation.js +60 -0
- package/types/_dnt.shims.d.ts +10 -0
- package/types/client/client.d.ts +19 -0
- package/types/client/client_abstract.d.ts +20 -0
- package/types/client/client_plain.d.ts +10 -0
- package/types/connection/connection.d.ts +7 -0
- package/types/connection/connection_web_socket.d.ts +13 -0
- package/types/constants.d.ts +2 -0
- package/types/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
- package/types/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
- package/types/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
- package/types/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
- package/types/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
- package/types/deps/deno.land/x/tgcrypto@0.1.1/mod.d.ts +47 -0
- package/types/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
- package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
- package/types/deps.d.ts +4 -0
- package/types/mod.d.ts +4 -0
- package/types/tl/0_tl_raw_reader.d.ts +13 -0
- package/types/tl/0_tl_raw_writer.d.ts +13 -0
- package/types/tl/1_tl_object.d.ts +36 -0
- package/types/tl/2_types.d.ts +14815 -0
- package/types/tl/3_functions.d.ts +6122 -0
- package/types/tl/3_tl_object_deserializer.d.ts +3 -0
- package/types/tl/3_tl_reader.d.ts +4 -0
- package/types/tl/3_tl_writer.d.ts +5 -0
- package/types/tl/4_rpc_result.d.ts +8 -0
- package/types/tl/5_message.d.ts +11 -0
- package/types/tl/6_message_container.d.ts +9 -0
- package/types/transport/transport.d.ts +15 -0
- package/types/transport/transport_intermediate.d.ts +11 -0
- package/types/transport/transport_provider.d.ts +12 -0
- package/types/types.d.ts +1 -0
- package/types/utilities/0_bigint.d.ts +4 -0
- package/types/utilities/0_buffer.d.ts +2 -0
- package/types/utilities/0_crypto.d.ts +8 -0
- package/types/utilities/0_hash.d.ts +2 -0
- package/types/utilities/1_auth.d.ts +1 -0
- package/types/utilities/1_message.d.ts +10 -0
- package/types/utilities/1_obfuscation.d.ts +6 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decryptMessage = exports.encryptMessage = exports.unpackUnencryptedMessage = exports.packUnencryptedMessage = exports.getMessageId = void 0;
|
|
4
|
+
const deps_js_1 = require("../deps.js");
|
|
5
|
+
const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
|
|
6
|
+
const _0_tl_raw_writer_js_1 = require("../tl/0_tl_raw_writer.js");
|
|
7
|
+
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
8
|
+
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
9
|
+
const _4_rpc_result_js_1 = require("../tl/4_rpc_result.js");
|
|
10
|
+
const _5_message_js_1 = require("../tl/5_message.js");
|
|
11
|
+
const _6_message_container_js_1 = require("../tl/6_message_container.js");
|
|
12
|
+
const _0_buffer_js_1 = require("./0_buffer.js");
|
|
13
|
+
const _0_hash_js_1 = require("./0_hash.js");
|
|
14
|
+
let lastMsgId = 0n;
|
|
15
|
+
function getMessageId() {
|
|
16
|
+
const now = new Date().getTime() / 1000 + 0;
|
|
17
|
+
const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
|
|
18
|
+
let newMsgId = (BigInt(Math.floor(now)) <<
|
|
19
|
+
32n) ||
|
|
20
|
+
(BigInt(nanoseconds) << 2n);
|
|
21
|
+
if (lastMsgId >= (newMsgId)) {
|
|
22
|
+
newMsgId = lastMsgId + 4n;
|
|
23
|
+
}
|
|
24
|
+
lastMsgId = newMsgId;
|
|
25
|
+
return newMsgId;
|
|
26
|
+
}
|
|
27
|
+
exports.getMessageId = getMessageId;
|
|
28
|
+
function packUnencryptedMessage(data) {
|
|
29
|
+
const message = (0, _0_buffer_js_1.concat)((0, _0_buffer_js_1.bufferFromBigInt)(0x00, 8), (0, _0_buffer_js_1.bufferFromBigInt)(getMessageId(), 8), (0, _0_buffer_js_1.bufferFromBigInt)(data.length, 4), data);
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
exports.packUnencryptedMessage = packUnencryptedMessage;
|
|
33
|
+
function unpackUnencryptedMessage(buffer) {
|
|
34
|
+
const reader = new _0_tl_raw_reader_js_1.TLRawReader(buffer);
|
|
35
|
+
const _authKeyId = reader.readInt64();
|
|
36
|
+
const messageId = reader.readInt64();
|
|
37
|
+
const messageLength = reader.readInt32();
|
|
38
|
+
const message = reader.read(messageLength);
|
|
39
|
+
return { messageId, message };
|
|
40
|
+
}
|
|
41
|
+
exports.unpackUnencryptedMessage = unpackUnencryptedMessage;
|
|
42
|
+
async function encryptMessage(message, authKey, authKeyId, salt, sessionId) {
|
|
43
|
+
const encoded = message.body.serialize();
|
|
44
|
+
const payloadWriter = new _0_tl_raw_writer_js_1.TLRawWriter();
|
|
45
|
+
payloadWriter.writeInt64(salt);
|
|
46
|
+
payloadWriter.writeInt64(sessionId);
|
|
47
|
+
payloadWriter.writeInt64(message.id);
|
|
48
|
+
payloadWriter.writeInt32(message.seqNo);
|
|
49
|
+
payloadWriter.writeInt32(encoded.length);
|
|
50
|
+
payloadWriter.write(encoded);
|
|
51
|
+
payloadWriter.write(new Uint8Array(payloadWriter.buffer.length + 12 % 16 + 12));
|
|
52
|
+
let payload = payloadWriter.buffer;
|
|
53
|
+
while (true) {
|
|
54
|
+
if (payload.length % 16 == 0 && (payload.length) % 4 == 0) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
payload = (0, _0_buffer_js_1.concat)(payload, new Uint8Array(1));
|
|
58
|
+
}
|
|
59
|
+
const messageKey = (await (0, _0_hash_js_1.sha256)((0, _0_buffer_js_1.concat)(authKey.slice(88, 120), payload))).slice(8, 24);
|
|
60
|
+
const a = await (0, _0_hash_js_1.sha256)((0, _0_buffer_js_1.concat)(messageKey, authKey.slice(0, 36)));
|
|
61
|
+
const b = await (0, _0_hash_js_1.sha256)((0, _0_buffer_js_1.concat)(authKey.slice(40, 76), messageKey));
|
|
62
|
+
const aesKey = (0, _0_buffer_js_1.concat)(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
|
|
63
|
+
const aesIV = (0, _0_buffer_js_1.concat)(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
|
|
64
|
+
const messageWriter = new _0_tl_raw_writer_js_1.TLRawWriter();
|
|
65
|
+
messageWriter.writeInt64(authKeyId);
|
|
66
|
+
messageWriter.write(messageKey);
|
|
67
|
+
messageWriter.write((0, deps_js_1.ige256Encrypt)(payload, aesKey, aesIV));
|
|
68
|
+
return messageWriter.buffer;
|
|
69
|
+
}
|
|
70
|
+
exports.encryptMessage = encryptMessage;
|
|
71
|
+
async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
|
|
72
|
+
const reader = new _3_tl_reader_js_1.TLReader(buffer);
|
|
73
|
+
(0, deps_js_1.assertEquals)(reader.readInt64(false), authKeyId);
|
|
74
|
+
const messageKey_ = reader.readInt128();
|
|
75
|
+
const messageKey = (0, _0_buffer_js_1.bufferFromBigInt)(messageKey_, 16, true, true);
|
|
76
|
+
const a = await (0, _0_hash_js_1.sha256)((0, _0_buffer_js_1.concat)(messageKey, authKey.slice(8, 44)));
|
|
77
|
+
const b = await (0, _0_hash_js_1.sha256)((0, _0_buffer_js_1.concat)(authKey.slice(48, 84), messageKey));
|
|
78
|
+
const aesKey = (0, _0_buffer_js_1.concat)(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
|
|
79
|
+
const aesIv = (0, _0_buffer_js_1.concat)(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
|
|
80
|
+
const plaintext = (0, deps_js_1.ige256Decrypt)(reader.buffer, aesKey, aesIv);
|
|
81
|
+
(0, deps_js_1.assertEquals)(plaintext.buffer.byteLength % 4, 0);
|
|
82
|
+
let plainReader = new _3_tl_reader_js_1.TLReader(plaintext);
|
|
83
|
+
const _salt = plainReader.readInt64();
|
|
84
|
+
const _sessionId_ = plainReader.readInt64(false);
|
|
85
|
+
const mid = plainReader.readInt64();
|
|
86
|
+
const seqno = plainReader.readInt32();
|
|
87
|
+
const length = plainReader.readInt32();
|
|
88
|
+
plainReader = new _3_tl_reader_js_1.TLReader(plainReader.read(length));
|
|
89
|
+
const cid = plainReader.readInt32(false);
|
|
90
|
+
if (cid == _6_message_container_js_1.MessageContainer[_1_tl_object_js_1.id]) {
|
|
91
|
+
return _6_message_container_js_1.MessageContainer.deserialize(plainReader.buffer);
|
|
92
|
+
}
|
|
93
|
+
else if (cid == _4_rpc_result_js_1.RPCResult[_1_tl_object_js_1.id]) {
|
|
94
|
+
const body = _4_rpc_result_js_1.RPCResult.deserialize(plainReader.buffer);
|
|
95
|
+
return new _5_message_js_1.Message(mid, seqno, body);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const body = plainReader.readObject(cid);
|
|
99
|
+
return new _5_message_js_1.Message(mid, seqno, body);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.decryptMessage = decryptMessage;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getObfuscationParameters = void 0;
|
|
27
|
+
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
28
|
+
const _0_buffer_js_1 = require("./0_buffer.js");
|
|
29
|
+
const _0_crypto_js_1 = require("./0_crypto.js");
|
|
30
|
+
async function getObfuscationParameters(protocol, connection) {
|
|
31
|
+
const dc = 0xFCFF;
|
|
32
|
+
let init;
|
|
33
|
+
while (true) {
|
|
34
|
+
init = (0, _0_buffer_js_1.concat)(dntShim.crypto.getRandomValues(new Uint8Array(56)), (0, _0_buffer_js_1.bufferFromBigInt)(protocol, 4, false), (0, _0_buffer_js_1.bufferFromBigInt)(dc, 2, false), dntShim.crypto.getRandomValues(new Uint8Array(2)));
|
|
35
|
+
if (init[0] == 0xEF) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const dataView = new DataView(init.buffer);
|
|
39
|
+
const firstInt = dataView.getInt32(0);
|
|
40
|
+
if ([0x44414548, 0x54534F50, 0x20544547, 0x4954504F, 0x02010316, 0xDDDDDDDD, 0xEEEEEEEE].includes(firstInt)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const secondInt = dataView.getInt32(4);
|
|
44
|
+
if (secondInt == 0x00000000) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
const encryptKey = init.slice(8, 8 + 32);
|
|
50
|
+
const encryptIv = init.slice(40, 40 + 16);
|
|
51
|
+
const encryptionCTR = new _0_crypto_js_1.CTR(encryptKey, encryptIv);
|
|
52
|
+
const encryptedInit = encryptionCTR.encrypt(init);
|
|
53
|
+
const initRev = new Uint8Array(init).reverse();
|
|
54
|
+
const decryptKey = initRev.slice(8, 8 + 32);
|
|
55
|
+
const decryptIv = initRev.slice(40, 40 + 16);
|
|
56
|
+
const decryptionCTR = new _0_crypto_js_1.CTR(decryptKey, decryptIv);
|
|
57
|
+
await connection.write((0, _0_buffer_js_1.concat)(init.slice(0, 56), encryptedInit.slice(56, 56 + 8)));
|
|
58
|
+
return { encryptionCTR, decryptionCTR };
|
|
59
|
+
}
|
|
60
|
+
exports.getObfuscationParameters = getObfuscationParameters;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { default as WebSocket } from "ws";
|
|
5
|
+
export { default as WebSocket } from "ws";
|
|
6
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "WebSocket" | "crypto" | "Deno"> & {
|
|
7
|
+
Deno: typeof Deno;
|
|
8
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
9
|
+
WebSocket: typeof WebSocket;
|
|
10
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MaybePromise } from "../types.js";
|
|
2
|
+
import { Type, Updates } from "../tl/2_types.js";
|
|
3
|
+
import { Function } from "../tl/3_functions.js";
|
|
4
|
+
import { ClientAbstract } from "./client_abstract.js";
|
|
5
|
+
export type UpdatesHandler = null | ((client: Client, update: Updates) => MaybePromise<void>);
|
|
6
|
+
export declare class Client extends ClientAbstract {
|
|
7
|
+
private sessionId;
|
|
8
|
+
private auth?;
|
|
9
|
+
private state;
|
|
10
|
+
private promises;
|
|
11
|
+
private toAcknowledge;
|
|
12
|
+
updatesHandler: UpdatesHandler;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
private receiveLoop;
|
|
15
|
+
private pingLoop;
|
|
16
|
+
invoke<T extends (Function<unknown> | Type) = Function<unknown>>(function_: T): Promise<T extends Function<unknown> ? T["__R"] : void>;
|
|
17
|
+
invoke<T extends (Function<unknown> | Type) = Function<unknown>>(function_: T, noWait: true): Promise<void>;
|
|
18
|
+
send<T extends (Function<unknown> | Type) = Function<unknown>>(function_: T): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Connection } from "../connection/connection.js";
|
|
2
|
+
import { Transport } from "../transport/transport.js";
|
|
3
|
+
export declare abstract class ClientAbstract {
|
|
4
|
+
protected transportProvider: (cdn: boolean) => {
|
|
5
|
+
connection: Connection;
|
|
6
|
+
transport: Transport;
|
|
7
|
+
dcId: number;
|
|
8
|
+
};
|
|
9
|
+
connection: Connection;
|
|
10
|
+
transport: Transport;
|
|
11
|
+
dcId: number;
|
|
12
|
+
protected connected: boolean;
|
|
13
|
+
constructor(transportProvider?: (cdn: boolean) => {
|
|
14
|
+
connection: Connection;
|
|
15
|
+
transport: Transport;
|
|
16
|
+
dcId: number;
|
|
17
|
+
});
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
disconnect(): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Function } from "../tl/3_functions.js";
|
|
2
|
+
import { ClientAbstract } from "./client_abstract.js";
|
|
3
|
+
export declare class ClientPlain extends ClientAbstract {
|
|
4
|
+
invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
|
|
5
|
+
createAuthKey(): Promise<{
|
|
6
|
+
authKey: Uint8Array;
|
|
7
|
+
authKeyId: bigint;
|
|
8
|
+
salt: bigint;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MaybePromise } from "../types.js";
|
|
2
|
+
export declare abstract class Connection {
|
|
3
|
+
abstract open(): MaybePromise<void>;
|
|
4
|
+
abstract read(p: Uint8Array): MaybePromise<void>;
|
|
5
|
+
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
6
|
+
abstract close(): MaybePromise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Connection } from "./connection.js";
|
|
2
|
+
export declare class ConnectionWebSocket implements Connection {
|
|
3
|
+
private webSocket;
|
|
4
|
+
private rMutex;
|
|
5
|
+
private wMutex;
|
|
6
|
+
private buffer;
|
|
7
|
+
private nextResolve;
|
|
8
|
+
constructor(url: string | URL);
|
|
9
|
+
open(): Promise<void>;
|
|
10
|
+
read(p: Uint8Array): Promise<void>;
|
|
11
|
+
write(p: Uint8Array): Promise<void>;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */
|
|
2
|
+
interface Rgb {
|
|
3
|
+
r: number;
|
|
4
|
+
g: number;
|
|
5
|
+
b: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Set changing text color to enabled or disabled
|
|
9
|
+
* @param value
|
|
10
|
+
*/
|
|
11
|
+
export declare function setColorEnabled(value: boolean): void;
|
|
12
|
+
/** Get whether text color change is enabled or disabled. */
|
|
13
|
+
export declare function getColorEnabled(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Reset the text modified
|
|
16
|
+
* @param str text to reset
|
|
17
|
+
*/
|
|
18
|
+
export declare function reset(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Make the text bold.
|
|
21
|
+
* @param str text to make bold
|
|
22
|
+
*/
|
|
23
|
+
export declare function bold(str: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* The text emits only a small amount of light.
|
|
26
|
+
* @param str text to dim
|
|
27
|
+
*/
|
|
28
|
+
export declare function dim(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Make the text italic.
|
|
31
|
+
* @param str text to make italic
|
|
32
|
+
*/
|
|
33
|
+
export declare function italic(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Make the text underline.
|
|
36
|
+
* @param str text to underline
|
|
37
|
+
*/
|
|
38
|
+
export declare function underline(str: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Invert background color and text color.
|
|
41
|
+
* @param str text to invert its color
|
|
42
|
+
*/
|
|
43
|
+
export declare function inverse(str: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Make the text hidden.
|
|
46
|
+
* @param str text to hide
|
|
47
|
+
*/
|
|
48
|
+
export declare function hidden(str: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Put horizontal line through the center of the text.
|
|
51
|
+
* @param str text to strike through
|
|
52
|
+
*/
|
|
53
|
+
export declare function strikethrough(str: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Set text color to black.
|
|
56
|
+
* @param str text to make black
|
|
57
|
+
*/
|
|
58
|
+
export declare function black(str: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Set text color to red.
|
|
61
|
+
* @param str text to make red
|
|
62
|
+
*/
|
|
63
|
+
export declare function red(str: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Set text color to green.
|
|
66
|
+
* @param str text to make green
|
|
67
|
+
*/
|
|
68
|
+
export declare function green(str: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Set text color to yellow.
|
|
71
|
+
* @param str text to make yellow
|
|
72
|
+
*/
|
|
73
|
+
export declare function yellow(str: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Set text color to blue.
|
|
76
|
+
* @param str text to make blue
|
|
77
|
+
*/
|
|
78
|
+
export declare function blue(str: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Set text color to magenta.
|
|
81
|
+
* @param str text to make magenta
|
|
82
|
+
*/
|
|
83
|
+
export declare function magenta(str: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Set text color to cyan.
|
|
86
|
+
* @param str text to make cyan
|
|
87
|
+
*/
|
|
88
|
+
export declare function cyan(str: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Set text color to white.
|
|
91
|
+
* @param str text to make white
|
|
92
|
+
*/
|
|
93
|
+
export declare function white(str: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Set text color to gray.
|
|
96
|
+
* @param str text to make gray
|
|
97
|
+
*/
|
|
98
|
+
export declare function gray(str: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Set text color to bright black.
|
|
101
|
+
* @param str text to make bright-black
|
|
102
|
+
*/
|
|
103
|
+
export declare function brightBlack(str: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Set text color to bright red.
|
|
106
|
+
* @param str text to make bright-red
|
|
107
|
+
*/
|
|
108
|
+
export declare function brightRed(str: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* Set text color to bright green.
|
|
111
|
+
* @param str text to make bright-green
|
|
112
|
+
*/
|
|
113
|
+
export declare function brightGreen(str: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Set text color to bright yellow.
|
|
116
|
+
* @param str text to make bright-yellow
|
|
117
|
+
*/
|
|
118
|
+
export declare function brightYellow(str: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Set text color to bright blue.
|
|
121
|
+
* @param str text to make bright-blue
|
|
122
|
+
*/
|
|
123
|
+
export declare function brightBlue(str: string): string;
|
|
124
|
+
/**
|
|
125
|
+
* Set text color to bright magenta.
|
|
126
|
+
* @param str text to make bright-magenta
|
|
127
|
+
*/
|
|
128
|
+
export declare function brightMagenta(str: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Set text color to bright cyan.
|
|
131
|
+
* @param str text to make bright-cyan
|
|
132
|
+
*/
|
|
133
|
+
export declare function brightCyan(str: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Set text color to bright white.
|
|
136
|
+
* @param str text to make bright-white
|
|
137
|
+
*/
|
|
138
|
+
export declare function brightWhite(str: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* Set background color to black.
|
|
141
|
+
* @param str text to make its background black
|
|
142
|
+
*/
|
|
143
|
+
export declare function bgBlack(str: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Set background color to red.
|
|
146
|
+
* @param str text to make its background red
|
|
147
|
+
*/
|
|
148
|
+
export declare function bgRed(str: string): string;
|
|
149
|
+
/**
|
|
150
|
+
* Set background color to green.
|
|
151
|
+
* @param str text to make its background green
|
|
152
|
+
*/
|
|
153
|
+
export declare function bgGreen(str: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Set background color to yellow.
|
|
156
|
+
* @param str text to make its background yellow
|
|
157
|
+
*/
|
|
158
|
+
export declare function bgYellow(str: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Set background color to blue.
|
|
161
|
+
* @param str text to make its background blue
|
|
162
|
+
*/
|
|
163
|
+
export declare function bgBlue(str: string): string;
|
|
164
|
+
/**
|
|
165
|
+
* Set background color to magenta.
|
|
166
|
+
* @param str text to make its background magenta
|
|
167
|
+
*/
|
|
168
|
+
export declare function bgMagenta(str: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Set background color to cyan.
|
|
171
|
+
* @param str text to make its background cyan
|
|
172
|
+
*/
|
|
173
|
+
export declare function bgCyan(str: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* Set background color to white.
|
|
176
|
+
* @param str text to make its background white
|
|
177
|
+
*/
|
|
178
|
+
export declare function bgWhite(str: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Set background color to bright black.
|
|
181
|
+
* @param str text to make its background bright-black
|
|
182
|
+
*/
|
|
183
|
+
export declare function bgBrightBlack(str: string): string;
|
|
184
|
+
/**
|
|
185
|
+
* Set background color to bright red.
|
|
186
|
+
* @param str text to make its background bright-red
|
|
187
|
+
*/
|
|
188
|
+
export declare function bgBrightRed(str: string): string;
|
|
189
|
+
/**
|
|
190
|
+
* Set background color to bright green.
|
|
191
|
+
* @param str text to make its background bright-green
|
|
192
|
+
*/
|
|
193
|
+
export declare function bgBrightGreen(str: string): string;
|
|
194
|
+
/**
|
|
195
|
+
* Set background color to bright yellow.
|
|
196
|
+
* @param str text to make its background bright-yellow
|
|
197
|
+
*/
|
|
198
|
+
export declare function bgBrightYellow(str: string): string;
|
|
199
|
+
/**
|
|
200
|
+
* Set background color to bright blue.
|
|
201
|
+
* @param str text to make its background bright-blue
|
|
202
|
+
*/
|
|
203
|
+
export declare function bgBrightBlue(str: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Set background color to bright magenta.
|
|
206
|
+
* @param str text to make its background bright-magenta
|
|
207
|
+
*/
|
|
208
|
+
export declare function bgBrightMagenta(str: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Set background color to bright cyan.
|
|
211
|
+
* @param str text to make its background bright-cyan
|
|
212
|
+
*/
|
|
213
|
+
export declare function bgBrightCyan(str: string): string;
|
|
214
|
+
/**
|
|
215
|
+
* Set background color to bright white.
|
|
216
|
+
* @param str text to make its background bright-white
|
|
217
|
+
*/
|
|
218
|
+
export declare function bgBrightWhite(str: string): string;
|
|
219
|
+
/**
|
|
220
|
+
* Set text color using paletted 8bit colors.
|
|
221
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
222
|
+
* @param str text color to apply paletted 8bit colors to
|
|
223
|
+
* @param color code
|
|
224
|
+
*/
|
|
225
|
+
export declare function rgb8(str: string, color: number): string;
|
|
226
|
+
/**
|
|
227
|
+
* Set background color using paletted 8bit colors.
|
|
228
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
229
|
+
* @param str text color to apply paletted 8bit background colors to
|
|
230
|
+
* @param color code
|
|
231
|
+
*/
|
|
232
|
+
export declare function bgRgb8(str: string, color: number): string;
|
|
233
|
+
/**
|
|
234
|
+
* Set text color using 24bit rgb.
|
|
235
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
236
|
+
* an `Rgb`.
|
|
237
|
+
*
|
|
238
|
+
* To produce the color magenta:
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { rgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
242
|
+
* rgb24("foo", 0xff00ff);
|
|
243
|
+
* rgb24("foo", {r: 255, g: 0, b: 255});
|
|
244
|
+
* ```
|
|
245
|
+
* @param str text color to apply 24bit rgb to
|
|
246
|
+
* @param color code
|
|
247
|
+
*/
|
|
248
|
+
export declare function rgb24(str: string, color: number | Rgb): string;
|
|
249
|
+
/**
|
|
250
|
+
* Set background color using 24bit rgb.
|
|
251
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
252
|
+
* an `Rgb`.
|
|
253
|
+
*
|
|
254
|
+
* To produce the color magenta:
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* import { bgRgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
258
|
+
* bgRgb24("foo", 0xff00ff);
|
|
259
|
+
* bgRgb24("foo", {r: 255, g: 0, b: 255});
|
|
260
|
+
* ```
|
|
261
|
+
* @param str text color to apply 24bit rgb to
|
|
262
|
+
* @param color code
|
|
263
|
+
*/
|
|
264
|
+
export declare function bgRgb24(str: string, color: number | Rgb): string;
|
|
265
|
+
/**
|
|
266
|
+
* Remove ANSI escape codes from the string.
|
|
267
|
+
* @param string to remove ANSI escape codes from
|
|
268
|
+
*/
|
|
269
|
+
export declare function stripColor(string: string): string;
|
|
270
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum DiffType {
|
|
2
|
+
removed = "removed",
|
|
3
|
+
common = "common",
|
|
4
|
+
added = "added"
|
|
5
|
+
}
|
|
6
|
+
export interface DiffResult<T> {
|
|
7
|
+
type: DiffType;
|
|
8
|
+
value: T;
|
|
9
|
+
details?: Array<DiffResult<T>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders the differences between the actual and expected values
|
|
13
|
+
* @param A Actual value
|
|
14
|
+
* @param B Expected value
|
|
15
|
+
*/
|
|
16
|
+
export declare function diff<T>(A: T[], B: T[]): Array<DiffResult<T>>;
|
|
17
|
+
/**
|
|
18
|
+
* Renders the differences between the actual and expected strings
|
|
19
|
+
* Partially inspired from https://github.com/kpdecker/jsdiff
|
|
20
|
+
* @param A Actual string
|
|
21
|
+
* @param B Expected string
|
|
22
|
+
*/
|
|
23
|
+
export declare function diffstr(A: string, B: string): DiffResult<string>[];
|
|
24
|
+
export declare function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>, { stringDiff }?: {
|
|
25
|
+
stringDiff?: boolean | undefined;
|
|
26
|
+
}): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function format(v: unknown): string;
|