@mtkruto/node 0.0.900 → 0.0.902
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/client/client.js +30 -27
- package/esm/client/client_abstract.d.ts +2 -0
- package/esm/client/client_abstract.js +14 -3
- package/esm/client/client_plain.js +20 -6
- package/{script/utilities/1_message.d.ts → esm/client/utilities/0_message.d.ts} +2 -2
- package/esm/{utilities/1_message.js → client/utilities/0_message.js} +10 -10
- package/esm/{utilities/1_password.d.ts → client/utilities/0_password.d.ts} +2 -2
- package/esm/{utilities/1_password.js → client/utilities/0_password.js} +5 -5
- package/esm/connection/connection_web_socket.js +5 -2
- package/esm/constants.d.ts +5 -5
- package/esm/constants.js +8 -6
- package/esm/deps.js +1 -1
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/transport/transport_abridged.js +1 -1
- package/esm/transport/transport_intermediate.js +1 -1
- package/esm/transport/transport_provider.d.ts +7 -4
- package/esm/transport/transport_provider.js +11 -8
- package/esm/{utilities/1_obfuscation.d.ts → transport/utilities/0_obfuscation.d.ts} +2 -2
- package/esm/{utilities/1_obfuscation.js → transport/utilities/0_obfuscation.js} +3 -3
- package/esm/{utilities → types/utilities}/0_html.d.ts +1 -1
- package/esm/{utilities → types/utilities}/0_html.js +2 -2
- package/package.json +1 -1
- package/script/client/client.js +33 -30
- package/script/client/client_abstract.d.ts +2 -0
- package/script/client/client_abstract.js +14 -3
- package/script/client/client_plain.js +22 -8
- package/{esm/utilities/1_message.d.ts → script/client/utilities/0_message.d.ts} +2 -2
- package/script/{utilities/1_message.js → client/utilities/0_message.js} +10 -10
- package/script/{utilities/1_password.d.ts → client/utilities/0_password.d.ts} +2 -2
- package/script/{utilities/1_password.js → client/utilities/0_password.js} +5 -5
- package/script/connection/connection_web_socket.js +4 -1
- package/script/constants.d.ts +5 -5
- package/script/constants.js +31 -6
- package/script/deps.js +1 -1
- package/script/mod.d.ts +1 -1
- package/script/mod.js +2 -2
- package/script/transport/transport_abridged.js +2 -2
- package/script/transport/transport_intermediate.js +2 -2
- package/script/transport/transport_provider.d.ts +7 -4
- package/script/transport/transport_provider.js +11 -8
- package/script/{utilities/1_obfuscation.d.ts → transport/utilities/0_obfuscation.d.ts} +2 -2
- package/script/{utilities/1_obfuscation.js → transport/utilities/0_obfuscation.js} +3 -3
- package/script/{utilities → types/utilities}/0_html.d.ts +1 -1
- package/script/{utilities → types/utilities}/0_html.js +2 -2
- /package/esm/{utilities/1_password_test.d.ts → client/utilities/0_password_test.d.ts} +0 -0
- /package/script/{utilities/1_password_test.d.ts → client/utilities/0_password_test.d.ts} +0 -0
package/script/client/client.js
CHANGED
|
@@ -29,9 +29,6 @@ const constants_js_1 = require("../constants.js");
|
|
|
29
29
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
30
30
|
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
31
31
|
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
32
|
-
const _0_html_js_1 = require("../utilities/0_html.js");
|
|
33
|
-
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
34
|
-
const _1_password_js_1 = require("../utilities/1_password.js");
|
|
35
32
|
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
36
33
|
const types = __importStar(require("../tl/2_types.js"));
|
|
37
34
|
const functions = __importStar(require("../tl/3_functions.js"));
|
|
@@ -42,15 +39,20 @@ const _7_message_container_js_1 = require("../tl/7_message_container.js");
|
|
|
42
39
|
const client_abstract_js_1 = require("./client_abstract.js");
|
|
43
40
|
const client_plain_js_1 = require("./client_plain.js");
|
|
44
41
|
const storage_memory_js_1 = require("../storage/storage_memory.js");
|
|
42
|
+
const _0_html_js_1 = require("../types/utilities/0_html.js");
|
|
45
43
|
const _0_message_entity_js_1 = require("../types/0_message_entity.js");
|
|
46
44
|
const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
|
|
47
45
|
const _0_force_reply_js_1 = require("../types/0_force_reply.js");
|
|
48
46
|
const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
|
|
49
47
|
const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
|
|
50
48
|
const _3_message_js_1 = require("../types/3_message.js"); // high-level wrapper for Telegram API's message
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
49
|
+
const _0_message_js_1 = require("./utilities/0_message.js");
|
|
50
|
+
const _0_password_js_1 = require("./utilities/0_password.js");
|
|
51
|
+
const d = (0, deps_js_1.debug)("Client");
|
|
52
|
+
const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
|
|
53
|
+
const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
54
|
+
const dAuth = (0, deps_js_1.debug)("Client/authorize");
|
|
55
|
+
const dRecv = (0, deps_js_1.debug)("Client/receiveLoop");
|
|
54
56
|
const UPDATE_GAP = Symbol();
|
|
55
57
|
exports.getEntity = Symbol();
|
|
56
58
|
exports.restartAuth = Symbol();
|
|
@@ -187,7 +189,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
187
189
|
if (body instanceof types.GZIPPacked) {
|
|
188
190
|
body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
|
|
189
191
|
}
|
|
190
|
-
|
|
192
|
+
dRecv("received %s", body.constructor.name);
|
|
191
193
|
if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
|
|
192
194
|
await this.processUpdates(body);
|
|
193
195
|
}
|
|
@@ -197,10 +199,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
197
199
|
result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
|
|
198
200
|
}
|
|
199
201
|
if (result instanceof types.RPCError) {
|
|
200
|
-
|
|
202
|
+
dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
|
|
201
203
|
}
|
|
202
204
|
else {
|
|
203
|
-
|
|
205
|
+
dRecv("RPCResult: %s", result.constructor.name);
|
|
204
206
|
}
|
|
205
207
|
if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
|
|
206
208
|
await this.processUpdates(result);
|
|
@@ -273,6 +275,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
273
275
|
if (await this.storage.getDc() != dc) {
|
|
274
276
|
await this.storage.setDc(dc);
|
|
275
277
|
await this.storage.setAuthKey(null);
|
|
278
|
+
await this.storage.getAuthKey();
|
|
276
279
|
}
|
|
277
280
|
super.setDc(dc);
|
|
278
281
|
}
|
|
@@ -314,7 +317,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
314
317
|
}
|
|
315
318
|
await super.connect();
|
|
316
319
|
if (dc == null) {
|
|
317
|
-
await this.storage.setDc(
|
|
320
|
+
await this.storage.setDc(this.transportProvider.initialDc);
|
|
318
321
|
}
|
|
319
322
|
d("enrypted client connected");
|
|
320
323
|
this.receiveLoop();
|
|
@@ -349,7 +352,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
349
352
|
if (!this.apiHash) {
|
|
350
353
|
throw new Error("apiHash not set");
|
|
351
354
|
}
|
|
352
|
-
|
|
355
|
+
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
353
356
|
await this.invoke(new functions.InitConnection({
|
|
354
357
|
apiId: this.apiId,
|
|
355
358
|
appVersion: this.appVersion,
|
|
@@ -372,10 +375,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
372
375
|
if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
|
|
373
376
|
try {
|
|
374
377
|
const password = typeof params.password === "string" ? params.password : await params.password();
|
|
375
|
-
const input = await (0,
|
|
378
|
+
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
376
379
|
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
377
380
|
await this.storage.setAccountType("user");
|
|
378
|
-
|
|
381
|
+
dAuth("authorized as user");
|
|
379
382
|
break;
|
|
380
383
|
}
|
|
381
384
|
catch (err) {
|
|
@@ -411,7 +414,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
411
414
|
try {
|
|
412
415
|
if (params instanceof types.AuthExportedAuthorization) {
|
|
413
416
|
await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
|
|
414
|
-
|
|
417
|
+
dAuth("authorization imported");
|
|
415
418
|
}
|
|
416
419
|
else if (typeof params == "object") {
|
|
417
420
|
while (true) {
|
|
@@ -427,7 +430,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
427
430
|
phoneNumber,
|
|
428
431
|
settings: new types.CodeSettings(),
|
|
429
432
|
}));
|
|
430
|
-
|
|
433
|
+
dAuth("verification code sent");
|
|
431
434
|
if (sentCode instanceof types.AuthSentCode) {
|
|
432
435
|
while (true) {
|
|
433
436
|
const phoneCode = typeof params.code === "string" ? params.code : await params.code();
|
|
@@ -439,7 +442,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
439
442
|
else {
|
|
440
443
|
signedIn = true;
|
|
441
444
|
await this.storage.setAccountType("user");
|
|
442
|
-
|
|
445
|
+
dAuth("authorized as user");
|
|
443
446
|
break;
|
|
444
447
|
}
|
|
445
448
|
}
|
|
@@ -474,7 +477,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
474
477
|
else {
|
|
475
478
|
await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
476
479
|
await this.storage.setAccountType("bot");
|
|
477
|
-
|
|
480
|
+
dAuth("authorized as bot");
|
|
478
481
|
}
|
|
479
482
|
}
|
|
480
483
|
catch (err) {
|
|
@@ -533,10 +536,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
533
536
|
}
|
|
534
537
|
let decrypted;
|
|
535
538
|
try {
|
|
536
|
-
decrypted = await (0,
|
|
539
|
+
decrypted = await (0, _0_message_js_1.decryptMessage)(buffer, this.auth.key, this.auth.id, this.sessionId);
|
|
537
540
|
}
|
|
538
541
|
catch (err) {
|
|
539
|
-
|
|
542
|
+
dRecv("failed to decrypt message: %o", err);
|
|
540
543
|
continue;
|
|
541
544
|
}
|
|
542
545
|
const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
@@ -565,8 +568,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
565
568
|
seqNo++;
|
|
566
569
|
this.state.seqNo++;
|
|
567
570
|
}
|
|
568
|
-
const message = new _6_message_js_1.Message((0,
|
|
569
|
-
await this.transport.send(await (0,
|
|
571
|
+
const message = new _6_message_js_1.Message((0, _0_message_js_1.getMessageId)(), seqNo, function_);
|
|
572
|
+
await this.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
570
573
|
d("invoked %s", function_.constructor.name);
|
|
571
574
|
if (noWait) {
|
|
572
575
|
return;
|
|
@@ -825,7 +828,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
825
828
|
return localState;
|
|
826
829
|
}
|
|
827
830
|
async recoverUpdateGap(source) {
|
|
828
|
-
|
|
831
|
+
dGap("recovering from update gap [%s]", source);
|
|
829
832
|
const release = await this.updateGapRecoveryMutex.acquire();
|
|
830
833
|
try {
|
|
831
834
|
let state = await this.getLocalState();
|
|
@@ -841,7 +844,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
841
844
|
await this.applyUpdateNoGap(update);
|
|
842
845
|
}
|
|
843
846
|
if (difference instanceof types.UpdatesDifference) {
|
|
844
|
-
|
|
847
|
+
dGap("recovered from update gap");
|
|
845
848
|
break;
|
|
846
849
|
}
|
|
847
850
|
else if (difference instanceof types.UpdatesDifferenceSlice) {
|
|
@@ -854,11 +857,11 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
854
857
|
else if (difference instanceof types.UpdatesDifferenceTooLong) {
|
|
855
858
|
// stored messages should be invalidated in case we store messages in the future
|
|
856
859
|
state.pts = difference.pts;
|
|
857
|
-
|
|
860
|
+
dGap("received differenceTooLong");
|
|
858
861
|
}
|
|
859
862
|
else if (difference instanceof types.UpdatesDifferenceEmpty) {
|
|
860
863
|
await this.setUpdateStateDate(difference.date);
|
|
861
|
-
|
|
864
|
+
dGap("there was no update gap");
|
|
862
865
|
break;
|
|
863
866
|
}
|
|
864
867
|
else {
|
|
@@ -871,7 +874,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
871
874
|
}
|
|
872
875
|
}
|
|
873
876
|
async recoverChannelUpdateGap(channelId, source) {
|
|
874
|
-
|
|
877
|
+
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
875
878
|
const release = await this.updateGapRecoveryMutex.acquire();
|
|
876
879
|
try {
|
|
877
880
|
const pts_ = await this.storage.getChannelPts(channelId);
|
|
@@ -894,12 +897,12 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
894
897
|
await this.applyUpdateNoGap(update, false);
|
|
895
898
|
}
|
|
896
899
|
await this.storage.setChannelPts(channelId, difference.pts);
|
|
897
|
-
|
|
900
|
+
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
898
901
|
break;
|
|
899
902
|
}
|
|
900
903
|
else if (difference instanceof types.UpdatesChannelDifferenceTooLong) {
|
|
901
904
|
// invalidate messages
|
|
902
|
-
|
|
905
|
+
dGapC("received channelDifferenceTooLong");
|
|
903
906
|
await this.processChats(difference.chats);
|
|
904
907
|
await this.processUsers(difference.users);
|
|
905
908
|
for (const message of difference.messages) {
|
|
@@ -912,10 +915,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
912
915
|
else {
|
|
913
916
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
914
917
|
}
|
|
915
|
-
|
|
918
|
+
dGapC("processed channelDifferenceTooLong");
|
|
916
919
|
}
|
|
917
920
|
else if (difference instanceof types.UpdatesChannelDifferenceEmpty) {
|
|
918
|
-
|
|
921
|
+
dGapC("there was no update gap");
|
|
919
922
|
break;
|
|
920
923
|
}
|
|
921
924
|
}
|
|
@@ -7,6 +7,8 @@ export declare abstract class ClientAbstract {
|
|
|
7
7
|
protected connection: Connection;
|
|
8
8
|
protected transport: Transport;
|
|
9
9
|
private _dcId;
|
|
10
|
+
private _initialDc;
|
|
11
|
+
get initialDc(): DC;
|
|
10
12
|
constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
|
|
11
13
|
get dcId(): number;
|
|
12
14
|
setDc(dc: DC): MaybePromise<void>;
|
|
@@ -5,6 +5,9 @@ const deps_js_1 = require("../deps.js");
|
|
|
5
5
|
const constants_js_1 = require("../constants.js");
|
|
6
6
|
const transport_provider_js_1 = require("../transport/transport_provider.js");
|
|
7
7
|
class ClientAbstract {
|
|
8
|
+
get initialDc() {
|
|
9
|
+
return this._initialDc;
|
|
10
|
+
}
|
|
8
11
|
constructor(transportProvider = (0, transport_provider_js_1.defaultTransportProvider)({ initialDc: constants_js_1.DEFAULT_INITIAL_DC })) {
|
|
9
12
|
Object.defineProperty(this, "transportProvider", {
|
|
10
13
|
enumerable: true,
|
|
@@ -30,7 +33,15 @@ class ClientAbstract {
|
|
|
30
33
|
writable: true,
|
|
31
34
|
value: void 0
|
|
32
35
|
});
|
|
33
|
-
|
|
36
|
+
Object.defineProperty(this, "_initialDc", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
const { initialDc, createTransport } = transportProvider;
|
|
43
|
+
this._initialDc = initialDc;
|
|
44
|
+
const { connection, transport, dcId } = createTransport({ cdn: false });
|
|
34
45
|
this.connection = connection;
|
|
35
46
|
this.transport = transport;
|
|
36
47
|
this._dcId = dcId;
|
|
@@ -40,7 +51,7 @@ class ClientAbstract {
|
|
|
40
51
|
}
|
|
41
52
|
// MaybePromise since `Client` has to deal with `Storage.set()`
|
|
42
53
|
setDc(dc) {
|
|
43
|
-
const { connection, transport, dcId } = this.transportProvider({ dc, cdn: false });
|
|
54
|
+
const { connection, transport, dcId } = this.transportProvider.createTransport({ dc, cdn: false });
|
|
44
55
|
this.connection = connection;
|
|
45
56
|
this.transport = transport;
|
|
46
57
|
this._dcId = dcId;
|
|
@@ -56,7 +67,7 @@ class ClientAbstract {
|
|
|
56
67
|
async reconnect(dc) {
|
|
57
68
|
await this.disconnect();
|
|
58
69
|
if (dc) {
|
|
59
|
-
this.setDc(dc);
|
|
70
|
+
await this.setDc(dc);
|
|
60
71
|
}
|
|
61
72
|
await this.connect();
|
|
62
73
|
}
|
|
@@ -5,18 +5,19 @@ const deps_js_1 = require("../deps.js");
|
|
|
5
5
|
const constants_js_1 = require("../constants.js");
|
|
6
6
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
7
7
|
const _0_buffer_js_1 = require("../utilities/0_buffer.js");
|
|
8
|
+
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
8
9
|
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
9
10
|
const _1_auth_js_1 = require("../utilities/1_auth.js");
|
|
10
11
|
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
11
|
-
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
12
12
|
const _2_types_js_1 = require("../tl/2_types.js");
|
|
13
13
|
const _3_functions_js_1 = require("../tl/3_functions.js");
|
|
14
14
|
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
15
15
|
const client_abstract_js_1 = require("./client_abstract.js");
|
|
16
|
-
const
|
|
16
|
+
const _0_message_js_1 = require("./utilities/0_message.js");
|
|
17
|
+
const d = (0, deps_js_1.debug)("ClientPlain/createAuthKey");
|
|
17
18
|
class ClientPlain extends client_abstract_js_1.ClientAbstract {
|
|
18
19
|
async invoke(function_) {
|
|
19
|
-
await this.transport.send((0,
|
|
20
|
+
await this.transport.send((0, _0_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize]()));
|
|
20
21
|
const buffer = await this.transport.receive();
|
|
21
22
|
if (buffer.length == 4) {
|
|
22
23
|
const int = (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, true);
|
|
@@ -24,17 +25,30 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
|
|
|
24
25
|
throw new Error("-404");
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
const { message } = (0,
|
|
28
|
+
const { message } = (0, _0_message_js_1.unpackUnencryptedMessage)(buffer);
|
|
28
29
|
const reader = new _3_tl_reader_js_1.TLReader(message);
|
|
29
30
|
return reader.readObject();
|
|
30
31
|
}
|
|
31
32
|
async createAuthKey() {
|
|
32
33
|
const nonce = (0, _0_bigint_js_1.getRandomBigInt)(16, false, true);
|
|
33
34
|
d("auth key creation started");
|
|
34
|
-
|
|
35
|
-
(0
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
let resPq = null;
|
|
36
|
+
for (let i = 0; i < 10; i++) {
|
|
37
|
+
try {
|
|
38
|
+
d("req_pq_multi [%d]", i + 1);
|
|
39
|
+
resPq = await this.invoke(new _3_functions_js_1.ReqPQMulti({ nonce }));
|
|
40
|
+
(0, deps_js_1.assertInstanceOf)(resPq, _2_types_js_1.ResPQ);
|
|
41
|
+
(0, deps_js_1.assertEquals)(resPq.nonce, nonce);
|
|
42
|
+
d("got res_pq");
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
d("req_pq_multi error: %o", err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!resPq) {
|
|
50
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
51
|
+
}
|
|
38
52
|
const pq_ = (0, _0_bigint_js_1.bigIntFromBuffer)(resPq.pq, false, false);
|
|
39
53
|
const [p_, q_] = (0, deps_js_1.factorize)(pq_);
|
|
40
54
|
d("factorized pq");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Message } from "
|
|
2
|
-
import { MessageContainer } from "
|
|
1
|
+
import { Message } from "../../tl/6_message.js";
|
|
2
|
+
import { MessageContainer } from "../../tl/7_message_container.js";
|
|
3
3
|
export declare function getMessageId(): bigint;
|
|
4
4
|
export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
|
|
5
5
|
export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decryptMessage = exports.encryptMessage = exports.unpackUnencryptedMessage = exports.packUnencryptedMessage = exports.getMessageId = void 0;
|
|
4
|
-
const deps_js_1 = require("
|
|
5
|
-
const _0_tl_raw_reader_js_1 = require("
|
|
6
|
-
const _0_tl_raw_writer_js_1 = require("
|
|
7
|
-
const _1_tl_object_js_1 = require("
|
|
8
|
-
const _3_tl_reader_js_1 = require("
|
|
9
|
-
const _5_rpc_result_js_1 = require("
|
|
10
|
-
const _6_message_js_1 = require("
|
|
11
|
-
const _7_message_container_js_1 = require("
|
|
12
|
-
const _0_buffer_js_1 = require("
|
|
13
|
-
const _0_hash_js_1 = require("
|
|
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 _5_rpc_result_js_1 = require("../../tl/5_rpc_result.js");
|
|
10
|
+
const _6_message_js_1 = require("../../tl/6_message.js");
|
|
11
|
+
const _7_message_container_js_1 = require("../../tl/7_message_container.js");
|
|
12
|
+
const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
|
|
13
|
+
const _0_hash_js_1 = require("../../utilities/0_hash.js");
|
|
14
14
|
let lastMsgId = 0n;
|
|
15
15
|
function getMessageId() {
|
|
16
16
|
const now = new Date().getTime() / 1000 + 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as types from "
|
|
2
|
-
import { sha256 } from "
|
|
1
|
+
import * as types from "../../tl/2_types.js";
|
|
2
|
+
import { sha256 } from "../../utilities/0_hash.js";
|
|
3
3
|
export declare function isSafePrime(primeBytes: Uint8Array, g: number): boolean;
|
|
4
4
|
export declare const h: typeof sha256;
|
|
5
5
|
export declare const sh: (data: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;
|
|
@@ -24,11 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.checkPassword = exports.pad = exports.isGoodModExpFirst = exports.ph2 = exports.pbkdf2 = exports.ph1 = exports.sh = exports.h = exports.isSafePrime = void 0;
|
|
27
|
-
const dntShim = __importStar(require("
|
|
28
|
-
const types = __importStar(require("
|
|
29
|
-
const _0_buffer_js_1 = require("
|
|
30
|
-
const _0_hash_js_1 = require("
|
|
31
|
-
const _0_bigint_js_1 = require("
|
|
27
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
28
|
+
const types = __importStar(require("../../tl/2_types.js"));
|
|
29
|
+
const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
|
|
30
|
+
const _0_hash_js_1 = require("../../utilities/0_hash.js");
|
|
31
|
+
const _0_bigint_js_1 = require("../../utilities/0_bigint.js");
|
|
32
32
|
function isSafePrime(primeBytes, g) {
|
|
33
33
|
// deno-fmt-ignore
|
|
34
34
|
const goodPrime = new Uint8Array([
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.ConnectionWebSocket = void 0;
|
|
27
27
|
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
28
28
|
const deps_js_1 = require("../deps.js");
|
|
29
|
+
const d = (0, deps_js_1.debug)("ConnectionWebSocket");
|
|
29
30
|
class ConnectionWebSocket {
|
|
30
31
|
constructor(url) {
|
|
31
32
|
Object.defineProperty(this, "webSocket", {
|
|
@@ -70,7 +71,9 @@ class ConnectionWebSocket {
|
|
|
70
71
|
this.nextResolve = null;
|
|
71
72
|
}
|
|
72
73
|
};
|
|
73
|
-
this.webSocket.onerror =
|
|
74
|
+
this.webSocket.onerror = (err) => {
|
|
75
|
+
d("WebSocket error: %O", err);
|
|
76
|
+
};
|
|
74
77
|
}
|
|
75
78
|
get connected() {
|
|
76
79
|
return this.webSocket.readyState == dntShim.WebSocket.OPEN;
|
package/script/constants.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto
|
|
8
|
-
export declare const DEFAULT_DEVICE_MODEL
|
|
9
|
-
export declare const DEFAULT_LANG_CODE
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.902";
|
|
8
|
+
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
|
+
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
|
11
|
-
export declare const DEFAULT_SYSTEM_LANG_CODE
|
|
12
|
-
export declare const DEFAULT_SYSTEM_VERSION
|
|
11
|
+
export declare const DEFAULT_SYSTEM_LANG_CODE: string;
|
|
12
|
+
export declare const DEFAULT_SYSTEM_VERSION: string;
|
|
13
13
|
export declare const USERNAME_TTL = 86400;
|
|
14
14
|
export declare const MAX_CHAT_ID = 999999999999;
|
|
15
15
|
export declare const MAX_CHANNEL_ID = 997852516352;
|
package/script/constants.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
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 (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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.CHANNEL_DIFFERENCE_LIMIT_BOT = exports.CHANNEL_DIFFERENCE_LIMIT_USER = exports.ZERO_CHANNEL_ID = exports.MAX_CHANNEL_ID = exports.MAX_CHAT_ID = exports.USERNAME_TTL = exports.DEFAULT_SYSTEM_VERSION = exports.DEFAULT_SYSTEM_LANG_CODE = exports.DEFAULT_LANG_PACK = exports.DEFAULT_LANG_CODE = exports.DEFAULT_DEVICE_MODEL = exports.DEFAULT_APP_VERSION = exports.LAYER = exports.DEFAULT_INITIAL_DC = exports.VECTOR_CONSTRUCTOR = exports.publicKeys = exports.ackThreshold = void 0;
|
|
27
|
+
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
4
28
|
exports.ackThreshold = 10;
|
|
5
29
|
exports.publicKeys = new Map([
|
|
6
30
|
[
|
|
@@ -64,13 +88,14 @@ exports.publicKeys = new Map([
|
|
|
64
88
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
65
89
|
exports.DEFAULT_INITIAL_DC = "2-test";
|
|
66
90
|
exports.LAYER = 158;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
exports.DEFAULT_DEVICE_MODEL = "
|
|
70
|
-
exports.DEFAULT_LANG_CODE = "en";
|
|
91
|
+
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.902";
|
|
92
|
+
// @ts-ignore: lib
|
|
93
|
+
exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
94
|
+
exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
71
95
|
exports.DEFAULT_LANG_PACK = "";
|
|
72
|
-
exports.DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
73
|
-
|
|
96
|
+
exports.DEFAULT_SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
97
|
+
// @ts-ignore: lib
|
|
98
|
+
exports.DEFAULT_SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
|
|
74
99
|
exports.USERNAME_TTL = 86400;
|
|
75
100
|
exports.MAX_CHAT_ID = 999999999999;
|
|
76
101
|
exports.MAX_CHANNEL_ID = 997852516352;
|
package/script/deps.js
CHANGED
|
@@ -31,7 +31,7 @@ Object.defineProperty(exports, "Mutex", { enumerable: true, get: function () { r
|
|
|
31
31
|
var mod_js_2 = require("./deps/deno.land/x/html_parser@v0.1.3/src/mod.js");
|
|
32
32
|
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return mod_js_2.Parser; } });
|
|
33
33
|
const mod_js_3 = require("./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js");
|
|
34
|
-
const debug = (v) => (0, mod_js_3.debug)(`
|
|
34
|
+
const debug = (v) => (0, mod_js_3.debug)(`mtkruto/${v}`);
|
|
35
35
|
exports.debug = debug;
|
|
36
36
|
var mod_js_4 = require("./deps/deno.land/x/q@v0.0.1/mod.js");
|
|
37
37
|
Object.defineProperty(exports, "queue", { enumerable: true, get: function () { return mod_js_4.queue; } });
|
package/script/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { checkPassword } from "./utilities/1_password.js";
|
|
2
1
|
import { getRandomId } from "./utilities/0_bigint.js";
|
|
2
|
+
import { checkPassword } from "./client/utilities/0_password.js";
|
|
3
3
|
export declare const utils: {
|
|
4
4
|
checkPassword: typeof checkPassword;
|
|
5
5
|
getRandomId: typeof getRandomId;
|
package/script/mod.js
CHANGED
|
@@ -27,9 +27,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.LAYER = exports.DEFAULT_SYSTEM_VERSION = exports.DEFAULT_SYSTEM_LANG_CODE = exports.DEFAULT_LANG_PACK = exports.DEFAULT_LANG_CODE = exports.DEFAULT_INITIAL_DC = exports.DEFAULT_DEVICE_MODEL = exports.DEFAULT_APP_VERSION = exports.functions = exports.types = exports.as = exports.utils = void 0;
|
|
30
|
-
const _1_password_js_1 = require("./utilities/1_password.js");
|
|
31
30
|
const _0_bigint_js_1 = require("./utilities/0_bigint.js");
|
|
32
|
-
|
|
31
|
+
const _0_password_js_1 = require("./client/utilities/0_password.js");
|
|
32
|
+
exports.utils = { checkPassword: _0_password_js_1.checkPassword, getRandomId: _0_bigint_js_1.getRandomId };
|
|
33
33
|
var _1_tl_object_js_1 = require("./tl/1_tl_object.js");
|
|
34
34
|
Object.defineProperty(exports, "as", { enumerable: true, get: function () { return _1_tl_object_js_1.as; } });
|
|
35
35
|
exports.types = __importStar(require("./tl/2_types.js"));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransportAbridged = void 0;
|
|
4
4
|
const _0_buffer_js_1 = require("../utilities/0_buffer.js");
|
|
5
|
-
const
|
|
5
|
+
const _0_obfuscation_js_1 = require("./utilities/0_obfuscation.js");
|
|
6
6
|
const transport_js_1 = require("./transport.js");
|
|
7
7
|
class TransportAbridged extends transport_js_1.Transport {
|
|
8
8
|
constructor(connection, obfuscated = false) {
|
|
@@ -23,7 +23,7 @@ class TransportAbridged extends transport_js_1.Transport {
|
|
|
23
23
|
async initialize() {
|
|
24
24
|
if (!this.initialized) {
|
|
25
25
|
if (this.obfuscated) {
|
|
26
|
-
this.obfuscationParameters = await (0,
|
|
26
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEFEFEFEF, this.connection);
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
await this.connection.write(new Uint8Array([0xEF]));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransportIntermediate = void 0;
|
|
4
4
|
const _0_buffer_js_1 = require("../utilities/0_buffer.js");
|
|
5
|
-
const
|
|
5
|
+
const _0_obfuscation_js_1 = require("./utilities/0_obfuscation.js");
|
|
6
6
|
const transport_js_1 = require("./transport.js");
|
|
7
7
|
class TransportIntermediate extends transport_js_1.Transport {
|
|
8
8
|
constructor(connection, obfuscated = false) {
|
|
@@ -23,7 +23,7 @@ class TransportIntermediate extends transport_js_1.Transport {
|
|
|
23
23
|
async initialize() {
|
|
24
24
|
if (!this.initialized) {
|
|
25
25
|
if (this.obfuscated) {
|
|
26
|
-
this.obfuscationParameters = await (0,
|
|
26
|
+
this.obfuscationParameters = await (0, _0_obfuscation_js_1.getObfuscationParameters)(0xEEEEEEEE, this.connection);
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
await this.connection.write(new Uint8Array([0xEE, 0xEE, 0xEE, 0xEE]));
|
|
@@ -5,10 +5,13 @@ export interface TransportProviderParams {
|
|
|
5
5
|
dc?: DC;
|
|
6
6
|
cdn: boolean;
|
|
7
7
|
}
|
|
8
|
-
export type TransportProvider =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export type TransportProvider = {
|
|
9
|
+
initialDc: DC;
|
|
10
|
+
createTransport: (params: TransportProviderParams) => {
|
|
11
|
+
connection: Connection;
|
|
12
|
+
transport: Transport;
|
|
13
|
+
dcId: number;
|
|
14
|
+
};
|
|
12
15
|
};
|
|
13
16
|
export interface TransportProviderCreatorParams {
|
|
14
17
|
initialDc: DC;
|
|
@@ -14,14 +14,17 @@ const dcToNameMap = {
|
|
|
14
14
|
"5": "flora",
|
|
15
15
|
};
|
|
16
16
|
const defaultTransportProvider = ({ initialDc, wss }) => {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
return {
|
|
18
|
+
initialDc,
|
|
19
|
+
createTransport: ({ dc, cdn }) => {
|
|
20
|
+
dc ??= initialDc;
|
|
21
|
+
wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
|
|
22
|
+
const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
23
|
+
const connection = new connection_web_socket_js_1.ConnectionWebSocket(url);
|
|
24
|
+
const transport = new transport_intermediate_js_1.TransportIntermediate(connection, true);
|
|
25
|
+
const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
|
|
26
|
+
return { connection, transport, dcId };
|
|
27
|
+
},
|
|
25
28
|
};
|
|
26
29
|
};
|
|
27
30
|
exports.defaultTransportProvider = defaultTransportProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CTR } from "../../utilities/0_crypto.js";
|
|
2
|
+
import { Connection } from "../../connection/connection.js";
|
|
3
3
|
export declare function getObfuscationParameters(protocol: number, connection: Connection): Promise<{
|
|
4
4
|
encryptionCTR: CTR;
|
|
5
5
|
decryptionCTR: CTR;
|
|
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getObfuscationParameters = void 0;
|
|
27
|
-
const dntShim = __importStar(require("
|
|
28
|
-
const _0_buffer_js_1 = require("
|
|
29
|
-
const _0_crypto_js_1 = require("
|
|
27
|
+
const dntShim = __importStar(require("../../_dnt.shims.js"));
|
|
28
|
+
const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
|
|
29
|
+
const _0_crypto_js_1 = require("../../utilities/0_crypto.js");
|
|
30
30
|
async function getObfuscationParameters(protocol, connection) {
|
|
31
31
|
const dc = 0xFCFF;
|
|
32
32
|
let init;
|