@mtkruto/node 0.0.967 → 0.0.969
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/1_client_abstract.js +3 -3
- package/esm/client/2_client_plain.d.ts +3 -0
- package/esm/client/2_client_plain.js +11 -5
- package/esm/client/3_client.d.ts +6 -3
- package/esm/client/3_client.js +19 -15
- package/esm/connection/0_connection.d.ts +11 -2
- package/esm/connection/0_connection.js +23 -1
- package/esm/connection/1_connection_http.d.ts +16 -0
- package/esm/connection/1_connection_http.js +91 -0
- package/esm/connection/1_connection_web_socket.d.ts +2 -2
- package/esm/connection/1_connection_web_socket.js +3 -2
- package/esm/constants.d.ts +11 -10
- package/esm/constants.js +10 -18
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/tl/2_types.d.ts +437 -40
- package/esm/tl/2_types.js +1470 -130
- package/esm/tl/3_functions.d.ts +274 -36
- package/esm/tl/3_functions.js +871 -116
- package/esm/transport/1_transport_piped.d.ts +10 -0
- package/esm/transport/1_transport_piped.js +23 -0
- package/esm/transport/2_transport_provider.d.ts +8 -2
- package/esm/transport/2_transport_provider.js +40 -2
- package/package.json +1 -1
- package/script/client/1_client_abstract.js +1 -1
- package/script/client/2_client_plain.d.ts +3 -0
- package/script/client/2_client_plain.js +10 -4
- package/script/client/3_client.d.ts +6 -3
- package/script/client/3_client.js +18 -14
- package/script/connection/0_connection.d.ts +11 -2
- package/script/connection/0_connection.js +26 -3
- package/script/connection/1_connection_http.d.ts +16 -0
- package/script/connection/1_connection_http.js +95 -0
- package/script/connection/1_connection_web_socket.d.ts +2 -2
- package/script/connection/1_connection_web_socket.js +3 -2
- package/script/constants.d.ts +11 -10
- package/script/constants.js +11 -19
- package/script/mod.d.ts +1 -1
- package/script/mod.js +8 -8
- package/script/tl/2_types.d.ts +437 -40
- package/script/tl/2_types.js +1540 -160
- package/script/tl/3_functions.d.ts +274 -36
- package/script/tl/3_functions.js +901 -125
- package/script/transport/1_transport_piped.d.ts +10 -0
- package/script/transport/1_transport_piped.js +27 -0
- package/script/transport/2_transport_provider.d.ts +8 -2
- package/script/transport/2_transport_provider.js +43 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConnectionFramed } from "../connection/0_connection.js";
|
|
2
|
+
import { Transport } from "./0_transport.js";
|
|
3
|
+
export declare class TransportPiped extends Transport implements Transport {
|
|
4
|
+
private readonly connection;
|
|
5
|
+
constructor(connection: ConnectionFramed);
|
|
6
|
+
initialize(): Promise<void>;
|
|
7
|
+
receive(): import("../utilities/0_types.js").MaybePromise<Uint8Array>;
|
|
8
|
+
send(buffer: Uint8Array): import("../utilities/0_types.js").MaybePromise<void>;
|
|
9
|
+
deinitialize(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Transport } from "./0_transport.js";
|
|
2
|
+
export class TransportPiped extends Transport {
|
|
3
|
+
constructor(connection) {
|
|
4
|
+
super();
|
|
5
|
+
Object.defineProperty(this, "connection", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: connection
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async initialize() {
|
|
13
|
+
}
|
|
14
|
+
receive() {
|
|
15
|
+
return this.connection.read();
|
|
16
|
+
}
|
|
17
|
+
send(buffer) {
|
|
18
|
+
return this.connection.write(buffer);
|
|
19
|
+
}
|
|
20
|
+
deinitialize() {
|
|
21
|
+
this.initialized = false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -16,5 +16,11 @@ export type TransportProvider = {
|
|
|
16
16
|
export interface TransportProviderCreatorParams {
|
|
17
17
|
initialDc: DC;
|
|
18
18
|
}
|
|
19
|
-
export type TransportProviderCreator = (params: TransportProviderCreatorParams) => TransportProvider;
|
|
20
|
-
export declare const
|
|
19
|
+
export type TransportProviderCreator<E = Record<never, never>> = (params: TransportProviderCreatorParams & E) => TransportProvider;
|
|
20
|
+
export declare const webSocketTransportProvider: TransportProviderCreator<{
|
|
21
|
+
wss?: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const httpTransportProvider: TransportProviderCreator<{
|
|
24
|
+
secure?: boolean;
|
|
25
|
+
v6?: boolean;
|
|
26
|
+
}>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ConnectionHTTP } from "../connection/1_connection_http.js";
|
|
1
2
|
import { ConnectionWebSocket } from "../connection/1_connection_web_socket.js";
|
|
3
|
+
import { TransportPiped } from "./1_transport_piped.js";
|
|
2
4
|
import { TransportIntermediate } from "./1_transport_intermediate.js";
|
|
3
5
|
const dcToNameMap = {
|
|
4
6
|
"1": "pluto",
|
|
@@ -10,7 +12,10 @@ const dcToNameMap = {
|
|
|
10
12
|
"4": "vesta",
|
|
11
13
|
"5": "flora",
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
function getDcId(dc, cdn) {
|
|
16
|
+
return Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
|
|
17
|
+
}
|
|
18
|
+
export const webSocketTransportProvider = ({ initialDc, wss }) => {
|
|
14
19
|
return {
|
|
15
20
|
initialDc,
|
|
16
21
|
createTransport: ({ dc, cdn }) => {
|
|
@@ -19,7 +24,40 @@ export const defaultTransportProvider = ({ initialDc, wss }) => {
|
|
|
19
24
|
const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
20
25
|
const connection = new ConnectionWebSocket(url);
|
|
21
26
|
const transport = new TransportIntermediate(connection, true);
|
|
22
|
-
const dcId =
|
|
27
|
+
const dcId = getDcId(dc, cdn);
|
|
28
|
+
return { connection, transport, dcId };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const dcToIPv4Map = {
|
|
33
|
+
"1": "149.154.175.50",
|
|
34
|
+
"1-test": "149.154.175.10",
|
|
35
|
+
"2": "149.154.167.51",
|
|
36
|
+
"2-test": "149.154.167.40",
|
|
37
|
+
"3": "149.154.175.100",
|
|
38
|
+
"3-test": "149.154.175.117",
|
|
39
|
+
"4": "149.154.167.91",
|
|
40
|
+
"5": "149.154.171.5",
|
|
41
|
+
};
|
|
42
|
+
const dcToIPv6Map = {
|
|
43
|
+
"1": "[2001:b28:f23d:f001::a]",
|
|
44
|
+
"1-test": "[2001:b28:f23d:f001::e]",
|
|
45
|
+
"2": "[2001:67c:4e8:f002::a]",
|
|
46
|
+
"2-test": "[2001:67c:4e8:f002::e]",
|
|
47
|
+
"3": "[2001:b28:f23d:f003::a]",
|
|
48
|
+
"3-test": "[2001:b28:f23d:f003::e]",
|
|
49
|
+
"4": "[2001:67c:4e8:f004::a]",
|
|
50
|
+
"5": "[2001:b28:f23f:f005::a]",
|
|
51
|
+
};
|
|
52
|
+
export const httpTransportProvider = ({ initialDc, secure, v6 }) => {
|
|
53
|
+
return {
|
|
54
|
+
initialDc,
|
|
55
|
+
createTransport({ dc, cdn }) {
|
|
56
|
+
dc ??= initialDc;
|
|
57
|
+
const url = secure ? `https://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiw1_test" : "apiw1"}` : `http://${(v6 ? dcToIPv6Map : dcToIPv4Map)[dc]}/${dc.endsWith("-test") ? "api_test" : "api"}`;
|
|
58
|
+
const connection = new ConnectionHTTP(url);
|
|
59
|
+
const transport = new TransportPiped(connection);
|
|
60
|
+
const dcId = getDcId(dc, cdn);
|
|
23
61
|
return { connection, transport, dcId };
|
|
24
62
|
},
|
|
25
63
|
};
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ class ClientAbstract {
|
|
|
8
8
|
get initialDc() {
|
|
9
9
|
return this._initialDc;
|
|
10
10
|
}
|
|
11
|
-
constructor(transportProvider = (0, _2_transport_provider_js_1.
|
|
11
|
+
constructor(transportProvider = (0, _2_transport_provider_js_1.webSocketTransportProvider)({ initialDc: constants_js_1.INITIAL_DC }), cdn = false) {
|
|
12
12
|
Object.defineProperty(this, "transportProvider", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
configurable: true,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Function } from "../tl/3_functions.js";
|
|
2
|
+
import { TransportProvider } from "../transport/2_transport_provider.js";
|
|
2
3
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
3
4
|
export declare class ClientPlain extends ClientAbstract {
|
|
5
|
+
private readonly publicKeys;
|
|
4
6
|
private lastMsgId;
|
|
7
|
+
constructor(transportProvider: TransportProvider, publicKeys?: import("../constants.js").PublicKeys);
|
|
5
8
|
invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
|
|
6
9
|
createAuthKey(): Promise<{
|
|
7
10
|
authKey: Uint8Array;
|
|
@@ -16,8 +16,14 @@ const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
|
16
16
|
const _0_message_js_1 = require("./0_message.js");
|
|
17
17
|
const d = (0, deps_js_1.debug)("ClientPlain/createAuthKey");
|
|
18
18
|
class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
|
|
19
|
-
constructor() {
|
|
20
|
-
super(
|
|
19
|
+
constructor(transportProvider, publicKeys = constants_js_1.PUBLIC_KEYS) {
|
|
20
|
+
super(transportProvider);
|
|
21
|
+
Object.defineProperty(this, "publicKeys", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: publicKeys
|
|
26
|
+
});
|
|
21
27
|
Object.defineProperty(this, "lastMsgId", {
|
|
22
28
|
enumerable: true,
|
|
23
29
|
configurable: true,
|
|
@@ -67,10 +73,10 @@ class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
67
73
|
let publicKeyFingerprint;
|
|
68
74
|
let publicKey;
|
|
69
75
|
for (const fingerprint of resPq.serverPublicKeyFingerprints) {
|
|
70
|
-
const maybePublicKey =
|
|
76
|
+
const maybePublicKey = this.publicKeys.find(([k]) => (k == fingerprint));
|
|
71
77
|
if (maybePublicKey) {
|
|
72
78
|
publicKeyFingerprint = fingerprint;
|
|
73
|
-
publicKey = maybePublicKey;
|
|
79
|
+
publicKey = maybePublicKey[1];
|
|
74
80
|
break;
|
|
75
81
|
}
|
|
76
82
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PublicKeys } from "../constants.js";
|
|
1
2
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
3
|
import * as types from "../tl/2_types.js";
|
|
3
4
|
import * as functions from "../tl/3_functions.js";
|
|
@@ -58,6 +59,7 @@ export interface ClientParams {
|
|
|
58
59
|
* The system_version parameter to be passed to initConnection when calling `authorize`.
|
|
59
60
|
*/
|
|
60
61
|
systemVersion?: string;
|
|
62
|
+
publicKeys?: PublicKeys;
|
|
61
63
|
}
|
|
62
64
|
export interface ForwardMessagesParams {
|
|
63
65
|
messageThreadId?: number;
|
|
@@ -69,8 +71,8 @@ export interface ForwardMessagesParams {
|
|
|
69
71
|
}
|
|
70
72
|
export declare class Client extends ClientAbstract {
|
|
71
73
|
readonly storage: Storage;
|
|
72
|
-
readonly apiId: number;
|
|
73
|
-
readonly apiHash: string;
|
|
74
|
+
readonly apiId: number | null;
|
|
75
|
+
readonly apiHash: string | null;
|
|
74
76
|
private auth;
|
|
75
77
|
private sessionId;
|
|
76
78
|
private state;
|
|
@@ -85,6 +87,7 @@ export declare class Client extends ClientAbstract {
|
|
|
85
87
|
readonly langPack: string;
|
|
86
88
|
readonly systemLangCode: string;
|
|
87
89
|
readonly systemVersion: string;
|
|
90
|
+
private readonly publicKeys?;
|
|
88
91
|
/**
|
|
89
92
|
* Constructs the client.
|
|
90
93
|
*
|
|
@@ -93,7 +96,7 @@ export declare class Client extends ClientAbstract {
|
|
|
93
96
|
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
|
|
94
97
|
* @param params Other parameters.
|
|
95
98
|
*/
|
|
96
|
-
constructor(storage?: Storage, apiId?: number, apiHash?: string, params?: ClientParams, cdn?: boolean);
|
|
99
|
+
constructor(storage?: Storage, apiId?: number | null, apiHash?: string | null, params?: ClientParams, cdn?: boolean);
|
|
97
100
|
private storageInited;
|
|
98
101
|
/**
|
|
99
102
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -179,6 +179,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
179
179
|
writable: true,
|
|
180
180
|
value: void 0
|
|
181
181
|
});
|
|
182
|
+
Object.defineProperty(this, "publicKeys", {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
configurable: true,
|
|
185
|
+
writable: true,
|
|
186
|
+
value: void 0
|
|
187
|
+
});
|
|
182
188
|
Object.defineProperty(this, "storageInited", {
|
|
183
189
|
enumerable: true,
|
|
184
190
|
configurable: true,
|
|
@@ -210,12 +216,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
210
216
|
value: new deps_js_1.Mutex()
|
|
211
217
|
});
|
|
212
218
|
this.parseMode = params?.parseMode ?? ParseMode.None;
|
|
213
|
-
this.appVersion = params?.appVersion ?? constants_js_1.
|
|
214
|
-
this.deviceModel = params?.deviceModel ?? constants_js_1.
|
|
215
|
-
this.langCode = params?.langCode ?? constants_js_1.
|
|
216
|
-
this.langPack = params?.langPack ?? constants_js_1.
|
|
217
|
-
this.systemLangCode = params?.systemLangCode ?? constants_js_1.
|
|
218
|
-
this.systemVersion = params?.systemVersion ?? constants_js_1.
|
|
219
|
+
this.appVersion = params?.appVersion ?? constants_js_1.APP_VERSION;
|
|
220
|
+
this.deviceModel = params?.deviceModel ?? constants_js_1.DEVICE_MODEL;
|
|
221
|
+
this.langCode = params?.langCode ?? constants_js_1.LANG_CODE;
|
|
222
|
+
this.langPack = params?.langPack ?? constants_js_1.LANG_PACK;
|
|
223
|
+
this.systemLangCode = params?.systemLangCode ?? constants_js_1.SYSTEM_LANG_CODE;
|
|
224
|
+
this.systemVersion = params?.systemVersion ?? constants_js_1.SYSTEM_VERSION;
|
|
225
|
+
this.publicKeys = params?.publicKeys;
|
|
219
226
|
}
|
|
220
227
|
/**
|
|
221
228
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -252,7 +259,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
252
259
|
}
|
|
253
260
|
const authKey = await this.storage.getAuthKey();
|
|
254
261
|
if (authKey == null) {
|
|
255
|
-
const plain = new _2_client_plain_js_1.ClientPlain(this.transportProvider);
|
|
262
|
+
const plain = new _2_client_plain_js_1.ClientPlain(this.transportProvider, this.publicKeys);
|
|
256
263
|
const dc = await this.storage.getDc();
|
|
257
264
|
if (dc != null) {
|
|
258
265
|
plain.setDc(dc);
|
|
@@ -398,7 +405,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
398
405
|
apiId: this.apiId,
|
|
399
406
|
apiHash: this.apiHash,
|
|
400
407
|
phoneNumber,
|
|
401
|
-
settings: new types.CodeSettings(),
|
|
408
|
+
settings: new types.CodeSettings({}),
|
|
402
409
|
}));
|
|
403
410
|
dAuth("verification code sent");
|
|
404
411
|
if (sentCode instanceof types.AuthSentCode) {
|
|
@@ -484,7 +491,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
484
491
|
}
|
|
485
492
|
while (this.connected) {
|
|
486
493
|
try {
|
|
487
|
-
if (this.toAcknowledge.size >= constants_js_1.
|
|
494
|
+
if (this.toAcknowledge.size >= constants_js_1.ACK_THRESHOLD) {
|
|
488
495
|
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
489
496
|
this.toAcknowledge.clear();
|
|
490
497
|
}
|
|
@@ -593,9 +600,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
593
600
|
const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
|
|
594
601
|
const message = new _6_message_js_1.Message(messageId, seqNo, function_);
|
|
595
602
|
await this.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
596
|
-
|
|
603
|
+
d("invoked %s", function_.constructor.name);
|
|
597
604
|
if (noWait) {
|
|
598
|
-
d_();
|
|
599
605
|
return;
|
|
600
606
|
}
|
|
601
607
|
const result = await new Promise((resolve, reject) => {
|
|
@@ -605,7 +611,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
605
611
|
return await this.invoke(function_);
|
|
606
612
|
}
|
|
607
613
|
else {
|
|
608
|
-
d_();
|
|
609
614
|
return result;
|
|
610
615
|
}
|
|
611
616
|
}
|
|
@@ -1173,8 +1178,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1173
1178
|
noWebpage,
|
|
1174
1179
|
silent,
|
|
1175
1180
|
noforwards,
|
|
1176
|
-
replyToMsgId,
|
|
1177
|
-
topMsgId,
|
|
1181
|
+
replyTo: replyToMsgId !== undefined ? new types.InputReplyToMessage({ replyToMsgId, topMsgId }) : undefined,
|
|
1178
1182
|
sendAs,
|
|
1179
1183
|
entities,
|
|
1180
1184
|
replyMarkup,
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
-
|
|
2
|
+
declare abstract class Foundation {
|
|
3
3
|
abstract get connected(): boolean;
|
|
4
4
|
abstract open(): MaybePromise<void>;
|
|
5
|
-
abstract read(p: Uint8Array): MaybePromise<void>;
|
|
6
5
|
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
7
6
|
abstract close(): MaybePromise<void>;
|
|
8
7
|
}
|
|
8
|
+
export declare abstract class ConnectionUnframed extends Foundation {
|
|
9
|
+
readonly type: "framed";
|
|
10
|
+
abstract read(p: Uint8Array): MaybePromise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class ConnectionFramed extends Foundation {
|
|
13
|
+
readonly type: "framed";
|
|
14
|
+
abstract read(): MaybePromise<Uint8Array>;
|
|
15
|
+
}
|
|
16
|
+
export type Connection = ConnectionUnframed | ConnectionFramed;
|
|
17
|
+
export {};
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.ConnectionFramed = exports.ConnectionUnframed = void 0;
|
|
4
|
+
class Foundation {
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
class ConnectionUnframed extends Foundation {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
Object.defineProperty(this, "type", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: "framed"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ConnectionUnframed = ConnectionUnframed;
|
|
18
|
+
class ConnectionFramed extends Foundation {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
Object.defineProperty(this, "type", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: "framed"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ConnectionFramed = ConnectionFramed;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConnectionFramed } from "./0_connection.js";
|
|
2
|
+
export declare class ConnectionHTTP extends ConnectionFramed implements ConnectionFramed {
|
|
3
|
+
private readonly url;
|
|
4
|
+
private rMutex;
|
|
5
|
+
private wMutex;
|
|
6
|
+
private resolveCanRead;
|
|
7
|
+
private canRead;
|
|
8
|
+
private buffers;
|
|
9
|
+
constructor(url: string | URL);
|
|
10
|
+
private resetCanRead;
|
|
11
|
+
get connected(): boolean;
|
|
12
|
+
open(): Promise<void>;
|
|
13
|
+
read(): Promise<Uint8Array>;
|
|
14
|
+
write(buffer: Uint8Array): Promise<void>;
|
|
15
|
+
close(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionHTTP = void 0;
|
|
4
|
+
const deps_js_1 = require("../deps.js");
|
|
5
|
+
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
6
|
+
const _0_connection_js_1 = require("./0_connection.js");
|
|
7
|
+
class ConnectionHTTP extends _0_connection_js_1.ConnectionFramed {
|
|
8
|
+
constructor(url) {
|
|
9
|
+
super();
|
|
10
|
+
Object.defineProperty(this, "url", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: url
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "rMutex", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: new deps_js_1.Mutex()
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "wMutex", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: new deps_js_1.Mutex()
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "resolveCanRead", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: () => { }
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "canRead", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: Promise.resolve()
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "buffers", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: new Array()
|
|
45
|
+
});
|
|
46
|
+
this.resetCanRead();
|
|
47
|
+
}
|
|
48
|
+
resetCanRead() {
|
|
49
|
+
this.canRead = new Promise((r) => this.resolveCanRead = r);
|
|
50
|
+
}
|
|
51
|
+
get connected() {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
async open() {
|
|
55
|
+
}
|
|
56
|
+
async read() {
|
|
57
|
+
await this.canRead;
|
|
58
|
+
const release = await this.rMutex.acquire();
|
|
59
|
+
try {
|
|
60
|
+
const buffer = this.buffers.pop();
|
|
61
|
+
if (buffer === undefined) {
|
|
62
|
+
throw (0, _0_control_js_1.UNREACHABLE)();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return buffer;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
if (this.buffers.length == 0) {
|
|
70
|
+
this.resetCanRead();
|
|
71
|
+
}
|
|
72
|
+
release();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async write(buffer) {
|
|
76
|
+
const release = await this.wMutex.acquire();
|
|
77
|
+
try {
|
|
78
|
+
const res = await fetch(this.url, {
|
|
79
|
+
mode: "cors",
|
|
80
|
+
method: "POST",
|
|
81
|
+
body: buffer,
|
|
82
|
+
});
|
|
83
|
+
this.buffers.push(new Uint8Array(await res.arrayBuffer()));
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
if (this.buffers.length == 1) {
|
|
87
|
+
this.resolveCanRead();
|
|
88
|
+
}
|
|
89
|
+
release();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
close() {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.ConnectionHTTP = ConnectionHTTP;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class ConnectionWebSocket implements
|
|
1
|
+
import { ConnectionUnframed } from "./0_connection.js";
|
|
2
|
+
export declare class ConnectionWebSocket extends ConnectionUnframed implements ConnectionUnframed {
|
|
3
3
|
private webSocket;
|
|
4
4
|
private rMutex;
|
|
5
5
|
private wMutex;
|
|
@@ -26,9 +26,11 @@ 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 _0_connection_js_1 = require("./0_connection.js");
|
|
29
30
|
const d = (0, deps_js_1.debug)("ConnectionWebSocket");
|
|
30
|
-
class ConnectionWebSocket {
|
|
31
|
+
class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
31
32
|
constructor(url) {
|
|
33
|
+
super();
|
|
32
34
|
Object.defineProperty(this, "webSocket", {
|
|
33
35
|
enumerable: true,
|
|
34
36
|
configurable: true,
|
|
@@ -72,7 +74,6 @@ class ConnectionWebSocket {
|
|
|
72
74
|
value: null
|
|
73
75
|
});
|
|
74
76
|
this.webSocket = this.reinitWs(url);
|
|
75
|
-
// TODO
|
|
76
77
|
this.webSocket.addEventListener("close", (e) => {
|
|
77
78
|
if (e.code != 1000 && e.reason != "method") {
|
|
78
79
|
this.webSocket = this.reinitWs(url);
|
package/script/constants.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { DC } from "./transport/2_transport_provider.js";
|
|
2
|
-
export declare const
|
|
3
|
-
export
|
|
2
|
+
export declare const ACK_THRESHOLD = 10;
|
|
3
|
+
export type PublicKeys = readonly [bigint, [bigint, bigint]][];
|
|
4
|
+
export declare const PUBLIC_KEYS: PublicKeys;
|
|
4
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const LAYER =
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
6
|
+
export declare const INITIAL_DC: DC;
|
|
7
|
+
export declare const LAYER = 160;
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.969";
|
|
9
|
+
export declare const DEVICE_MODEL: string;
|
|
10
|
+
export declare const LANG_CODE: string;
|
|
11
|
+
export declare const LANG_PACK = "";
|
|
12
|
+
export declare const SYSTEM_LANG_CODE: string;
|
|
13
|
+
export declare const SYSTEM_VERSION: string;
|
|
13
14
|
export declare const USERNAME_TTL = 86400;
|
|
14
15
|
export declare const STICKER_SET_NAME_TTL = 172800;
|
|
15
16
|
export declare const MAX_CHAT_ID = 999999999999;
|
package/script/constants.js
CHANGED
|
@@ -23,10 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.CHANNEL_DIFFERENCE_LIMIT_BOT = exports.CHANNEL_DIFFERENCE_LIMIT_USER = exports.ZERO_CHANNEL_ID = exports.MAX_CHANNEL_ID = exports.MAX_CHAT_ID = exports.STICKER_SET_NAME_TTL = exports.USERNAME_TTL = exports.
|
|
26
|
+
exports.CHANNEL_DIFFERENCE_LIMIT_BOT = exports.CHANNEL_DIFFERENCE_LIMIT_USER = exports.ZERO_CHANNEL_ID = exports.MAX_CHANNEL_ID = exports.MAX_CHAT_ID = exports.STICKER_SET_NAME_TTL = exports.USERNAME_TTL = exports.SYSTEM_VERSION = exports.SYSTEM_LANG_CODE = exports.LANG_PACK = exports.LANG_CODE = exports.DEVICE_MODEL = exports.APP_VERSION = exports.LAYER = exports.INITIAL_DC = exports.VECTOR_CONSTRUCTOR = exports.PUBLIC_KEYS = exports.ACK_THRESHOLD = void 0;
|
|
27
27
|
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
28
|
+
exports.ACK_THRESHOLD = 10;
|
|
29
|
+
exports.PUBLIC_KEYS = Object.freeze([
|
|
30
30
|
[
|
|
31
31
|
1562291298945373506n,
|
|
32
32
|
[
|
|
@@ -76,26 +76,18 @@ exports.publicKeys = new Map([
|
|
|
76
76
|
0x010001n,
|
|
77
77
|
],
|
|
78
78
|
],
|
|
79
|
-
// Piltover
|
|
80
|
-
[
|
|
81
|
-
-5746138571559360724n,
|
|
82
|
-
[
|
|
83
|
-
26007219673003768186863565706940772901187119797549016801229858995725553827566821957407312503173782965285118977548255274803204174826509270586421841734996746493071723679186583391927378886693846518017621303145594627156874011707147548520576401963675756312298478878474644101348427872255774246965916073553469761183250044599310582333625453447885100318336864215713703860033765477732305055537755094341310278183464296754000479758644167423888581130401586546401934096183449791147912201040435037926911688179080223967863256047196705714611239523210563418382771999824529581206920323901890386681875893623076449827387008128524246269437n,
|
|
84
|
-
0x010001n,
|
|
85
|
-
],
|
|
86
|
-
],
|
|
87
79
|
]);
|
|
88
80
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
89
|
-
exports.
|
|
90
|
-
exports.LAYER =
|
|
91
|
-
exports.
|
|
81
|
+
exports.INITIAL_DC = "2-test";
|
|
82
|
+
exports.LAYER = 160;
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.0.969";
|
|
92
84
|
// @ts-ignore: lib
|
|
93
|
-
exports.
|
|
94
|
-
exports.
|
|
95
|
-
exports.
|
|
96
|
-
exports.
|
|
85
|
+
exports.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;
|
|
86
|
+
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
87
|
+
exports.LANG_PACK = "";
|
|
88
|
+
exports.SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
97
89
|
// @ts-ignore: lib
|
|
98
|
-
exports.
|
|
90
|
+
exports.SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
|
|
99
91
|
exports.USERNAME_TTL = 86400;
|
|
100
92
|
exports.STICKER_SET_NAME_TTL = 172800;
|
|
101
93
|
exports.MAX_CHAT_ID = 999999999999;
|
package/script/mod.d.ts
CHANGED
|
@@ -23,4 +23,4 @@ export * from "./transport/0_transport.js";
|
|
|
23
23
|
export * from "./transport/2_transport_provider.js";
|
|
24
24
|
export * from "./connection/0_connection.js";
|
|
25
25
|
export * from "./connection/1_connection_web_socket.js";
|
|
26
|
-
export {
|
|
26
|
+
export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./constants.js";
|
package/script/mod.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.SYSTEM_VERSION = exports.SYSTEM_LANG_CODE = exports.LAYER = exports.LANG_PACK = exports.LANG_CODE = exports.INITIAL_DC = exports.DEVICE_MODEL = exports.APP_VERSION = exports.functions = exports.types = exports.serialize = exports.as = exports.utils = void 0;
|
|
30
30
|
const _0_bigint_js_1 = require("./utilities/0_bigint.js");
|
|
31
31
|
const _0_password_js_1 = require("./client/0_password.js");
|
|
32
32
|
exports.utils = { checkPassword: _0_password_js_1.checkPassword, getRandomId: _0_bigint_js_1.getRandomId };
|
|
@@ -52,11 +52,11 @@ __exportStar(require("./transport/2_transport_provider.js"), exports);
|
|
|
52
52
|
__exportStar(require("./connection/0_connection.js"), exports);
|
|
53
53
|
__exportStar(require("./connection/1_connection_web_socket.js"), exports);
|
|
54
54
|
var constants_js_1 = require("./constants.js");
|
|
55
|
-
Object.defineProperty(exports, "
|
|
56
|
-
Object.defineProperty(exports, "
|
|
57
|
-
Object.defineProperty(exports, "
|
|
58
|
-
Object.defineProperty(exports, "
|
|
59
|
-
Object.defineProperty(exports, "
|
|
60
|
-
Object.defineProperty(exports, "DEFAULT_SYSTEM_LANG_CODE", { enumerable: true, get: function () { return constants_js_1.DEFAULT_SYSTEM_LANG_CODE; } });
|
|
61
|
-
Object.defineProperty(exports, "DEFAULT_SYSTEM_VERSION", { enumerable: true, get: function () { return constants_js_1.DEFAULT_SYSTEM_VERSION; } });
|
|
55
|
+
Object.defineProperty(exports, "APP_VERSION", { enumerable: true, get: function () { return constants_js_1.APP_VERSION; } });
|
|
56
|
+
Object.defineProperty(exports, "DEVICE_MODEL", { enumerable: true, get: function () { return constants_js_1.DEVICE_MODEL; } });
|
|
57
|
+
Object.defineProperty(exports, "INITIAL_DC", { enumerable: true, get: function () { return constants_js_1.INITIAL_DC; } });
|
|
58
|
+
Object.defineProperty(exports, "LANG_CODE", { enumerable: true, get: function () { return constants_js_1.LANG_CODE; } });
|
|
59
|
+
Object.defineProperty(exports, "LANG_PACK", { enumerable: true, get: function () { return constants_js_1.LANG_PACK; } });
|
|
62
60
|
Object.defineProperty(exports, "LAYER", { enumerable: true, get: function () { return constants_js_1.LAYER; } });
|
|
61
|
+
Object.defineProperty(exports, "SYSTEM_LANG_CODE", { enumerable: true, get: function () { return constants_js_1.SYSTEM_LANG_CODE; } });
|
|
62
|
+
Object.defineProperty(exports, "SYSTEM_VERSION", { enumerable: true, get: function () { return constants_js_1.SYSTEM_VERSION; } });
|