@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/esm/client/client.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { debug, gunzip, Mutex, queue } from "../deps.js";
|
|
2
|
-
import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL,
|
|
2
|
+
import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
|
|
3
3
|
import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
|
|
4
4
|
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
5
5
|
import { sha1 } from "../utilities/0_hash.js";
|
|
6
|
-
import { parseHtml } from "../utilities/0_html.js";
|
|
7
|
-
import { decryptMessage, encryptMessage, getMessageId } from "../utilities/1_message.js";
|
|
8
|
-
import { checkPassword } from "../utilities/1_password.js";
|
|
9
6
|
import { as } from "../tl/1_tl_object.js";
|
|
10
7
|
import * as types from "../tl/2_types.js";
|
|
11
8
|
import * as functions from "../tl/3_functions.js";
|
|
@@ -16,15 +13,20 @@ import { MessageContainer } from "../tl/7_message_container.js";
|
|
|
16
13
|
import { ClientAbstract } from "./client_abstract.js";
|
|
17
14
|
import { ClientPlain } from "./client_plain.js";
|
|
18
15
|
import { StorageMemory } from "../storage/storage_memory.js";
|
|
16
|
+
import { parseHtml } from "../types/utilities/0_html.js";
|
|
19
17
|
import { messageEntityToTlObject } from "../types/0_message_entity.js";
|
|
20
18
|
import { replyKeyboardRemoveToTlObject } from "../types/0_reply_keyboard_remove.js";
|
|
21
19
|
import { forceReplyToTlObject } from "../types/0_force_reply.js";
|
|
22
20
|
import { replyKeyboardMarkupToTlObject } from "../types/2_reply_keyboard_markup.js";
|
|
23
21
|
import { inlineKeyboardMarkupToTlObject } from "../types/2_inline_keyboard_markup.js";
|
|
24
22
|
import { constructMessage } from "../types/3_message.js"; // high-level wrapper for Telegram API's message
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
23
|
+
import { decryptMessage, encryptMessage, getMessageId } from "./utilities/0_message.js";
|
|
24
|
+
import { checkPassword } from "./utilities/0_password.js";
|
|
25
|
+
const d = debug("Client");
|
|
26
|
+
const dGap = debug("Client/recoverUpdateGap");
|
|
27
|
+
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
28
|
+
const dAuth = debug("Client/authorize");
|
|
29
|
+
const dRecv = debug("Client/receiveLoop");
|
|
28
30
|
const UPDATE_GAP = Symbol();
|
|
29
31
|
export const getEntity = Symbol();
|
|
30
32
|
export const restartAuth = Symbol();
|
|
@@ -161,7 +163,7 @@ export class Client extends ClientAbstract {
|
|
|
161
163
|
if (body instanceof types.GZIPPacked) {
|
|
162
164
|
body = new TLReader(gunzip(body.packedData)).readObject();
|
|
163
165
|
}
|
|
164
|
-
|
|
166
|
+
dRecv("received %s", body.constructor.name);
|
|
165
167
|
if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
|
|
166
168
|
await this.processUpdates(body);
|
|
167
169
|
}
|
|
@@ -171,10 +173,10 @@ export class Client extends ClientAbstract {
|
|
|
171
173
|
result = new TLReader(gunzip(result.packedData)).readObject();
|
|
172
174
|
}
|
|
173
175
|
if (result instanceof types.RPCError) {
|
|
174
|
-
|
|
176
|
+
dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
|
|
175
177
|
}
|
|
176
178
|
else {
|
|
177
|
-
|
|
179
|
+
dRecv("RPCResult: %s", result.constructor.name);
|
|
178
180
|
}
|
|
179
181
|
if (result instanceof types.Updates || result instanceof types.TypeUpdate) {
|
|
180
182
|
await this.processUpdates(result);
|
|
@@ -247,6 +249,7 @@ export class Client extends ClientAbstract {
|
|
|
247
249
|
if (await this.storage.getDc() != dc) {
|
|
248
250
|
await this.storage.setDc(dc);
|
|
249
251
|
await this.storage.setAuthKey(null);
|
|
252
|
+
await this.storage.getAuthKey();
|
|
250
253
|
}
|
|
251
254
|
super.setDc(dc);
|
|
252
255
|
}
|
|
@@ -288,7 +291,7 @@ export class Client extends ClientAbstract {
|
|
|
288
291
|
}
|
|
289
292
|
await super.connect();
|
|
290
293
|
if (dc == null) {
|
|
291
|
-
await this.storage.setDc(
|
|
294
|
+
await this.storage.setDc(this.transportProvider.initialDc);
|
|
292
295
|
}
|
|
293
296
|
d("enrypted client connected");
|
|
294
297
|
this.receiveLoop();
|
|
@@ -323,7 +326,7 @@ export class Client extends ClientAbstract {
|
|
|
323
326
|
if (!this.apiHash) {
|
|
324
327
|
throw new Error("apiHash not set");
|
|
325
328
|
}
|
|
326
|
-
|
|
329
|
+
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
327
330
|
await this.invoke(new functions.InitConnection({
|
|
328
331
|
apiId: this.apiId,
|
|
329
332
|
appVersion: this.appVersion,
|
|
@@ -349,7 +352,7 @@ export class Client extends ClientAbstract {
|
|
|
349
352
|
const input = await checkPassword(password, ap);
|
|
350
353
|
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
351
354
|
await this.storage.setAccountType("user");
|
|
352
|
-
|
|
355
|
+
dAuth("authorized as user");
|
|
353
356
|
break;
|
|
354
357
|
}
|
|
355
358
|
catch (err) {
|
|
@@ -385,7 +388,7 @@ export class Client extends ClientAbstract {
|
|
|
385
388
|
try {
|
|
386
389
|
if (params instanceof types.AuthExportedAuthorization) {
|
|
387
390
|
await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
|
|
388
|
-
|
|
391
|
+
dAuth("authorization imported");
|
|
389
392
|
}
|
|
390
393
|
else if (typeof params == "object") {
|
|
391
394
|
while (true) {
|
|
@@ -401,7 +404,7 @@ export class Client extends ClientAbstract {
|
|
|
401
404
|
phoneNumber,
|
|
402
405
|
settings: new types.CodeSettings(),
|
|
403
406
|
}));
|
|
404
|
-
|
|
407
|
+
dAuth("verification code sent");
|
|
405
408
|
if (sentCode instanceof types.AuthSentCode) {
|
|
406
409
|
while (true) {
|
|
407
410
|
const phoneCode = typeof params.code === "string" ? params.code : await params.code();
|
|
@@ -413,7 +416,7 @@ export class Client extends ClientAbstract {
|
|
|
413
416
|
else {
|
|
414
417
|
signedIn = true;
|
|
415
418
|
await this.storage.setAccountType("user");
|
|
416
|
-
|
|
419
|
+
dAuth("authorized as user");
|
|
417
420
|
break;
|
|
418
421
|
}
|
|
419
422
|
}
|
|
@@ -448,7 +451,7 @@ export class Client extends ClientAbstract {
|
|
|
448
451
|
else {
|
|
449
452
|
await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
|
|
450
453
|
await this.storage.setAccountType("bot");
|
|
451
|
-
|
|
454
|
+
dAuth("authorized as bot");
|
|
452
455
|
}
|
|
453
456
|
}
|
|
454
457
|
catch (err) {
|
|
@@ -510,7 +513,7 @@ export class Client extends ClientAbstract {
|
|
|
510
513
|
decrypted = await decryptMessage(buffer, this.auth.key, this.auth.id, this.sessionId);
|
|
511
514
|
}
|
|
512
515
|
catch (err) {
|
|
513
|
-
|
|
516
|
+
dRecv("failed to decrypt message: %o", err);
|
|
514
517
|
continue;
|
|
515
518
|
}
|
|
516
519
|
const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
|
|
@@ -799,7 +802,7 @@ export class Client extends ClientAbstract {
|
|
|
799
802
|
return localState;
|
|
800
803
|
}
|
|
801
804
|
async recoverUpdateGap(source) {
|
|
802
|
-
|
|
805
|
+
dGap("recovering from update gap [%s]", source);
|
|
803
806
|
const release = await this.updateGapRecoveryMutex.acquire();
|
|
804
807
|
try {
|
|
805
808
|
let state = await this.getLocalState();
|
|
@@ -815,7 +818,7 @@ export class Client extends ClientAbstract {
|
|
|
815
818
|
await this.applyUpdateNoGap(update);
|
|
816
819
|
}
|
|
817
820
|
if (difference instanceof types.UpdatesDifference) {
|
|
818
|
-
|
|
821
|
+
dGap("recovered from update gap");
|
|
819
822
|
break;
|
|
820
823
|
}
|
|
821
824
|
else if (difference instanceof types.UpdatesDifferenceSlice) {
|
|
@@ -828,11 +831,11 @@ export class Client extends ClientAbstract {
|
|
|
828
831
|
else if (difference instanceof types.UpdatesDifferenceTooLong) {
|
|
829
832
|
// stored messages should be invalidated in case we store messages in the future
|
|
830
833
|
state.pts = difference.pts;
|
|
831
|
-
|
|
834
|
+
dGap("received differenceTooLong");
|
|
832
835
|
}
|
|
833
836
|
else if (difference instanceof types.UpdatesDifferenceEmpty) {
|
|
834
837
|
await this.setUpdateStateDate(difference.date);
|
|
835
|
-
|
|
838
|
+
dGap("there was no update gap");
|
|
836
839
|
break;
|
|
837
840
|
}
|
|
838
841
|
else {
|
|
@@ -845,7 +848,7 @@ export class Client extends ClientAbstract {
|
|
|
845
848
|
}
|
|
846
849
|
}
|
|
847
850
|
async recoverChannelUpdateGap(channelId, source) {
|
|
848
|
-
|
|
851
|
+
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
849
852
|
const release = await this.updateGapRecoveryMutex.acquire();
|
|
850
853
|
try {
|
|
851
854
|
const pts_ = await this.storage.getChannelPts(channelId);
|
|
@@ -868,12 +871,12 @@ export class Client extends ClientAbstract {
|
|
|
868
871
|
await this.applyUpdateNoGap(update, false);
|
|
869
872
|
}
|
|
870
873
|
await this.storage.setChannelPts(channelId, difference.pts);
|
|
871
|
-
|
|
874
|
+
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
872
875
|
break;
|
|
873
876
|
}
|
|
874
877
|
else if (difference instanceof types.UpdatesChannelDifferenceTooLong) {
|
|
875
878
|
// invalidate messages
|
|
876
|
-
|
|
879
|
+
dGapC("received channelDifferenceTooLong");
|
|
877
880
|
await this.processChats(difference.chats);
|
|
878
881
|
await this.processUsers(difference.users);
|
|
879
882
|
for (const message of difference.messages) {
|
|
@@ -886,10 +889,10 @@ export class Client extends ClientAbstract {
|
|
|
886
889
|
else {
|
|
887
890
|
UNREACHABLE();
|
|
888
891
|
}
|
|
889
|
-
|
|
892
|
+
dGapC("processed channelDifferenceTooLong");
|
|
890
893
|
}
|
|
891
894
|
else if (difference instanceof types.UpdatesChannelDifferenceEmpty) {
|
|
892
|
-
|
|
895
|
+
dGapC("there was no update gap");
|
|
893
896
|
break;
|
|
894
897
|
}
|
|
895
898
|
}
|
|
@@ -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>;
|
|
@@ -2,6 +2,9 @@ import { initTgCrypto } from "../deps.js";
|
|
|
2
2
|
import { DEFAULT_INITIAL_DC } from "../constants.js";
|
|
3
3
|
import { defaultTransportProvider } from "../transport/transport_provider.js";
|
|
4
4
|
export class ClientAbstract {
|
|
5
|
+
get initialDc() {
|
|
6
|
+
return this._initialDc;
|
|
7
|
+
}
|
|
5
8
|
constructor(transportProvider = defaultTransportProvider({ initialDc: DEFAULT_INITIAL_DC })) {
|
|
6
9
|
Object.defineProperty(this, "transportProvider", {
|
|
7
10
|
enumerable: true,
|
|
@@ -27,7 +30,15 @@ export class ClientAbstract {
|
|
|
27
30
|
writable: true,
|
|
28
31
|
value: void 0
|
|
29
32
|
});
|
|
30
|
-
|
|
33
|
+
Object.defineProperty(this, "_initialDc", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
const { initialDc, createTransport } = transportProvider;
|
|
40
|
+
this._initialDc = initialDc;
|
|
41
|
+
const { connection, transport, dcId } = createTransport({ cdn: false });
|
|
31
42
|
this.connection = connection;
|
|
32
43
|
this.transport = transport;
|
|
33
44
|
this._dcId = dcId;
|
|
@@ -37,7 +48,7 @@ export class ClientAbstract {
|
|
|
37
48
|
}
|
|
38
49
|
// MaybePromise since `Client` has to deal with `Storage.set()`
|
|
39
50
|
setDc(dc) {
|
|
40
|
-
const { connection, transport, dcId } = this.transportProvider({ dc, cdn: false });
|
|
51
|
+
const { connection, transport, dcId } = this.transportProvider.createTransport({ dc, cdn: false });
|
|
41
52
|
this.connection = connection;
|
|
42
53
|
this.transport = transport;
|
|
43
54
|
this._dcId = dcId;
|
|
@@ -53,7 +64,7 @@ export class ClientAbstract {
|
|
|
53
64
|
async reconnect(dc) {
|
|
54
65
|
await this.disconnect();
|
|
55
66
|
if (dc) {
|
|
56
|
-
this.setDc(dc);
|
|
67
|
+
await this.setDc(dc);
|
|
57
68
|
}
|
|
58
69
|
await this.connect();
|
|
59
70
|
}
|
|
@@ -2,15 +2,16 @@ import { assertEquals, assertInstanceOf, debug, factorize, ige256Decrypt, ige256
|
|
|
2
2
|
import { publicKeys } from "../constants.js";
|
|
3
3
|
import { bigIntFromBuffer, getRandomBigInt, modExp } from "../utilities/0_bigint.js";
|
|
4
4
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
5
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
5
6
|
import { sha1 } from "../utilities/0_hash.js";
|
|
6
7
|
import { rsaPad } from "../utilities/1_auth.js";
|
|
7
8
|
import { serialize } from "../tl/1_tl_object.js";
|
|
8
|
-
import { packUnencryptedMessage, unpackUnencryptedMessage } from "../utilities/1_message.js";
|
|
9
9
|
import { ClientDHInnerData, DHGenOK, PQInnerDataDC, ResPQ, ServerDHInnerData, ServerDHParamsOK } from "../tl/2_types.js";
|
|
10
10
|
import { ReqDHParams, ReqPQMulti, SetClientDHParams } from "../tl/3_functions.js";
|
|
11
11
|
import { TLReader } from "../tl/3_tl_reader.js";
|
|
12
12
|
import { ClientAbstract } from "./client_abstract.js";
|
|
13
|
-
|
|
13
|
+
import { packUnencryptedMessage, unpackUnencryptedMessage } from "./utilities/0_message.js";
|
|
14
|
+
const d = debug("ClientPlain/createAuthKey");
|
|
14
15
|
export class ClientPlain extends ClientAbstract {
|
|
15
16
|
async invoke(function_) {
|
|
16
17
|
await this.transport.send(packUnencryptedMessage(function_[serialize]()));
|
|
@@ -28,10 +29,23 @@ export class ClientPlain extends ClientAbstract {
|
|
|
28
29
|
async createAuthKey() {
|
|
29
30
|
const nonce = getRandomBigInt(16, false, true);
|
|
30
31
|
d("auth key creation started");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
let resPq = null;
|
|
33
|
+
for (let i = 0; i < 10; i++) {
|
|
34
|
+
try {
|
|
35
|
+
d("req_pq_multi [%d]", i + 1);
|
|
36
|
+
resPq = await this.invoke(new ReqPQMulti({ nonce }));
|
|
37
|
+
assertInstanceOf(resPq, ResPQ);
|
|
38
|
+
assertEquals(resPq.nonce, nonce);
|
|
39
|
+
d("got res_pq");
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
d("req_pq_multi error: %o", err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!resPq) {
|
|
47
|
+
UNREACHABLE();
|
|
48
|
+
}
|
|
35
49
|
const pq_ = bigIntFromBuffer(resPq.pq, false, false);
|
|
36
50
|
const [p_, q_] = factorize(pq_);
|
|
37
51
|
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,13 +1,13 @@
|
|
|
1
|
-
import { assertEquals, ige256Decrypt, ige256Encrypt } from "
|
|
2
|
-
import { TLRawReader } from "
|
|
3
|
-
import { TLRawWriter } from "
|
|
4
|
-
import { id, serialize } from "
|
|
5
|
-
import { TLReader } from "
|
|
6
|
-
import { RPCResult } from "
|
|
7
|
-
import { Message } from "
|
|
8
|
-
import { MessageContainer } from "
|
|
9
|
-
import { bufferFromBigInt, concat } from "
|
|
10
|
-
import { sha256 } from "
|
|
1
|
+
import { assertEquals, ige256Decrypt, ige256Encrypt } from "../../deps.js";
|
|
2
|
+
import { TLRawReader } from "../../tl/0_tl_raw_reader.js";
|
|
3
|
+
import { TLRawWriter } from "../../tl/0_tl_raw_writer.js";
|
|
4
|
+
import { id, serialize } from "../../tl/1_tl_object.js";
|
|
5
|
+
import { TLReader } from "../../tl/3_tl_reader.js";
|
|
6
|
+
import { RPCResult } from "../../tl/5_rpc_result.js";
|
|
7
|
+
import { Message } from "../../tl/6_message.js";
|
|
8
|
+
import { MessageContainer } from "../../tl/7_message_container.js";
|
|
9
|
+
import { bufferFromBigInt, concat } from "../../utilities/0_buffer.js";
|
|
10
|
+
import { sha256 } from "../../utilities/0_hash.js";
|
|
11
11
|
let lastMsgId = 0n;
|
|
12
12
|
export function getMessageId() {
|
|
13
13
|
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>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as dntShim from "
|
|
2
|
-
import * as types from "
|
|
3
|
-
import { bufferFromBigInt, concat } from "
|
|
4
|
-
import { sha256 } from "
|
|
5
|
-
import { bigIntFromBuffer, getRandomBigInt, mod, modExp } from "
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import * as types from "../../tl/2_types.js";
|
|
3
|
+
import { bufferFromBigInt, concat } from "../../utilities/0_buffer.js";
|
|
4
|
+
import { sha256 } from "../../utilities/0_hash.js";
|
|
5
|
+
import { bigIntFromBuffer, getRandomBigInt, mod, modExp } from "../../utilities/0_bigint.js";
|
|
6
6
|
export function isSafePrime(primeBytes, g) {
|
|
7
7
|
// deno-fmt-ignore
|
|
8
8
|
const goodPrime = new Uint8Array([
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
-
import { Mutex } from "../deps.js";
|
|
2
|
+
import { debug, Mutex } from "../deps.js";
|
|
3
|
+
const d = debug("ConnectionWebSocket");
|
|
3
4
|
export class ConnectionWebSocket {
|
|
4
5
|
constructor(url) {
|
|
5
6
|
Object.defineProperty(this, "webSocket", {
|
|
@@ -44,7 +45,9 @@ export class ConnectionWebSocket {
|
|
|
44
45
|
this.nextResolve = null;
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
this.webSocket.onerror =
|
|
48
|
+
this.webSocket.onerror = (err) => {
|
|
49
|
+
d("WebSocket error: %O", err);
|
|
50
|
+
};
|
|
48
51
|
}
|
|
49
52
|
get connected() {
|
|
50
53
|
return this.webSocket.readyState == dntShim.WebSocket.OPEN;
|
package/esm/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/esm/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as dntShim from "./_dnt.shims.js";
|
|
1
2
|
export const ackThreshold = 10;
|
|
2
3
|
export const publicKeys = new Map([
|
|
3
4
|
[
|
|
@@ -61,13 +62,14 @@ export const publicKeys = new Map([
|
|
|
61
62
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
62
63
|
export const DEFAULT_INITIAL_DC = "2-test";
|
|
63
64
|
export const LAYER = 158;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export const DEFAULT_DEVICE_MODEL = "
|
|
67
|
-
export const DEFAULT_LANG_CODE = "en";
|
|
65
|
+
export const DEFAULT_APP_VERSION = "MTKruto 0.0.902";
|
|
66
|
+
// @ts-ignore: lib
|
|
67
|
+
export const 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;
|
|
68
|
+
export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
68
69
|
export const DEFAULT_LANG_PACK = "";
|
|
69
|
-
export const DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
70
|
-
|
|
70
|
+
export const DEFAULT_SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
71
|
+
// @ts-ignore: lib
|
|
72
|
+
export const DEFAULT_SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
|
|
71
73
|
export const USERNAME_TTL = 86400;
|
|
72
74
|
export const MAX_CHAT_ID = 999999999999;
|
|
73
75
|
export const MAX_CHANNEL_ID = 997852516352;
|
package/esm/deps.js
CHANGED
|
@@ -4,6 +4,6 @@ export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/
|
|
|
4
4
|
export { Mutex } from "async-mutex";
|
|
5
5
|
export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
|
|
6
6
|
import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
|
|
7
|
-
export const debug = (v) => debug_(`
|
|
7
|
+
export const debug = (v) => debug_(`mtkruto/${v}`);
|
|
8
8
|
export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
|
|
9
9
|
export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
|
package/esm/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/esm/mod.js
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 const utils = { checkPassword, getRandomId };
|
|
4
4
|
export { as } from "./tl/1_tl_object.js";
|
|
5
5
|
export * as types from "./tl/2_types.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
2
|
-
import { getObfuscationParameters } from "
|
|
2
|
+
import { getObfuscationParameters } from "./utilities/0_obfuscation.js";
|
|
3
3
|
import { Transport } from "./transport.js";
|
|
4
4
|
export class TransportAbridged extends Transport {
|
|
5
5
|
constructor(connection, obfuscated = false) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
2
|
-
import { getObfuscationParameters } from "
|
|
2
|
+
import { getObfuscationParameters } from "./utilities/0_obfuscation.js";
|
|
3
3
|
import { Transport } from "./transport.js";
|
|
4
4
|
export class TransportIntermediate extends Transport {
|
|
5
5
|
constructor(connection, obfuscated = false) {
|
|
@@ -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;
|
|
@@ -11,13 +11,16 @@ const dcToNameMap = {
|
|
|
11
11
|
"5": "flora",
|
|
12
12
|
};
|
|
13
13
|
export const defaultTransportProvider = ({ initialDc, wss }) => {
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
return {
|
|
15
|
+
initialDc,
|
|
16
|
+
createTransport: ({ dc, cdn }) => {
|
|
17
|
+
dc ??= initialDc;
|
|
18
|
+
wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
|
|
19
|
+
const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
20
|
+
const connection = new ConnectionWebSocket(url);
|
|
21
|
+
const transport = new TransportIntermediate(connection, true);
|
|
22
|
+
const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
|
|
23
|
+
return { connection, transport, dcId };
|
|
24
|
+
},
|
|
22
25
|
};
|
|
23
26
|
};
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as dntShim from "
|
|
2
|
-
import { bufferFromBigInt, concat } from "
|
|
3
|
-
import { CTR } from "
|
|
1
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
2
|
+
import { bufferFromBigInt, concat } from "../../utilities/0_buffer.js";
|
|
3
|
+
import { CTR } from "../../utilities/0_crypto.js";
|
|
4
4
|
export async function getObfuscationParameters(protocol, connection) {
|
|
5
5
|
const dc = 0xFCFF;
|
|
6
6
|
let init;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MessageEntity } from "../
|
|
1
|
+
import { MessageEntity } from "../0_message_entity.js";
|
|
2
2
|
export declare function parseHtml(html: string): readonly [string, MessageEntity[]];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Parser } from "
|
|
2
|
-
import { MessageEntityType } from "../
|
|
1
|
+
import { Parser } from "../../deps.js";
|
|
2
|
+
import { MessageEntityType } from "../0_message_entity.js";
|
|
3
3
|
export function parseHtml(html) {
|
|
4
4
|
let text = "";
|
|
5
5
|
const entities = new Array();
|
package/package.json
CHANGED