@mtkruto/node 0.0.966 → 0.0.968
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/0_message.js +1 -2
- package/esm/client/1_client_abstract.js +2 -2
- package/esm/client/3_client.d.ts +3 -3
- package/esm/client/3_client.js +3 -6
- 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 +4 -4
- package/esm/constants.d.ts +2 -2
- package/esm/constants.js +2 -2
- package/esm/tl/2_types.d.ts +484 -87
- package/esm/tl/2_types.js +1647 -308
- package/esm/tl/3_functions.d.ts +286 -48
- package/esm/tl/3_functions.js +919 -165
- 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/0_message.js +1 -2
- package/script/client/1_client_abstract.js +1 -1
- package/script/client/3_client.d.ts +3 -3
- package/script/client/3_client.js +3 -6
- 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 +4 -4
- package/script/constants.d.ts +2 -2
- package/script/constants.js +2 -2
- package/script/tl/2_types.d.ts +484 -87
- package/script/tl/2_types.js +1718 -339
- package/script/tl/3_functions.d.ts +286 -48
- package/script/tl/3_functions.js +950 -175
- 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
package/esm/client/0_message.js
CHANGED
|
@@ -17,11 +17,10 @@ export function getMessageId(lastMsgId) {
|
|
|
17
17
|
if (lastMsgId >= (newMsgId)) {
|
|
18
18
|
newMsgId = lastMsgId + 4n;
|
|
19
19
|
}
|
|
20
|
-
lastMsgId = newMsgId;
|
|
21
20
|
return newMsgId;
|
|
22
21
|
}
|
|
23
22
|
export function packUnencryptedMessage(data, messageId) {
|
|
24
|
-
const message = concat(bufferFromBigInt(0x00, 8), bufferFromBigInt(
|
|
23
|
+
const message = concat(bufferFromBigInt(0x00, 8), bufferFromBigInt(messageId, 8), bufferFromBigInt(data.length, 4), data);
|
|
25
24
|
return message;
|
|
26
25
|
}
|
|
27
26
|
export function unpackUnencryptedMessage(buffer) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { initTgCrypto } from "../deps.js";
|
|
2
2
|
import { DEFAULT_INITIAL_DC } from "../constants.js";
|
|
3
|
-
import {
|
|
3
|
+
import { webSocketTransportProvider } from "../transport/2_transport_provider.js";
|
|
4
4
|
export class ClientAbstract {
|
|
5
5
|
get initialDc() {
|
|
6
6
|
return this._initialDc;
|
|
7
7
|
}
|
|
8
|
-
constructor(transportProvider =
|
|
8
|
+
constructor(transportProvider = webSocketTransportProvider({ initialDc: DEFAULT_INITIAL_DC }), cdn = false) {
|
|
9
9
|
Object.defineProperty(this, "transportProvider", {
|
|
10
10
|
enumerable: true,
|
|
11
11
|
configurable: true,
|
package/esm/client/3_client.d.ts
CHANGED
|
@@ -69,8 +69,8 @@ export interface ForwardMessagesParams {
|
|
|
69
69
|
}
|
|
70
70
|
export declare class Client extends ClientAbstract {
|
|
71
71
|
readonly storage: Storage;
|
|
72
|
-
readonly apiId: number;
|
|
73
|
-
readonly apiHash: string;
|
|
72
|
+
readonly apiId: number | null;
|
|
73
|
+
readonly apiHash: string | null;
|
|
74
74
|
private auth;
|
|
75
75
|
private sessionId;
|
|
76
76
|
private state;
|
|
@@ -93,7 +93,7 @@ export declare class Client extends ClientAbstract {
|
|
|
93
93
|
* @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Default to empty string (unset).
|
|
94
94
|
* @param params Other parameters.
|
|
95
95
|
*/
|
|
96
|
-
constructor(storage?: Storage, apiId?: number, apiHash?: string, params?: ClientParams, cdn?: boolean);
|
|
96
|
+
constructor(storage?: Storage, apiId?: number | null, apiHash?: string | null, params?: ClientParams, cdn?: boolean);
|
|
97
97
|
private storageInited;
|
|
98
98
|
/**
|
|
99
99
|
* Sets the DC and resets the auth key stored in the session provider
|
package/esm/client/3_client.js
CHANGED
|
@@ -372,7 +372,7 @@ export class Client extends ClientAbstract {
|
|
|
372
372
|
apiId: this.apiId,
|
|
373
373
|
apiHash: this.apiHash,
|
|
374
374
|
phoneNumber,
|
|
375
|
-
settings: new types.CodeSettings(),
|
|
375
|
+
settings: new types.CodeSettings({}),
|
|
376
376
|
}));
|
|
377
377
|
dAuth("verification code sent");
|
|
378
378
|
if (sentCode instanceof types.AuthSentCode) {
|
|
@@ -567,9 +567,8 @@ export class Client extends ClientAbstract {
|
|
|
567
567
|
const messageId = this.lastMsgId = getMessageId(this.lastMsgId);
|
|
568
568
|
const message = new Message_(messageId, seqNo, function_);
|
|
569
569
|
await this.transport.send(await encryptMessage(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
570
|
-
|
|
570
|
+
d("invoked %s", function_.constructor.name);
|
|
571
571
|
if (noWait) {
|
|
572
|
-
d_();
|
|
573
572
|
return;
|
|
574
573
|
}
|
|
575
574
|
const result = await new Promise((resolve, reject) => {
|
|
@@ -579,7 +578,6 @@ export class Client extends ClientAbstract {
|
|
|
579
578
|
return await this.invoke(function_);
|
|
580
579
|
}
|
|
581
580
|
else {
|
|
582
|
-
d_();
|
|
583
581
|
return result;
|
|
584
582
|
}
|
|
585
583
|
}
|
|
@@ -1147,8 +1145,7 @@ export class Client extends ClientAbstract {
|
|
|
1147
1145
|
noWebpage,
|
|
1148
1146
|
silent,
|
|
1149
1147
|
noforwards,
|
|
1150
|
-
replyToMsgId,
|
|
1151
|
-
topMsgId,
|
|
1148
|
+
replyTo: replyToMsgId !== undefined ? new types.InputReplyToMessage({ replyToMsgId, topMsgId }) : undefined,
|
|
1152
1149
|
sendAs,
|
|
1153
1150
|
entities,
|
|
1154
1151
|
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,2 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
class Foundation {
|
|
2
|
+
}
|
|
3
|
+
export class ConnectionUnframed extends Foundation {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
Object.defineProperty(this, "type", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: "framed"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class ConnectionFramed extends Foundation {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
Object.defineProperty(this, "type", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: "framed"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
2
24
|
}
|
|
@@ -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,91 @@
|
|
|
1
|
+
import { Mutex } from "../deps.js";
|
|
2
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
3
|
+
import { ConnectionFramed } from "./0_connection.js";
|
|
4
|
+
export class ConnectionHTTP extends ConnectionFramed {
|
|
5
|
+
constructor(url) {
|
|
6
|
+
super();
|
|
7
|
+
Object.defineProperty(this, "url", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: url
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "rMutex", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: new Mutex()
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "wMutex", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: new Mutex()
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "resolveCanRead", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: () => { }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "canRead", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: Promise.resolve()
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "buffers", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: new Array()
|
|
42
|
+
});
|
|
43
|
+
this.resetCanRead();
|
|
44
|
+
}
|
|
45
|
+
resetCanRead() {
|
|
46
|
+
this.canRead = new Promise((r) => this.resolveCanRead = r);
|
|
47
|
+
}
|
|
48
|
+
get connected() {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
async open() {
|
|
52
|
+
}
|
|
53
|
+
async read() {
|
|
54
|
+
await this.canRead;
|
|
55
|
+
const release = await this.rMutex.acquire();
|
|
56
|
+
try {
|
|
57
|
+
const buffer = this.buffers.pop();
|
|
58
|
+
if (buffer === undefined) {
|
|
59
|
+
throw UNREACHABLE();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return buffer;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (this.buffers.length == 0) {
|
|
67
|
+
this.resetCanRead();
|
|
68
|
+
}
|
|
69
|
+
release();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async write(buffer) {
|
|
73
|
+
const release = await this.wMutex.acquire();
|
|
74
|
+
try {
|
|
75
|
+
const res = await fetch(this.url, {
|
|
76
|
+
mode: "cors",
|
|
77
|
+
method: "POST",
|
|
78
|
+
body: buffer,
|
|
79
|
+
});
|
|
80
|
+
this.buffers.push(new Uint8Array(await res.arrayBuffer()));
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (this.buffers.length == 1) {
|
|
84
|
+
this.resolveCanRead();
|
|
85
|
+
}
|
|
86
|
+
release();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -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;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as dntShim from "../_dnt.shims.js";
|
|
2
2
|
import { debug, Mutex } from "../deps.js";
|
|
3
|
+
import { ConnectionUnframed } from "./0_connection.js";
|
|
3
4
|
const d = debug("ConnectionWebSocket");
|
|
4
|
-
export class ConnectionWebSocket {
|
|
5
|
+
export class ConnectionWebSocket extends ConnectionUnframed {
|
|
5
6
|
constructor(url) {
|
|
7
|
+
super();
|
|
6
8
|
Object.defineProperty(this, "webSocket", {
|
|
7
9
|
enumerable: true,
|
|
8
10
|
configurable: true,
|
|
@@ -46,7 +48,6 @@ export class ConnectionWebSocket {
|
|
|
46
48
|
value: null
|
|
47
49
|
});
|
|
48
50
|
this.webSocket = this.reinitWs(url);
|
|
49
|
-
// TODO
|
|
50
51
|
this.webSocket.addEventListener("close", (e) => {
|
|
51
52
|
if (e.code != 1000 && e.reason != "method") {
|
|
52
53
|
this.webSocket = this.reinitWs(url);
|
|
@@ -61,7 +62,7 @@ export class ConnectionWebSocket {
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
const release = await mutex.acquire();
|
|
64
|
-
const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof ArrayBuffer ? v : Array.isArray(v) ? v.map((v) => v.buffer) : v.buffer).flat()).arrayBuffer());
|
|
65
|
+
const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob ? v : v instanceof ArrayBuffer ? v : Array.isArray(v) ? v.map((v) => v.buffer) : v.buffer).flat()).arrayBuffer());
|
|
65
66
|
for (const byte of data) {
|
|
66
67
|
this.buffer.push(byte);
|
|
67
68
|
}
|
|
@@ -140,6 +141,5 @@ export class ConnectionWebSocket {
|
|
|
140
141
|
throw new Error("Connection not open");
|
|
141
142
|
}
|
|
142
143
|
this.webSocket.close(1000, "method");
|
|
143
|
-
console.trace("close called");
|
|
144
144
|
}
|
|
145
145
|
}
|
package/esm/constants.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export declare const ackThreshold = 10;
|
|
|
3
3
|
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
|
-
export declare const LAYER =
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
6
|
+
export declare const LAYER = 160;
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.968";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/esm/constants.js
CHANGED
|
@@ -61,8 +61,8 @@ export const publicKeys = new Map([
|
|
|
61
61
|
]);
|
|
62
62
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
63
63
|
export const DEFAULT_INITIAL_DC = "2-test";
|
|
64
|
-
export const LAYER =
|
|
65
|
-
export const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
64
|
+
export const LAYER = 160;
|
|
65
|
+
export const DEFAULT_APP_VERSION = "MTKruto 0.0.968";
|
|
66
66
|
// @ts-ignore: lib
|
|
67
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
68
|
export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|