@mtkruto/node 0.132.0 → 0.132.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/0_deps.d.ts +2 -2
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +2 -2
- package/esm/2_connection.d.ts +2 -0
- package/esm/2_connection.d.ts.map +1 -1
- package/esm/2_connection.js +2 -0
- package/esm/3_transport.d.ts +1 -0
- package/esm/3_transport.d.ts.map +1 -1
- package/esm/3_transport.js +1 -0
- package/esm/connection/0_get_tls_header.d.ts +2 -0
- package/esm/connection/0_get_tls_header.d.ts.map +1 -0
- package/esm/connection/0_get_tls_header.js +152 -0
- package/esm/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.node.js +4 -4
- package/esm/connection/1_connection_tls.node.d.ts +31 -0
- package/esm/connection/1_connection_tls.node.d.ts.map +1 -0
- package/esm/connection/1_connection_tls.node.js +199 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/write_all.js +61 -0
- package/esm/session/2_session_encrypted.d.ts.map +1 -1
- package/esm/session/2_session_encrypted.js +4 -1
- package/esm/transport/0_obfuscation.d.ts +5 -1
- package/esm/transport/0_obfuscation.d.ts.map +1 -1
- package/esm/transport/0_obfuscation.js +17 -4
- package/esm/transport/1_transport_intermediate.d.ts +7 -20
- package/esm/transport/1_transport_intermediate.d.ts.map +1 -1
- package/esm/transport/1_transport_intermediate.js +18 -7
- package/esm/transport/2_transport_provider_mtproxy.d.ts +23 -0
- package/esm/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
- package/esm/transport/2_transport_provider_mtproxy.js +51 -0
- package/esm/transport/2_transport_provider_web_socket.js +1 -1
- package/esm/utilities/1_crypto.d.ts +1 -0
- package/esm/utilities/1_crypto.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +4 -0
- package/package.json +1 -1
- package/script/0_deps.d.ts +2 -2
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +4 -3
- package/script/2_connection.d.ts +2 -0
- package/script/2_connection.d.ts.map +1 -1
- package/script/2_connection.js +2 -0
- package/script/3_transport.d.ts +1 -0
- package/script/3_transport.d.ts.map +1 -1
- package/script/3_transport.js +1 -0
- package/script/connection/0_get_tls_header.d.ts +2 -0
- package/script/connection/0_get_tls_header.d.ts.map +1 -0
- package/script/connection/0_get_tls_header.js +188 -0
- package/script/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.node.js +4 -4
- package/script/connection/1_connection_tls.node.d.ts +31 -0
- package/script/connection/1_connection_tls.node.d.ts.map +1 -0
- package/script/connection/1_connection_tls.node.js +203 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts +52 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/io/0.225.3/write_all.js +65 -0
- package/script/session/2_session_encrypted.d.ts.map +1 -1
- package/script/session/2_session_encrypted.js +4 -1
- package/script/transport/0_obfuscation.d.ts +5 -1
- package/script/transport/0_obfuscation.d.ts.map +1 -1
- package/script/transport/0_obfuscation.js +16 -3
- package/script/transport/1_transport_intermediate.d.ts +7 -20
- package/script/transport/1_transport_intermediate.d.ts.map +1 -1
- package/script/transport/1_transport_intermediate.js +52 -8
- package/script/transport/2_transport_provider_mtproxy.d.ts +23 -0
- package/script/transport/2_transport_provider_mtproxy.d.ts.map +1 -0
- package/script/transport/2_transport_provider_mtproxy.js +54 -0
- package/script/transport/2_transport_provider_web_socket.js +1 -1
- package/script/utilities/1_crypto.d.ts +1 -0
- package/script/utilities/1_crypto.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +5 -0
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -4
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -96
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts +0 -3
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/io/0.225.3/_constants.js +0 -7
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts +0 -80
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/io/0.225.3/iterate_reader.js +0 -100
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1_connection_tls.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tls.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AASpD,qBAAa,aAAc,YAAW,UAAU;;IAY9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC;IAarE,IAAI;IAyFV,IAAI,WAAW,YAEd;IAsDK,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAclC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBzC,KAAK;CAKN"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.ConnectionTLS = void 0;
|
|
23
|
+
const node_net_1 = require("node:net");
|
|
24
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
25
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
26
|
+
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
27
|
+
const _0_get_tls_header_js_1 = require("./0_get_tls_header.js");
|
|
28
|
+
const HEADER_LENGTH = 5;
|
|
29
|
+
const MAX_PACKET_LENGTH = 2878;
|
|
30
|
+
const L = (0, _1_utilities_js_1.getLogger)("ConnectionTCP");
|
|
31
|
+
const errConnectionNotOpen = new _0_errors_js_1.ConnectionError("The connection is not open.");
|
|
32
|
+
class ConnectionTLS {
|
|
33
|
+
#hostname;
|
|
34
|
+
#port;
|
|
35
|
+
#secret;
|
|
36
|
+
#socket;
|
|
37
|
+
#rMutex = new _1_utilities_js_1.Mutex();
|
|
38
|
+
#wMutex = new _1_utilities_js_1.Mutex();
|
|
39
|
+
#buffer = new Array();
|
|
40
|
+
#nextResolve = null;
|
|
41
|
+
stateChangeHandler;
|
|
42
|
+
constructor(hostname, port, secret) {
|
|
43
|
+
this.#hostname = hostname;
|
|
44
|
+
this.#port = port;
|
|
45
|
+
this.#secret = (secret[0] === 0xDD || secret[0] === 0xEE) ? secret.slice(1) : secret;
|
|
46
|
+
}
|
|
47
|
+
#rejectRead() {
|
|
48
|
+
if (this.#nextResolve !== null) {
|
|
49
|
+
this.#nextResolve[1].reject(errConnectionNotOpen);
|
|
50
|
+
this.#nextResolve = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async open() {
|
|
54
|
+
if (this.isConnected) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.#socket = new node_net_1.Socket();
|
|
58
|
+
this.#socket.on("close", () => {
|
|
59
|
+
this.#rejectRead();
|
|
60
|
+
this.stateChangeHandler?.(false);
|
|
61
|
+
});
|
|
62
|
+
this.#socket.on("data", (data) => {
|
|
63
|
+
if (typeof data === "string") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const byte of data) {
|
|
67
|
+
this.#buffer.push(byte);
|
|
68
|
+
}
|
|
69
|
+
if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
|
|
70
|
+
const resolve = this.#nextResolve[1].resolve;
|
|
71
|
+
this.#nextResolve = null;
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
await new Promise((resolve, reject) => {
|
|
76
|
+
this.#socket.connect(this.#port, this.#hostname);
|
|
77
|
+
this.#socket.once("error", reject);
|
|
78
|
+
this.#socket.once("connect", () => {
|
|
79
|
+
this.#socket.off("error", reject);
|
|
80
|
+
resolve();
|
|
81
|
+
this.stateChangeHandler?.(true);
|
|
82
|
+
L.debug("connected to", this.#hostname, "port", this.#port);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
const header = await (0, _0_get_tls_header_js_1.getTlsHeader)(this.#secret);
|
|
86
|
+
const helloRand = header.subarray(11, 43);
|
|
87
|
+
await this.#write(header);
|
|
88
|
+
let offset = 0;
|
|
89
|
+
let read = new Uint8Array();
|
|
90
|
+
for (const prefix of [
|
|
91
|
+
new Uint8Array([0x16, 0x03, 0x03]),
|
|
92
|
+
new Uint8Array([0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x17, 0x03, 0x03]),
|
|
93
|
+
]) {
|
|
94
|
+
while (true) {
|
|
95
|
+
if ((read.byteLength - offset) >= (prefix.byteLength + 2)) {
|
|
96
|
+
if (!(0, _0_deps_js_1.startsWith)(read.subarray(offset), prefix)) {
|
|
97
|
+
throw new TypeError("Received an invalid prefix.");
|
|
98
|
+
}
|
|
99
|
+
const dataView = new DataView(read.buffer, read.byteOffset, read.byteLength);
|
|
100
|
+
const size = dataView.getUint16(offset + prefix.byteLength, false);
|
|
101
|
+
const total = prefix.byteLength + 2 + size;
|
|
102
|
+
if ((read.byteLength - offset) >= total) {
|
|
103
|
+
offset += total;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
await new Promise((resolve, reject) => this.#nextResolve = [0, { resolve, reject }]);
|
|
108
|
+
read = (0, _0_deps_js_1.concat)([read, new Uint8Array(this.#buffer.splice(0, this.#buffer.length))]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const response = read.subarray(0, offset);
|
|
112
|
+
const actual = response.slice(11, 43);
|
|
113
|
+
const zeroed = response.slice();
|
|
114
|
+
zeroed.fill(0, 11, 43);
|
|
115
|
+
const expected = await (0, _1_utilities_js_1.hmacSha256)((0, _0_deps_js_1.concat)([helloRand, zeroed]), this.#secret.slice(0, 16));
|
|
116
|
+
if (!(0, _0_deps_js_1.equals)(actual, expected)) {
|
|
117
|
+
throw new TypeError("Failed to initialize TLS connection.");
|
|
118
|
+
}
|
|
119
|
+
L.debug(`initialized TLS connection with ${this.#hostname}`);
|
|
120
|
+
}
|
|
121
|
+
get isConnected() {
|
|
122
|
+
return this.#socket?.readyState === "open";
|
|
123
|
+
}
|
|
124
|
+
#assertConnected() {
|
|
125
|
+
if (!this.isConnected) {
|
|
126
|
+
throw errConnectionNotOpen;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
#packetBuffer = new Uint8Array();
|
|
130
|
+
async #readPacket() {
|
|
131
|
+
const header = new Uint8Array(HEADER_LENGTH);
|
|
132
|
+
await this.#read(header);
|
|
133
|
+
if (!(0, _0_deps_js_1.startsWith)(header, new Uint8Array([0x17, 0x03, 0x03]))) {
|
|
134
|
+
throw new TypeError("Failed to read TLS packet.");
|
|
135
|
+
}
|
|
136
|
+
const length = new DataView(header.buffer).getUint16(3);
|
|
137
|
+
const packet = new Uint8Array(length);
|
|
138
|
+
await this.#read(packet);
|
|
139
|
+
this.#packetBuffer = (0, _0_deps_js_1.concat)([this.#packetBuffer, packet]);
|
|
140
|
+
}
|
|
141
|
+
#isFirstWrite = false;
|
|
142
|
+
async #writePacket(packet) {
|
|
143
|
+
const header = new Uint8Array([0x17, 0x03, 0x03, 0x00, 0x00]);
|
|
144
|
+
new DataView(header.buffer).setUint16(3, packet.byteLength);
|
|
145
|
+
let data = (0, _0_deps_js_1.concat)([header, packet]);
|
|
146
|
+
if (this.#isFirstWrite) {
|
|
147
|
+
this.#isFirstWrite = false;
|
|
148
|
+
data = (0, _0_deps_js_1.concat)([new Uint8Array([0x14, 0x03, 0x03, 0x00, 0x01, 0x01]), data]);
|
|
149
|
+
}
|
|
150
|
+
await this.#write(data);
|
|
151
|
+
}
|
|
152
|
+
async #read(p) {
|
|
153
|
+
if (this.#buffer.length < p.length) {
|
|
154
|
+
await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
|
|
155
|
+
}
|
|
156
|
+
p.set(this.#buffer.splice(0, p.length));
|
|
157
|
+
}
|
|
158
|
+
async #write(p) {
|
|
159
|
+
await new Promise((resolve, reject) => {
|
|
160
|
+
this.#socket.write(p, (err) => {
|
|
161
|
+
(err === undefined || err === null) ? resolve() : reject(err);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async read(p) {
|
|
166
|
+
this.#assertConnected();
|
|
167
|
+
const unlock = await this.#rMutex.lock();
|
|
168
|
+
try {
|
|
169
|
+
while (this.#packetBuffer.byteLength < p.byteLength) {
|
|
170
|
+
await this.#readPacket();
|
|
171
|
+
}
|
|
172
|
+
p.set(this.#packetBuffer.subarray(0, p.byteLength));
|
|
173
|
+
this.#packetBuffer = this.#packetBuffer.slice(p.byteLength);
|
|
174
|
+
}
|
|
175
|
+
finally {
|
|
176
|
+
unlock();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async write(p) {
|
|
180
|
+
this.#assertConnected();
|
|
181
|
+
const unlock = await this.#wMutex.lock();
|
|
182
|
+
try {
|
|
183
|
+
let offset = 0;
|
|
184
|
+
while (true) {
|
|
185
|
+
const packet = p.subarray(offset, offset + MAX_PACKET_LENGTH - HEADER_LENGTH);
|
|
186
|
+
if (packet.byteLength === 0) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
await this.#writePacket(packet);
|
|
190
|
+
offset += packet.byteLength;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
unlock();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
close() {
|
|
198
|
+
this.#assertConnected();
|
|
199
|
+
this.#socket.destroy();
|
|
200
|
+
this.#socket = undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.ConnectionTLS = ConnectionTLS;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Writer, WriterSync } from "./types.js";
|
|
2
|
+
export type { Writer, WriterSync } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Write all the content of the array buffer (`arr`) to the writer (`w`).
|
|
5
|
+
*
|
|
6
|
+
* @example Writing to stdout
|
|
7
|
+
* ```ts no-assert
|
|
8
|
+
* import { writeAll } from "@std/io/write-all";
|
|
9
|
+
*
|
|
10
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
11
|
+
* await writeAll(Deno.stdout, contentBytes);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @example Writing to file
|
|
15
|
+
* ```ts ignore no-assert
|
|
16
|
+
* import { writeAll } from "@std/io/write-all";
|
|
17
|
+
*
|
|
18
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
19
|
+
* using file = await Deno.open('test.file', { write: true });
|
|
20
|
+
* await writeAll(file, contentBytes);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param writer The writer to write to
|
|
24
|
+
* @param data The data to write
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeAll(writer: Writer, data: Uint8Array): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Synchronously write all the content of the array buffer (`arr`) to the
|
|
29
|
+
* writer (`w`).
|
|
30
|
+
*
|
|
31
|
+
* @example "riting to stdout
|
|
32
|
+
* ```ts no-assert
|
|
33
|
+
* import { writeAllSync } from "@std/io/write-all";
|
|
34
|
+
*
|
|
35
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
36
|
+
* writeAllSync(Deno.stdout, contentBytes);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Writing to file
|
|
40
|
+
* ```ts ignore no-assert
|
|
41
|
+
* import { writeAllSync } from "@std/io/write-all";
|
|
42
|
+
*
|
|
43
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
44
|
+
* using file = Deno.openSync("test.file", { write: true });
|
|
45
|
+
* writeAllSync(file, contentBytes);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param writer The writer to write to
|
|
49
|
+
* @param data The data to write
|
|
50
|
+
*/
|
|
51
|
+
export declare function writeAllSync(writer: WriterSync, data: Uint8Array): void;
|
|
52
|
+
//# sourceMappingURL=write_all.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write_all.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/io/0.225.3/write_all.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,iBAK9D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,QAKhE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.writeAll = writeAll;
|
|
6
|
+
exports.writeAllSync = writeAllSync;
|
|
7
|
+
/**
|
|
8
|
+
* Write all the content of the array buffer (`arr`) to the writer (`w`).
|
|
9
|
+
*
|
|
10
|
+
* @example Writing to stdout
|
|
11
|
+
* ```ts no-assert
|
|
12
|
+
* import { writeAll } from "@std/io/write-all";
|
|
13
|
+
*
|
|
14
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
15
|
+
* await writeAll(Deno.stdout, contentBytes);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Writing to file
|
|
19
|
+
* ```ts ignore no-assert
|
|
20
|
+
* import { writeAll } from "@std/io/write-all";
|
|
21
|
+
*
|
|
22
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
23
|
+
* using file = await Deno.open('test.file', { write: true });
|
|
24
|
+
* await writeAll(file, contentBytes);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param writer The writer to write to
|
|
28
|
+
* @param data The data to write
|
|
29
|
+
*/
|
|
30
|
+
async function writeAll(writer, data) {
|
|
31
|
+
let nwritten = 0;
|
|
32
|
+
while (nwritten < data.length) {
|
|
33
|
+
nwritten += await writer.write(data.subarray(nwritten));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Synchronously write all the content of the array buffer (`arr`) to the
|
|
38
|
+
* writer (`w`).
|
|
39
|
+
*
|
|
40
|
+
* @example "riting to stdout
|
|
41
|
+
* ```ts no-assert
|
|
42
|
+
* import { writeAllSync } from "@std/io/write-all";
|
|
43
|
+
*
|
|
44
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
45
|
+
* writeAllSync(Deno.stdout, contentBytes);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Writing to file
|
|
49
|
+
* ```ts ignore no-assert
|
|
50
|
+
* import { writeAllSync } from "@std/io/write-all";
|
|
51
|
+
*
|
|
52
|
+
* const contentBytes = new TextEncoder().encode("Hello World");
|
|
53
|
+
* using file = Deno.openSync("test.file", { write: true });
|
|
54
|
+
* writeAllSync(file, contentBytes);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param writer The writer to write to
|
|
58
|
+
* @param data The data to write
|
|
59
|
+
*/
|
|
60
|
+
function writeAllSync(writer, data) {
|
|
61
|
+
let nwritten = 0;
|
|
62
|
+
while (nwritten < data.length) {
|
|
63
|
+
nwritten += writer.writeSync(data.subarray(nwritten));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAiBZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAQpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAErC;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"2_session_encrypted.d.ts","sourceRoot":"","sources":["../../src/session/2_session_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAwD,OAAO,EAAuC,MAAM,YAAY,CAAC;AAChI,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;IAC5D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxD;AAED,qBAAa,gBAAiB,SAAQ,OAAQ,YAAW,OAAO;;IAI9D,QAAQ,EAAE,QAAQ,CAAM;gBAiBZ,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAQpC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC;IAM7C,IAAI,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAErC;IAEc,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAe9B,UAAU,IAAI,IAAI;IA6ErB,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CA4X3D"}
|
|
@@ -193,10 +193,13 @@ class SessionEncrypted extends _1_session_js_1.Session {
|
|
|
193
193
|
return messageWriter.buffer;
|
|
194
194
|
}
|
|
195
195
|
async #decryptMessage(buffer) {
|
|
196
|
-
|
|
196
|
+
let reader = new _2_tl_js_1.TLReader(buffer);
|
|
197
197
|
(0, _0_deps_js_1.assertEquals)(reader.readInt64(), this.#authKeyId);
|
|
198
198
|
const messageKey_ = reader.readInt128();
|
|
199
199
|
const messageKey = (0, _1_utilities_js_1.intToBytes)(messageKey_, 16);
|
|
200
|
+
if (reader.buffer.length % 16 !== 0) {
|
|
201
|
+
reader = new _2_tl_js_1.TLReader(reader.buffer.subarray(0, -(reader.buffer.length % 16)));
|
|
202
|
+
}
|
|
200
203
|
const a = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([messageKey, this.#authKey.subarray(8, 44)]));
|
|
201
204
|
const b = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([this.#authKey.subarray(48, 84), messageKey]));
|
|
202
205
|
const aesKey = (0, _0_deps_js_1.concat)([a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32)]);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { CTR } from "../1_utilities.js";
|
|
2
2
|
import type { Connection } from "../2_connection.js";
|
|
3
|
-
export
|
|
3
|
+
export interface GetObfuscationParametersParams {
|
|
4
|
+
dcId?: number;
|
|
5
|
+
secret?: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
export declare function getObfuscationParameters(protocol: number, connection: Connection, params?: GetObfuscationParametersParams): Promise<{
|
|
4
8
|
encryptionCTR: CTR;
|
|
5
9
|
decryptionCTR: CTR;
|
|
6
10
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"0_obfuscation.d.ts","sourceRoot":"","sources":["../../src/transport/0_obfuscation.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,GAAG,EAAsB,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,8BAA8B;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,wBAAsB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,8BAA8B;;;GAyD/H"}
|
|
@@ -56,7 +56,7 @@ exports.getObfuscationParameters = getObfuscationParameters;
|
|
|
56
56
|
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
57
57
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
58
58
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
59
|
-
async function getObfuscationParameters(protocol, connection) {
|
|
59
|
+
async function getObfuscationParameters(protocol, connection, params) {
|
|
60
60
|
let init;
|
|
61
61
|
while (true) {
|
|
62
62
|
init = (0, _0_deps_js_1.concat)([dntShim.crypto.getRandomValues(new Uint8Array(56)), (0, _1_utilities_js_1.intToBytes)(protocol, 4, { byteOrder: "big", isSigned: false }), dntShim.crypto.getRandomValues(new Uint8Array(4))]);
|
|
@@ -74,14 +74,27 @@ async function getObfuscationParameters(protocol, connection) {
|
|
|
74
74
|
}
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
if (params?.dcId !== undefined) {
|
|
78
|
+
init.set((0, _1_utilities_js_1.intToBytes)(params.dcId, 2, { byteOrder: "little" }), 60);
|
|
79
|
+
}
|
|
80
|
+
let secret = params?.secret;
|
|
81
|
+
if (secret !== undefined && secret.byteLength >= 17) {
|
|
82
|
+
secret = secret.subarray(1, 17);
|
|
83
|
+
}
|
|
84
|
+
let encryptKey = init.slice(8, 8 + 32);
|
|
78
85
|
const encryptIv = init.slice(40, 40 + 16);
|
|
86
|
+
if (secret) {
|
|
87
|
+
encryptKey = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([encryptKey, secret]));
|
|
88
|
+
}
|
|
79
89
|
const importedEncryptedKey = await _1_utilities_js_1.CTR.importKey(encryptKey);
|
|
80
90
|
const encryptionCTR = new _1_utilities_js_1.CTR(importedEncryptedKey, encryptIv);
|
|
81
91
|
const encryptedInit = await encryptionCTR.call(init);
|
|
82
92
|
const initRev = new Uint8Array(init).reverse();
|
|
83
|
-
|
|
93
|
+
let decryptKey = initRev.slice(8, 8 + 32);
|
|
84
94
|
const decryptIv = initRev.slice(40, 40 + 16);
|
|
95
|
+
if (secret) {
|
|
96
|
+
decryptKey = await (0, _1_utilities_js_1.sha256)((0, _0_deps_js_1.concat)([decryptKey, secret]));
|
|
97
|
+
}
|
|
85
98
|
const importedDecryptKey = await _1_utilities_js_1.CTR.importKey(decryptKey);
|
|
86
99
|
const decryptionCTR = new _1_utilities_js_1.CTR(importedDecryptKey, decryptIv);
|
|
87
100
|
await connection.write((0, _0_deps_js_1.concat)([init.subarray(0, 56), encryptedInit.subarray(56, 56 + 8)]));
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
-
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
-
*
|
|
5
|
-
* This file is part of MTKruto.
|
|
6
|
-
*
|
|
7
|
-
* This program is free software: you can redistribute it and/or modify
|
|
8
|
-
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
-
* (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* This program is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
-
* GNU Lesser General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
-
*/
|
|
20
1
|
import type { Connection } from "../2_connection.js";
|
|
21
2
|
import { Transport } from "./0_transport.js";
|
|
3
|
+
export interface TransportIntermediateParams {
|
|
4
|
+
isObfuscated?: boolean;
|
|
5
|
+
isPadded?: boolean;
|
|
6
|
+
dcId?: number;
|
|
7
|
+
secret?: Uint8Array;
|
|
8
|
+
}
|
|
22
9
|
export declare class TransportIntermediate extends Transport implements Transport {
|
|
23
10
|
#private;
|
|
24
|
-
constructor(connection: Connection,
|
|
11
|
+
constructor(connection: Connection, params?: TransportIntermediateParams);
|
|
25
12
|
initialize(): Promise<void>;
|
|
26
13
|
receive(): Promise<Uint8Array>;
|
|
27
14
|
send(buffer: Uint8Array): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_transport_intermediate.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_intermediate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"1_transport_intermediate.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_intermediate.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,WAAW,2BAA2B;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,qBAAa,qBAAsB,SAAQ,SAAU,YAAW,SAAS;;gBAO3D,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,2BAA2B;IASlE,UAAU;IAYV,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAiB9B,IAAI,CAAC,MAAM,EAAE,UAAU;CAW9B"}
|
|
@@ -1,4 +1,39 @@
|
|
|
1
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.TransportIntermediate = void 0;
|
|
2
37
|
/**
|
|
3
38
|
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
39
|
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
@@ -18,26 +53,31 @@
|
|
|
18
53
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
54
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
55
|
*/
|
|
21
|
-
|
|
22
|
-
exports.TransportIntermediate = void 0;
|
|
56
|
+
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
23
57
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
58
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
25
59
|
const _0_obfuscation_js_1 = require("./0_obfuscation.js");
|
|
26
60
|
const _0_transport_js_1 = require("./0_transport.js");
|
|
27
61
|
class TransportIntermediate extends _0_transport_js_1.Transport {
|
|
28
62
|
#connection;
|
|
29
|
-
#
|
|
30
|
-
|
|
63
|
+
#isObfuscated;
|
|
64
|
+
#isPadded;
|
|
65
|
+
#dcId;
|
|
66
|
+
#secret;
|
|
67
|
+
constructor(connection, params) {
|
|
31
68
|
super();
|
|
32
69
|
this.#connection = connection;
|
|
33
|
-
this.#
|
|
70
|
+
this.#isObfuscated = params?.isObfuscated ?? false;
|
|
71
|
+
this.#isPadded = params?.isPadded ?? false;
|
|
72
|
+
this.#dcId = params?.dcId;
|
|
73
|
+
this.#secret = params?.secret;
|
|
34
74
|
}
|
|
35
75
|
async initialize() {
|
|
36
|
-
if (this.#
|
|
37
|
-
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEEEEEEEE, this.#connection);
|
|
76
|
+
if (this.#isObfuscated) {
|
|
77
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(this.#isPadded ? 0xDDDDDDDD : 0xEEEEEEEE, this.#connection, { dcId: this.#dcId, secret: this.#secret });
|
|
38
78
|
}
|
|
39
79
|
else {
|
|
40
|
-
await this.#connection.write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
|
|
80
|
+
await this.#connection.write(new Uint8Array(this.#isPadded ? [0xDD, 0xDD, 0xDD, 0xDD] : [0xEE, 0xEE, 0xEE, 0xEE]));
|
|
41
81
|
}
|
|
42
82
|
}
|
|
43
83
|
async receive() {
|
|
@@ -54,6 +94,10 @@ class TransportIntermediate extends _0_transport_js_1.Transport {
|
|
|
54
94
|
return await this.decrypt(buffer);
|
|
55
95
|
}
|
|
56
96
|
async send(buffer) {
|
|
97
|
+
if (this.#isPadded) {
|
|
98
|
+
const padding = dntShim.crypto.getRandomValues(new Uint8Array(Math.abs((0, _1_utilities_js_1.getRandomId)(true) % 16)));
|
|
99
|
+
buffer = (0, _0_deps_js_1.concat)([buffer, padding]);
|
|
100
|
+
}
|
|
57
101
|
const length = (0, _1_utilities_js_1.intToBytes)(buffer.length, 4);
|
|
58
102
|
const data = (0, _0_deps_js_1.concat)([length, buffer]);
|
|
59
103
|
await this.#connection.write(await this.encrypt(data));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { type TransportProvider } from "./1_transport_provider.js";
|
|
21
|
+
export declare function transportProviderMtproxy(link: string): TransportProvider;
|
|
22
|
+
export declare function transportProviderMtproxy(hostname: string, port: number, secret: Uint8Array<ArrayBuffer>): TransportProvider;
|
|
23
|
+
//# sourceMappingURL=2_transport_provider_mtproxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2_transport_provider_mtproxy.d.ts","sourceRoot":"","sources":["../../src/transport/2_transport_provider_mtproxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAW,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;AAC1E,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.transportProviderMtproxy = transportProviderMtproxy;
|
|
23
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
|
+
const _1_connection_tcp_node_js_1 = require("../connection/1_connection_tcp.node.js");
|
|
25
|
+
const _1_connection_tls_node_js_1 = require("../connection/1_connection_tls.node.js");
|
|
26
|
+
const _1_transport_intermediate_js_1 = require("./1_transport_intermediate.js");
|
|
27
|
+
const _1_transport_provider_js_1 = require("./1_transport_provider.js");
|
|
28
|
+
function transportProviderMtproxy(hostnameOrLink, port, secret) {
|
|
29
|
+
let hostname = hostnameOrLink;
|
|
30
|
+
if (port === undefined && secret === undefined) {
|
|
31
|
+
const url = new URL(hostnameOrLink);
|
|
32
|
+
const hostname_ = url.searchParams.get("server");
|
|
33
|
+
const port_ = url.searchParams.get("port");
|
|
34
|
+
const secret_ = url.searchParams.get("secret");
|
|
35
|
+
if (!hostname_ || !port_ || !secret_) {
|
|
36
|
+
throw new TypeError("Invalid MTProxy link.");
|
|
37
|
+
}
|
|
38
|
+
hostname = hostname_;
|
|
39
|
+
port = parseInt(port_);
|
|
40
|
+
secret = (0, _0_deps_js_1.decodeHex)(secret_);
|
|
41
|
+
if (isNaN(port) || port < 0 || port > 0xFFFF) {
|
|
42
|
+
throw new TypeError("Server port is invalid.");
|
|
43
|
+
}
|
|
44
|
+
if (secret.byteLength < 16) {
|
|
45
|
+
throw new TypeError("Proxy secret must be at least 16 bytes.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return ({ dc, isCdn }) => {
|
|
49
|
+
const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
|
|
50
|
+
const connection = secret.byteLength <= 17 ? new _1_connection_tcp_node_js_1.ConnectionTCP(hostname, port) : new _1_connection_tls_node_js_1.ConnectionTLS(hostname, port, secret);
|
|
51
|
+
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isPadded: true, isObfuscated: true, secret, dcId });
|
|
52
|
+
return { connection, transport, dcId };
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -39,8 +39,8 @@ const transportProviderWebSocket = (params) => {
|
|
|
39
39
|
params.wss ??= typeof location !== "undefined" && location.protocol === "http:" && location.hostname !== "localhost" ? false : true;
|
|
40
40
|
const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${isCdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
41
41
|
const connection = new _2_connection_js_1.ConnectionWebSocket(url);
|
|
42
|
-
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, true);
|
|
43
42
|
const dcId = (0, _1_transport_provider_js_1.getDcId)(dc, isCdn);
|
|
43
|
+
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, { isObfuscated: true, dcId });
|
|
44
44
|
return { connection, transport, dcId };
|
|
45
45
|
};
|
|
46
46
|
};
|
|
@@ -28,4 +28,5 @@ export declare class CTR {
|
|
|
28
28
|
static importKey(key: Uint8Array<ArrayBuffer>): Promise<dntShim.CryptoKey>;
|
|
29
29
|
call(data: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
|
|
30
30
|
}
|
|
31
|
+
export declare function hmacSha256(data: Uint8Array<ArrayBuffer>, secret: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
|
|
31
32
|
//# sourceMappingURL=1_crypto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_crypto.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAM5C,qBAAa,GAAG;;IAMd,IAAI,MAAM,IAAI;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAE9C;gBAEW,GAAG,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,EAAE,UAAU;WAKrC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IAI1E,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;CAkD5E"}
|
|
1
|
+
{"version":3,"file":"1_crypto.d.ts","sourceRoot":"","sources":["../../src/utilities/1_crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAM5C,qBAAa,GAAG;;IAMd,IAAI,MAAM,IAAI;QAAE,EAAE,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAE9C;gBAEW,GAAG,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,EAAE,UAAU;WAKrC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IAI1E,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;CAkD5E;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,oCAe9F"}
|