@mtkruto/node 0.0.835 → 0.0.901
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.d.ts +23 -3
- package/esm/client/client.js +497 -76
- package/esm/client/client_abstract.d.ts +2 -0
- package/esm/client/client_abstract.js +14 -3
- package/esm/client/client_plain.js +18 -4
- package/esm/constants.d.ts +7 -5
- package/esm/constants.js +10 -6
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/esm/deps/deno.land/std@0.190.0/encoding/base64.js +140 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.js +71 -0
- package/esm/deps.d.ts +2 -0
- package/esm/deps.js +2 -0
- package/esm/mod.d.ts +3 -3
- package/esm/mod.js +3 -3
- package/esm/storage/storage.d.ts +18 -0
- package/esm/storage/storage.js +103 -0
- package/esm/tl/1_tl_object.d.ts +0 -1
- package/esm/tl/1_tl_object.js +1 -1
- package/esm/tl/4_tl_writer.d.ts +5 -0
- package/esm/tl/5_rpc_result.d.ts +9 -0
- package/esm/tl/6_message.d.ts +10 -0
- package/esm/tl/{5_message.js → 6_message.js} +2 -2
- package/esm/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/esm/tl/{6_message_container.js → 7_message_container.js} +2 -2
- package/esm/transport/transport_provider.d.ts +7 -4
- package/esm/transport/transport_provider.js +11 -8
- package/esm/types/3_message.d.ts +5 -1
- package/esm/types/3_message.js +26 -22
- package/esm/utilities/1_message.d.ts +2 -2
- package/esm/utilities/1_message.js +3 -3
- package/esm/utilities/1_password.js +1 -1
- package/package.json +1 -1
- package/script/client/client.d.ts +23 -3
- package/script/client/client.js +497 -76
- package/script/client/client_abstract.d.ts +2 -0
- package/script/client/client_abstract.js +14 -3
- package/script/client/client_plain.js +18 -4
- package/script/constants.d.ts +7 -5
- package/script/constants.js +34 -7
- package/script/deps/deno.land/std@0.190.0/encoding/base64.d.ts +11 -0
- package/script/deps/deno.land/std@0.190.0/encoding/base64.js +145 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +6 -0
- package/script/deps/deno.land/x/q@v0.0.1/mod.js +75 -0
- package/script/deps.d.ts +2 -0
- package/script/deps.js +6 -1
- package/script/mod.d.ts +3 -3
- package/script/mod.js +3 -3
- package/script/storage/storage.d.ts +18 -0
- package/script/storage/storage.js +126 -0
- package/script/tl/1_tl_object.d.ts +0 -1
- package/script/tl/1_tl_object.js +1 -1
- package/script/tl/4_tl_writer.d.ts +5 -0
- package/script/tl/5_rpc_result.d.ts +9 -0
- package/script/tl/6_message.d.ts +10 -0
- package/script/tl/{5_message.js → 6_message.js} +6 -6
- package/script/tl/{6_message_container.d.ts → 7_message_container.d.ts} +1 -1
- package/script/tl/{6_message_container.js → 7_message_container.js} +4 -4
- package/script/transport/transport_provider.d.ts +7 -4
- package/script/transport/transport_provider.js +11 -8
- package/script/types/3_message.d.ts +5 -1
- package/script/types/3_message.js +26 -22
- package/script/utilities/1_message.d.ts +2 -2
- package/script/utilities/1_message.js +9 -9
- package/script/utilities/1_password.js +1 -1
- package/esm/tl/3_tl_writer.d.ts +0 -5
- package/esm/tl/4_rpc_result.d.ts +0 -8
- package/esm/tl/5_message.d.ts +0 -11
- package/script/tl/3_tl_writer.d.ts +0 -5
- package/script/tl/4_rpc_result.d.ts +0 -8
- package/script/tl/5_message.d.ts +0 -11
- /package/esm/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/esm/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
- /package/script/tl/{3_tl_writer.js → 4_tl_writer.js} +0 -0
- /package/script/tl/{4_rpc_result.js → 5_rpc_result.js} +0 -0
|
@@ -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,6 +2,7 @@ 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";
|
|
@@ -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");
|
package/esm/constants.d.ts
CHANGED
|
@@ -4,13 +4,15 @@ 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.901";
|
|
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;
|
|
16
16
|
export declare const ZERO_CHANNEL_ID = -1000000000000;
|
|
17
|
+
export declare const CHANNEL_DIFFERENCE_LIMIT_USER = 100;
|
|
18
|
+
export declare const CHANNEL_DIFFERENCE_LIMIT_BOT = 100000;
|
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,14 +62,17 @@ 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.901";
|
|
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;
|
|
74
76
|
export const ZERO_CHANNEL_ID = -1000000000000;
|
|
77
|
+
export const CHANNEL_DIFFERENCE_LIMIT_USER = 100;
|
|
78
|
+
export const CHANNEL_DIFFERENCE_LIMIT_BOT = 100000;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
3
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
4
|
+
* @param data
|
|
5
|
+
*/
|
|
6
|
+
export declare function encode(data: ArrayBuffer | string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
9
|
+
* @param b64
|
|
10
|
+
*/
|
|
11
|
+
export declare function decode(b64: string): Uint8Array;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* {@linkcode encode} and {@linkcode decode} for
|
|
5
|
+
* [base64](https://en.wikipedia.org/wiki/Base64) encoding.
|
|
6
|
+
*
|
|
7
|
+
* This module is browser compatible.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {
|
|
12
|
+
* decode,
|
|
13
|
+
* encode,
|
|
14
|
+
* } from "https://deno.land/std@$STD_VERSION/encoding/base64.ts";
|
|
15
|
+
*
|
|
16
|
+
* const b64Repr = "Zm9vYg==";
|
|
17
|
+
*
|
|
18
|
+
* const binaryData = decode(b64Repr);
|
|
19
|
+
* console.log(binaryData);
|
|
20
|
+
* // => Uint8Array [ 102, 111, 111, 98 ]
|
|
21
|
+
*
|
|
22
|
+
* console.log(encode(binaryData));
|
|
23
|
+
* // => Zm9vYg==
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
const base64abc = [
|
|
29
|
+
"A",
|
|
30
|
+
"B",
|
|
31
|
+
"C",
|
|
32
|
+
"D",
|
|
33
|
+
"E",
|
|
34
|
+
"F",
|
|
35
|
+
"G",
|
|
36
|
+
"H",
|
|
37
|
+
"I",
|
|
38
|
+
"J",
|
|
39
|
+
"K",
|
|
40
|
+
"L",
|
|
41
|
+
"M",
|
|
42
|
+
"N",
|
|
43
|
+
"O",
|
|
44
|
+
"P",
|
|
45
|
+
"Q",
|
|
46
|
+
"R",
|
|
47
|
+
"S",
|
|
48
|
+
"T",
|
|
49
|
+
"U",
|
|
50
|
+
"V",
|
|
51
|
+
"W",
|
|
52
|
+
"X",
|
|
53
|
+
"Y",
|
|
54
|
+
"Z",
|
|
55
|
+
"a",
|
|
56
|
+
"b",
|
|
57
|
+
"c",
|
|
58
|
+
"d",
|
|
59
|
+
"e",
|
|
60
|
+
"f",
|
|
61
|
+
"g",
|
|
62
|
+
"h",
|
|
63
|
+
"i",
|
|
64
|
+
"j",
|
|
65
|
+
"k",
|
|
66
|
+
"l",
|
|
67
|
+
"m",
|
|
68
|
+
"n",
|
|
69
|
+
"o",
|
|
70
|
+
"p",
|
|
71
|
+
"q",
|
|
72
|
+
"r",
|
|
73
|
+
"s",
|
|
74
|
+
"t",
|
|
75
|
+
"u",
|
|
76
|
+
"v",
|
|
77
|
+
"w",
|
|
78
|
+
"x",
|
|
79
|
+
"y",
|
|
80
|
+
"z",
|
|
81
|
+
"0",
|
|
82
|
+
"1",
|
|
83
|
+
"2",
|
|
84
|
+
"3",
|
|
85
|
+
"4",
|
|
86
|
+
"5",
|
|
87
|
+
"6",
|
|
88
|
+
"7",
|
|
89
|
+
"8",
|
|
90
|
+
"9",
|
|
91
|
+
"+",
|
|
92
|
+
"/",
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727
|
|
96
|
+
* Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation
|
|
97
|
+
* @param data
|
|
98
|
+
*/
|
|
99
|
+
export function encode(data) {
|
|
100
|
+
const uint8 = typeof data === "string"
|
|
101
|
+
? new TextEncoder().encode(data)
|
|
102
|
+
: data instanceof Uint8Array
|
|
103
|
+
? data
|
|
104
|
+
: new Uint8Array(data);
|
|
105
|
+
let result = "", i;
|
|
106
|
+
const l = uint8.length;
|
|
107
|
+
for (i = 2; i < l; i += 3) {
|
|
108
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
109
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
110
|
+
result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)];
|
|
111
|
+
result += base64abc[uint8[i] & 0x3f];
|
|
112
|
+
}
|
|
113
|
+
if (i === l + 1) {
|
|
114
|
+
// 1 octet yet to write
|
|
115
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
116
|
+
result += base64abc[(uint8[i - 2] & 0x03) << 4];
|
|
117
|
+
result += "==";
|
|
118
|
+
}
|
|
119
|
+
if (i === l) {
|
|
120
|
+
// 2 octets yet to write
|
|
121
|
+
result += base64abc[uint8[i - 2] >> 2];
|
|
122
|
+
result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)];
|
|
123
|
+
result += base64abc[(uint8[i - 1] & 0x0f) << 2];
|
|
124
|
+
result += "=";
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Decodes a given RFC4648 base64 encoded string
|
|
130
|
+
* @param b64
|
|
131
|
+
*/
|
|
132
|
+
export function decode(b64) {
|
|
133
|
+
const binString = atob(b64);
|
|
134
|
+
const size = binString.length;
|
|
135
|
+
const bytes = new Uint8Array(size);
|
|
136
|
+
for (let i = 0; i < size; i++) {
|
|
137
|
+
bytes[i] = binString.charCodeAt(i);
|
|
138
|
+
}
|
|
139
|
+
return bytes;
|
|
140
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function queue<T, R>(runner: (task: T) => R, concurrency: number): {
|
|
2
|
+
push: (task: T | T[]) => void;
|
|
3
|
+
drain: (fn?: any) => void | Promise<any>;
|
|
4
|
+
onError: (fn: (task: T, error: Error) => any) => (task: T, error: Error) => any;
|
|
5
|
+
onDone: (fn: (task: T, result: R) => any) => (task: T, result: R) => any;
|
|
6
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export function queue(runner, concurrency) {
|
|
2
|
+
if (concurrency <= 0) {
|
|
3
|
+
throw new RangeError('concurrency can only be a positive integer');
|
|
4
|
+
}
|
|
5
|
+
if (!Number.isInteger(concurrency)) {
|
|
6
|
+
throw new RangeError('concurrency can only be a positive integer');
|
|
7
|
+
}
|
|
8
|
+
const tasks = [];
|
|
9
|
+
let running = 0;
|
|
10
|
+
let drains = [];
|
|
11
|
+
let onError = () => { };
|
|
12
|
+
let onDone = () => { };
|
|
13
|
+
let drainAwaiters = [];
|
|
14
|
+
function drained() {
|
|
15
|
+
drains.forEach((d) => d());
|
|
16
|
+
drains = [];
|
|
17
|
+
drainAwaiters.forEach((s) => s());
|
|
18
|
+
drainAwaiters = [];
|
|
19
|
+
}
|
|
20
|
+
async function runNext() {
|
|
21
|
+
if (running < concurrency && tasks.length > 0) {
|
|
22
|
+
running++;
|
|
23
|
+
const task = tasks.shift();
|
|
24
|
+
if (task) {
|
|
25
|
+
try {
|
|
26
|
+
const result = await runner(task);
|
|
27
|
+
onDone(task, result);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
onError(task, err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
running--;
|
|
34
|
+
if (tasks.length > 0) {
|
|
35
|
+
queueMicrotask(runNext); // to prevent "Maximum call stack size exceeded"
|
|
36
|
+
}
|
|
37
|
+
else if (running === 0) {
|
|
38
|
+
drained();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
push: (task) => {
|
|
44
|
+
let needed = 1;
|
|
45
|
+
if (Array.isArray(task)) {
|
|
46
|
+
tasks.push(...task);
|
|
47
|
+
needed = task.length;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
tasks.push(task);
|
|
51
|
+
}
|
|
52
|
+
const free = concurrency - running;
|
|
53
|
+
for (let i = 0; i < Math.max(free, needed); i++) {
|
|
54
|
+
runNext();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
drain: (fn) => {
|
|
58
|
+
if (fn) {
|
|
59
|
+
drains.push(fn);
|
|
60
|
+
}
|
|
61
|
+
else if (tasks.length > 0 || running > 0) {
|
|
62
|
+
return new Promise((resolve) => drainAwaiters.push(resolve));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onError: (fn) => (onError = fn),
|
|
69
|
+
onDone: (fn) => (onDone = fn),
|
|
70
|
+
};
|
|
71
|
+
}
|
package/esm/deps.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ 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
7
|
export declare const debug: typeof debug_;
|
|
8
|
+
export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
|
|
9
|
+
export { decode as base64Decode, encode as base64Encode } from "./deps/deno.land/std@0.190.0/encoding/base64.js";
|
package/esm/deps.js
CHANGED
|
@@ -5,3 +5,5 @@ 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
7
|
export const debug = (v) => debug_(`mtkruto__${v}`);
|
|
8
|
+
export { queue } from "./deps/deno.land/x/q@v0.0.1/mod.js";
|
|
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
|
@@ -7,9 +7,9 @@ export declare const utils: {
|
|
|
7
7
|
export { as } from "./tl/1_tl_object.js";
|
|
8
8
|
export * as types from "./tl/2_types.js";
|
|
9
9
|
export * as functions from "./tl/3_functions.js";
|
|
10
|
-
export * from "./tl/
|
|
11
|
-
export * from "./tl/
|
|
12
|
-
export * from "./tl/
|
|
10
|
+
export * from "./tl/5_rpc_result.js";
|
|
11
|
+
export * from "./tl/6_message.js";
|
|
12
|
+
export * from "./tl/7_message_container.js";
|
|
13
13
|
export * from "./client/client_plain.js";
|
|
14
14
|
export * from "./client/client.js";
|
|
15
15
|
export * from "./storage/storage.js";
|
package/esm/mod.js
CHANGED
|
@@ -4,9 +4,9 @@ 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";
|
|
6
6
|
export * as functions from "./tl/3_functions.js";
|
|
7
|
-
export * from "./tl/
|
|
8
|
-
export * from "./tl/
|
|
9
|
-
export * from "./tl/
|
|
7
|
+
export * from "./tl/5_rpc_result.js";
|
|
8
|
+
export * from "./tl/6_message.js";
|
|
9
|
+
export * from "./tl/7_message_container.js";
|
|
10
10
|
export * from "./client/client_plain.js";
|
|
11
11
|
export * from "./client/client.js";
|
|
12
12
|
export * from "./storage/storage.js";
|
package/esm/storage/storage.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
import { DC } from "../transport/transport_provider.js";
|
|
3
|
+
import * as types from "../tl/2_types.js";
|
|
3
4
|
export declare abstract class Storage {
|
|
4
5
|
private _authKeyId;
|
|
5
6
|
abstract init(): MaybePromise<void>;
|
|
@@ -20,4 +21,21 @@ export declare abstract class Storage {
|
|
|
20
21
|
private readonly username__;
|
|
21
22
|
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
22
23
|
getUsername(username: string): Promise<readonly ["channel" | "user", bigint, Date] | null>;
|
|
24
|
+
private readonly state__;
|
|
25
|
+
setState(state: types.UpdatesState): Promise<void>;
|
|
26
|
+
getState(): Promise<types.UpdatesState | null>;
|
|
27
|
+
private readonly channelPts__;
|
|
28
|
+
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
29
|
+
getChannelPts(channelId: bigint): Promise<number | null>;
|
|
30
|
+
private readonly peer__;
|
|
31
|
+
setEntity(peer: types.Channel): Promise<void>;
|
|
32
|
+
setEntity(peer: types.Chat): Promise<void>;
|
|
33
|
+
setEntity(peer: types.User): Promise<void>;
|
|
34
|
+
getEntity(type: "channel", id: bigint): Promise<types.Channel | null>;
|
|
35
|
+
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
36
|
+
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
37
|
+
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
38
|
+
private readonly accountType__;
|
|
39
|
+
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
40
|
+
getAccountType(): Promise<"bot" | "user">;
|
|
23
41
|
}
|
package/esm/storage/storage.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { base64Decode, base64Encode } from "../deps.js";
|
|
2
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
1
3
|
import { sha1 } from "../utilities/0_hash.js";
|
|
2
4
|
import { bigIntFromBuffer } from "../utilities/0_bigint.js";
|
|
5
|
+
import { serialize } from "../tl/1_tl_object.js";
|
|
6
|
+
import * as types from "../tl/2_types.js";
|
|
7
|
+
import { TLReader } from "../tl/3_tl_reader.js";
|
|
3
8
|
export class Storage {
|
|
4
9
|
constructor() {
|
|
5
10
|
Object.defineProperty(this, "_authKeyId", {
|
|
@@ -26,6 +31,30 @@ export class Storage {
|
|
|
26
31
|
writable: true,
|
|
27
32
|
value: "username__"
|
|
28
33
|
});
|
|
34
|
+
Object.defineProperty(this, "state__", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: "state__"
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "channelPts__", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: "channelPts__"
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "peer__", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: "peer__"
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "accountType__", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: "accountType__"
|
|
57
|
+
});
|
|
29
58
|
}
|
|
30
59
|
setDc(dc) {
|
|
31
60
|
return this.set("dc", dc);
|
|
@@ -95,4 +124,78 @@ export class Storage {
|
|
|
95
124
|
return null;
|
|
96
125
|
}
|
|
97
126
|
}
|
|
127
|
+
async setState(state) {
|
|
128
|
+
await this.set(this.state__, JSON.stringify({
|
|
129
|
+
date: state.date,
|
|
130
|
+
pts: state.pts,
|
|
131
|
+
qts: state.qts,
|
|
132
|
+
seq: state.seq,
|
|
133
|
+
unreadCount: state.unreadCount,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
async getState() {
|
|
137
|
+
const state__ = await this.get(this.state__);
|
|
138
|
+
if (state__ != null) {
|
|
139
|
+
const state_ = JSON.parse(state__);
|
|
140
|
+
return new types.UpdatesState({
|
|
141
|
+
date: state_.date,
|
|
142
|
+
pts: state_.pts,
|
|
143
|
+
qts: state_.qts,
|
|
144
|
+
seq: state_.seq,
|
|
145
|
+
unreadCount: state_.unreadCount,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async setChannelPts(channelId, pts) {
|
|
153
|
+
await this.set(`${this.channelPts__}${channelId}`, String(pts));
|
|
154
|
+
}
|
|
155
|
+
async getChannelPts(channelId) {
|
|
156
|
+
const pts = await this.get(`${this.channelPts__}${channelId}`);
|
|
157
|
+
if (pts != null) {
|
|
158
|
+
return Number(pts);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async setEntity(peer) {
|
|
165
|
+
const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : UNREACHABLE();
|
|
166
|
+
await this.set(`${this.peer__}${type}${peer.id}`, base64Encode(peer[serialize]()));
|
|
167
|
+
}
|
|
168
|
+
async getEntity(type, id) {
|
|
169
|
+
const peer_ = await this.get(`${this.peer__}${type}${id}`);
|
|
170
|
+
if (peer_ != null) {
|
|
171
|
+
const reader = new TLReader(base64Decode(peer_));
|
|
172
|
+
return reader.readObject();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async setAccountType(type) {
|
|
179
|
+
try {
|
|
180
|
+
await this.getAccountType();
|
|
181
|
+
UNREACHABLE();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
if (!(err instanceof Error) || !(err.message == "Unreachable")) {
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await this.set(this.accountType__, type);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async getAccountType() {
|
|
193
|
+
const accountType = await this.get(this.accountType__);
|
|
194
|
+
if (accountType != null) {
|
|
195
|
+
return accountType;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
UNREACHABLE();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
98
201
|
}
|
package/esm/tl/1_tl_object.d.ts
CHANGED
|
@@ -31,7 +31,6 @@ export declare abstract class TLObject {
|
|
|
31
31
|
[serialize](): Uint8Array;
|
|
32
32
|
[as]<T extends TLObjectConstructor<InstanceType<T>>>(constructor: T): InstanceType<T>;
|
|
33
33
|
}
|
|
34
|
-
export type MaybeVectorTLObject = TLObject | Array<MaybeVectorTLObject | TLObject>;
|
|
35
34
|
export interface TLObjectConstructor<T = TLObject> {
|
|
36
35
|
new (params: any): T;
|
|
37
36
|
[paramDesc]: ParamDesc;
|
package/esm/tl/1_tl_object.js
CHANGED
|
@@ -28,7 +28,7 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
throw new TypeError(`Expected ${type.name}`);
|
|
31
|
+
throw new TypeError(`Expected ${type.name} but received ${value == null ? null : value.constructor.name}`);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
if (type == Uint8Array) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { id } from "./1_tl_object.js";
|
|
2
|
+
import { ReadObject } from "./3_tl_reader.js";
|
|
3
|
+
export declare class RPCResult {
|
|
4
|
+
readonly messageId: bigint;
|
|
5
|
+
readonly result: ReadObject;
|
|
6
|
+
static get [id](): number;
|
|
7
|
+
constructor(messageId: bigint, result: ReadObject);
|
|
8
|
+
static deserialize(buffer: Uint8Array): RPCResult;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReadObject, TLReader } from "./3_tl_reader.js";
|
|
2
|
+
import { RPCResult } from "./5_rpc_result.js";
|
|
3
|
+
export declare class Message {
|
|
4
|
+
readonly id: bigint;
|
|
5
|
+
readonly seqNo: number;
|
|
6
|
+
readonly body: ReadObject | RPCResult;
|
|
7
|
+
constructor(id: bigint, seqNo: number, body: ReadObject | RPCResult);
|
|
8
|
+
serialize(): Uint8Array;
|
|
9
|
+
static deserialize(reader: TLReader): Message;
|
|
10
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { id, serialize } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
|
-
import { TLWriter } from "./
|
|
4
|
-
import { RPCResult } from "./
|
|
3
|
+
import { TLWriter } from "./4_tl_writer.js";
|
|
4
|
+
import { RPCResult } from "./5_rpc_result.js";
|
|
5
5
|
// TODO: test
|
|
6
6
|
function calculateLength(object) {
|
|
7
7
|
let length = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { id } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
|
-
import { TLWriter } from "./
|
|
4
|
-
import { Message } from "./
|
|
3
|
+
import { TLWriter } from "./4_tl_writer.js";
|
|
4
|
+
import { Message } from "./6_message.js";
|
|
5
5
|
export class MessageContainer {
|
|
6
6
|
static get [id]() {
|
|
7
7
|
return 0x73F1F8DC;
|
|
@@ -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;
|