@mtkruto/node 0.0.801 → 0.0.821
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/_dnt.test_shims.d.ts +10 -0
- package/esm/client/client_plain.js +4 -3
- package/esm/connection/connection_web_socket.js +3 -1
- package/{types → esm}/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/tl/0_tl_raw_reader_test.d.ts +1 -0
- package/esm/tl/0_tl_raw_writer_test.d.ts +1 -0
- package/{types → esm}/tl/1_tl_object.d.ts +5 -2
- package/esm/tl/1_tl_object.js +14 -7
- package/esm/tl/1_tl_object_test.d.ts +1 -0
- package/esm/tl/2_types_test.d.ts +1 -0
- package/esm/tl/3_deserialize_test.d.ts +1 -0
- package/esm/tl/3_functions_test.d.ts +1 -0
- package/esm/tl/3_tl_reader.js +1 -1
- package/esm/tl/3_tl_writer.js +2 -1
- package/esm/tl/5_message.js +2 -2
- package/esm/utilities/0_bigint_test.d.ts +1 -0
- package/esm/utilities/0_buffer_test.d.ts +1 -0
- package/esm/utilities/1_message.js +2 -2
- package/esm/utilities/1_password_test.d.ts +1 -0
- package/package.json +5 -12
- package/script/_dnt.shims.d.ts +10 -0
- package/script/_dnt.test_shims.d.ts +10 -0
- package/script/client/client.d.ts +50 -0
- package/script/client/client_abstract.d.ts +16 -0
- package/script/client/client_plain.d.ts +9 -0
- package/script/client/client_plain.js +4 -3
- package/script/connection/connection.d.ts +7 -0
- package/script/connection/connection_web_socket.d.ts +13 -0
- package/script/connection/connection_web_socket.js +3 -1
- package/script/constants.d.ts +12 -0
- package/script/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
- package/script/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
- package/script/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
- package/script/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
- package/script/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.3/mod.d.ts +47 -0
- package/script/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.d.ts +2 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
- package/script/deps.d.ts +4 -0
- package/script/mod.d.ts +24 -0
- package/script/mod.js +3 -1
- package/script/session/session.d.ts +12 -0
- package/script/session/session_local_storage.d.ts +7 -0
- package/script/session/session_memory.d.ts +5 -0
- package/script/tl/0_tl_raw_reader.d.ts +13 -0
- package/script/tl/0_tl_raw_reader_test.d.ts +1 -0
- package/script/tl/0_tl_raw_writer.d.ts +13 -0
- package/script/tl/0_tl_raw_writer_test.d.ts +1 -0
- package/script/tl/1_tl_object.d.ts +40 -0
- package/script/tl/1_tl_object.js +15 -8
- package/script/tl/1_tl_object_test.d.ts +1 -0
- package/script/tl/2_types.d.ts +14815 -0
- package/script/tl/2_types_test.d.ts +1 -0
- package/script/tl/3_deserialize.d.ts +3 -0
- package/script/tl/3_deserialize_test.d.ts +1 -0
- package/script/tl/3_functions.d.ts +6122 -0
- package/script/tl/3_functions_test.d.ts +1 -0
- package/script/tl/3_tl_reader.d.ts +6 -0
- package/script/tl/3_tl_reader.js +2 -2
- package/script/tl/3_tl_writer.d.ts +5 -0
- package/script/tl/3_tl_writer.js +2 -1
- package/script/tl/4_rpc_result.d.ts +8 -0
- package/script/tl/5_message.d.ts +11 -0
- package/script/tl/5_message.js +1 -1
- package/script/tl/6_message_container.d.ts +9 -0
- package/script/transport/transport.d.ts +15 -0
- package/script/transport/transport_abridged.d.ts +11 -0
- package/script/transport/transport_intermediate.d.ts +11 -0
- package/script/transport/transport_provider.d.ts +17 -0
- package/script/types.d.ts +1 -0
- package/script/utilities/0_bigint.d.ts +5 -0
- package/script/utilities/0_bigint_test.d.ts +1 -0
- package/script/utilities/0_buffer.d.ts +2 -0
- package/script/utilities/0_buffer_test.d.ts +1 -0
- package/script/utilities/0_crypto.d.ts +8 -0
- package/script/utilities/0_hash.d.ts +2 -0
- package/script/utilities/1_auth.d.ts +1 -0
- package/script/utilities/1_message.d.ts +10 -0
- package/script/utilities/1_message.js +1 -1
- package/script/utilities/1_obfuscation.d.ts +6 -0
- package/script/utilities/1_password.d.ts +11 -0
- package/script/utilities/1_password_test.d.ts +1 -0
- /package/{types → esm}/_dnt.shims.d.ts +0 -0
- /package/{types → esm}/client/client.d.ts +0 -0
- /package/{types → esm}/client/client_abstract.d.ts +0 -0
- /package/{types → esm}/client/client_plain.d.ts +0 -0
- /package/{types → esm}/connection/connection.d.ts +0 -0
- /package/{types → esm}/connection/connection_web_socket.d.ts +0 -0
- /package/{types → esm}/constants.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/std@0.186.0/fmt/colors.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/std@0.186.0/testing/_diff.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/std@0.186.0/testing/_format.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/std@0.186.0/testing/asserts.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/x/tgcrypto@0.1.3/mod.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +0 -0
- /package/{types → esm}/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +0 -0
- /package/{types → esm}/deps.d.ts +0 -0
- /package/{types → esm}/session/session.d.ts +0 -0
- /package/{types → esm}/session/session_local_storage.d.ts +0 -0
- /package/{types → esm}/session/session_memory.d.ts +0 -0
- /package/{types → esm}/tl/0_tl_raw_reader.d.ts +0 -0
- /package/{types → esm}/tl/0_tl_raw_writer.d.ts +0 -0
- /package/{types → esm}/tl/2_types.d.ts +0 -0
- /package/{types/tl/3_tl_object_deserializer.d.ts → esm/tl/3_deserialize.d.ts} +0 -0
- /package/esm/tl/{3_tl_object_deserializer.js → 3_deserialize.js} +0 -0
- /package/{types → esm}/tl/3_functions.d.ts +0 -0
- /package/{types → esm}/tl/3_tl_reader.d.ts +0 -0
- /package/{types → esm}/tl/3_tl_writer.d.ts +0 -0
- /package/{types → esm}/tl/4_rpc_result.d.ts +0 -0
- /package/{types → esm}/tl/5_message.d.ts +0 -0
- /package/{types → esm}/tl/6_message_container.d.ts +0 -0
- /package/{types → esm}/transport/transport.d.ts +0 -0
- /package/{types → esm}/transport/transport_abridged.d.ts +0 -0
- /package/{types → esm}/transport/transport_intermediate.d.ts +0 -0
- /package/{types → esm}/transport/transport_provider.d.ts +0 -0
- /package/{types → esm}/types.d.ts +0 -0
- /package/{types → esm}/utilities/0_bigint.d.ts +0 -0
- /package/{types → esm}/utilities/0_buffer.d.ts +0 -0
- /package/{types → esm}/utilities/0_crypto.d.ts +0 -0
- /package/{types → esm}/utilities/0_hash.d.ts +0 -0
- /package/{types → esm}/utilities/1_auth.d.ts +0 -0
- /package/{types → esm}/utilities/1_message.d.ts +0 -0
- /package/{types → esm}/utilities/1_obfuscation.d.ts +0 -0
- /package/{types → esm}/utilities/1_password.d.ts +0 -0
- /package/script/tl/{3_tl_object_deserializer.js → 3_deserialize.js} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { default as WebSocket } from "ws";
|
|
5
|
+
export { default as WebSocket } from "ws";
|
|
6
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "WebSocket" | "crypto" | "Deno"> & {
|
|
7
|
+
Deno: typeof Deno;
|
|
8
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
9
|
+
WebSocket: typeof WebSocket;
|
|
10
|
+
};
|
|
@@ -4,6 +4,7 @@ import { bigIntFromBuffer, getRandomBigInt, modExp } from "../utilities/0_bigint
|
|
|
4
4
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
5
5
|
import { sha1 } from "../utilities/0_hash.js";
|
|
6
6
|
import { rsaPad } from "../utilities/1_auth.js";
|
|
7
|
+
import { serialize } from "../tl/1_tl_object.js";
|
|
7
8
|
import { packUnencryptedMessage, unpackUnencryptedMessage } from "../utilities/1_message.js";
|
|
8
9
|
import { ClientDHInnerData, DHGenOK, PQInnerDataDC, ResPQ, ServerDHInnerData, ServerDHParamsOK } from "../tl/2_types.js";
|
|
9
10
|
import { ReqDHParams, ReqPQMulti, SetClientDHParams } from "../tl/3_functions.js";
|
|
@@ -11,7 +12,7 @@ import { TLReader } from "../tl/3_tl_reader.js";
|
|
|
11
12
|
import { ClientAbstract } from "./client_abstract.js";
|
|
12
13
|
export class ClientPlain extends ClientAbstract {
|
|
13
14
|
async invoke(function_) {
|
|
14
|
-
await this.transport.send(packUnencryptedMessage(function_
|
|
15
|
+
await this.transport.send(packUnencryptedMessage(function_[serialize]()));
|
|
15
16
|
const buffer = await this.transport.receive();
|
|
16
17
|
if (buffer.length == 4) {
|
|
17
18
|
const int = bigIntFromBuffer(buffer, true, true);
|
|
@@ -60,7 +61,7 @@ export class ClientPlain extends ClientAbstract {
|
|
|
60
61
|
newNonce,
|
|
61
62
|
nonce,
|
|
62
63
|
serverNonce,
|
|
63
|
-
})
|
|
64
|
+
})[serialize](), publicKey);
|
|
64
65
|
const dhParams = await this.invoke(new ReqDHParams({
|
|
65
66
|
nonce,
|
|
66
67
|
serverNonce,
|
|
@@ -88,7 +89,7 @@ export class ClientPlain extends ClientAbstract {
|
|
|
88
89
|
serverNonce,
|
|
89
90
|
retryId: 0n,
|
|
90
91
|
gB: bufferFromBigInt(gB, 256, false, false),
|
|
91
|
-
})
|
|
92
|
+
})[serialize]();
|
|
92
93
|
let dataWithHash = concat(await sha1(data), data);
|
|
93
94
|
while (dataWithHash.length % 16 != 0) {
|
|
94
95
|
dataWithHash = concat(dataWithHash, new Uint8Array(1));
|
|
@@ -36,7 +36,9 @@ export class ConnectionWebSocket {
|
|
|
36
36
|
this.webSocket.onmessage = async (e) => {
|
|
37
37
|
// deno-lint-ignore no-explicit-any
|
|
38
38
|
const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
|
|
39
|
-
|
|
39
|
+
for (const byte of data) {
|
|
40
|
+
this.buffer.push(byte);
|
|
41
|
+
}
|
|
40
42
|
if (this.nextResolve != null && this.buffer.length >= this.nextResolve[0]) {
|
|
41
43
|
this.nextResolve[1]();
|
|
42
44
|
this.nextResolve = null;
|
package/{types → esm}/mod.d.ts
RENAMED
|
@@ -4,6 +4,7 @@ export declare const utils: {
|
|
|
4
4
|
checkPassword: typeof checkPassword;
|
|
5
5
|
getRandomId: typeof getRandomId;
|
|
6
6
|
};
|
|
7
|
+
export { as } from "./tl/1_tl_object.js";
|
|
7
8
|
export * as types from "./tl/2_types.js";
|
|
8
9
|
export * as functions from "./tl/3_functions.js";
|
|
9
10
|
export * from "./tl/4_rpc_result.js";
|
package/esm/mod.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { checkPassword } from "./utilities/1_password.js";
|
|
2
2
|
import { getRandomId } from "./utilities/0_bigint.js";
|
|
3
3
|
export const utils = { checkPassword, getRandomId };
|
|
4
|
+
export { as } from "./tl/1_tl_object.js";
|
|
4
5
|
export * as types from "./tl/2_types.js";
|
|
5
6
|
export * as functions from "./tl/3_functions.js";
|
|
6
7
|
export * from "./tl/4_rpc_result.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -16,6 +16,8 @@ export declare const id: unique symbol;
|
|
|
16
16
|
export declare const params: unique symbol;
|
|
17
17
|
export declare const paramDesc: unique symbol;
|
|
18
18
|
export declare const length: unique symbol;
|
|
19
|
+
export declare const serialize: unique symbol;
|
|
20
|
+
export declare const as: unique symbol;
|
|
19
21
|
export declare function isOptionalParam(ntype: string): boolean;
|
|
20
22
|
export declare function analyzeOptionalParam(ntype: string): {
|
|
21
23
|
flagField: string;
|
|
@@ -26,11 +28,12 @@ export declare abstract class TLObject {
|
|
|
26
28
|
protected abstract get [params](): Params;
|
|
27
29
|
protected static get [paramDesc](): ParamDesc;
|
|
28
30
|
get [length](): number;
|
|
29
|
-
serialize(): Uint8Array;
|
|
31
|
+
[serialize](): Uint8Array;
|
|
32
|
+
[as]<T extends TLObjectConstructor<InstanceType<T>>>(constructor: T): InstanceType<T>;
|
|
30
33
|
}
|
|
31
34
|
export type MaybeVectorTLObject = TLObject | Array<MaybeVectorTLObject | TLObject>;
|
|
32
35
|
export interface TLObjectConstructor<T = TLObject> {
|
|
33
|
-
new (params:
|
|
36
|
+
new (params: any): T;
|
|
34
37
|
[paramDesc]: ParamDesc;
|
|
35
38
|
}
|
|
36
39
|
export declare function isTLObjectConstructor(t: unknown): t is typeof TLObject;
|
package/esm/tl/1_tl_object.js
CHANGED
|
@@ -5,6 +5,8 @@ export const id = Symbol("id");
|
|
|
5
5
|
export const params = Symbol("params");
|
|
6
6
|
export const paramDesc = Symbol("paramDesc");
|
|
7
7
|
export const length = Symbol("length");
|
|
8
|
+
export const serialize = Symbol();
|
|
9
|
+
export const as = Symbol();
|
|
8
10
|
export function isOptionalParam(ntype) {
|
|
9
11
|
return ntype.includes("?");
|
|
10
12
|
}
|
|
@@ -22,7 +24,7 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
22
24
|
if (isTLObjectConstructor(type)) {
|
|
23
25
|
if ((type.name == "TypeX" && value instanceof TLObject) ||
|
|
24
26
|
value instanceof type) {
|
|
25
|
-
writer.write(value
|
|
27
|
+
writer.write(value[serialize]());
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
@@ -87,10 +89,7 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
87
89
|
}
|
|
88
90
|
break;
|
|
89
91
|
case "true":
|
|
90
|
-
if (value
|
|
91
|
-
writer.writeInt32(0x997275B5);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
92
|
+
if (value !== true) {
|
|
94
93
|
throw new TypeError("Expected true");
|
|
95
94
|
}
|
|
96
95
|
}
|
|
@@ -101,9 +100,9 @@ export class TLObject {
|
|
|
101
100
|
return [];
|
|
102
101
|
}
|
|
103
102
|
get [length]() {
|
|
104
|
-
return this
|
|
103
|
+
return this[serialize]().byteLength;
|
|
105
104
|
}
|
|
106
|
-
serialize() {
|
|
105
|
+
[serialize]() {
|
|
107
106
|
const writer = new TLRawWriter();
|
|
108
107
|
writer.writeInt32(this[id], false);
|
|
109
108
|
for (const [value, type, ntype] of this[params]) {
|
|
@@ -142,6 +141,14 @@ export class TLObject {
|
|
|
142
141
|
}
|
|
143
142
|
return writer.buffer;
|
|
144
143
|
}
|
|
144
|
+
[as](constructor) {
|
|
145
|
+
if (this instanceof constructor) {
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw new TypeError(`Expected ${constructor.name}, got ${this.constructor.name}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
145
152
|
}
|
|
146
153
|
export function isTLObjectConstructor(t) {
|
|
147
154
|
// deno-lint-ignore no-explicit-any
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/tl/3_tl_reader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TLRawReader } from "./0_tl_raw_reader.js";
|
|
2
2
|
import { paramDesc } from "./1_tl_object.js";
|
|
3
3
|
import { map } from "./2_types.js";
|
|
4
|
-
import { deserialize } from "./
|
|
4
|
+
import { deserialize } from "./3_deserialize.js";
|
|
5
5
|
export class TLReader extends TLRawReader {
|
|
6
6
|
readObject(id) {
|
|
7
7
|
if (!id) {
|
package/esm/tl/3_tl_writer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VECTOR_CONSTRUCTOR } from "../constants.js";
|
|
2
2
|
import { TLRawWriter } from "./0_tl_raw_writer.js";
|
|
3
|
+
import { serialize } from "./1_tl_object.js";
|
|
3
4
|
export class TLWriter extends TLRawWriter {
|
|
4
5
|
writeObject(object) {
|
|
5
6
|
if (Array.isArray(object)) {
|
|
@@ -10,7 +11,7 @@ export class TLWriter extends TLRawWriter {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
else {
|
|
13
|
-
this.write(object
|
|
14
|
+
this.write(object[serialize]());
|
|
14
15
|
}
|
|
15
16
|
return this;
|
|
16
17
|
}
|
package/esm/tl/5_message.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { id } from "./1_tl_object.js";
|
|
1
|
+
import { id, serialize } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
3
|
import { TLWriter } from "./3_tl_writer.js";
|
|
4
4
|
import { RPCResult } from "./4_rpc_result.js";
|
|
@@ -13,7 +13,7 @@ function calculateLength(object) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
length += object
|
|
16
|
+
length += object[serialize]().length;
|
|
17
17
|
}
|
|
18
18
|
return length;
|
|
19
19
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertEquals, ige256Decrypt, ige256Encrypt } from "../deps.js";
|
|
2
2
|
import { TLRawReader } from "../tl/0_tl_raw_reader.js";
|
|
3
3
|
import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
|
|
4
|
-
import { id } from "../tl/1_tl_object.js";
|
|
4
|
+
import { id, serialize } from "../tl/1_tl_object.js";
|
|
5
5
|
import { TLReader } from "../tl/3_tl_reader.js";
|
|
6
6
|
import { RPCResult } from "../tl/4_rpc_result.js";
|
|
7
7
|
import { Message } from "../tl/5_message.js";
|
|
@@ -34,7 +34,7 @@ export function unpackUnencryptedMessage(buffer) {
|
|
|
34
34
|
return { messageId, message };
|
|
35
35
|
}
|
|
36
36
|
export async function encryptMessage(message, authKey, authKeyId, salt, sessionId) {
|
|
37
|
-
const encoded = message.body
|
|
37
|
+
const encoded = message.body[serialize]();
|
|
38
38
|
const payloadWriter = new TLRawWriter();
|
|
39
39
|
payloadWriter.writeInt64(salt);
|
|
40
40
|
payloadWriter.writeInt64(sessionId);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"module": "./esm/mod.js",
|
|
3
3
|
"main": "./script/mod.js",
|
|
4
|
-
"types": "./types/mod.d.ts",
|
|
5
4
|
"name": "@mtkruto/node",
|
|
6
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.821",
|
|
7
6
|
"description": "MTKruto for Node.js",
|
|
8
7
|
"author": "Roj <rojvv@icloud.com>",
|
|
9
8
|
"license": "LGPL-3.0-or-later",
|
|
@@ -13,14 +12,8 @@
|
|
|
13
12
|
},
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"import":
|
|
17
|
-
|
|
18
|
-
"default": "./esm/mod.js"
|
|
19
|
-
},
|
|
20
|
-
"require": {
|
|
21
|
-
"types": "./types/mod.d.ts",
|
|
22
|
-
"default": "./script/mod.js"
|
|
23
|
-
}
|
|
15
|
+
"import": "./esm/mod.js",
|
|
16
|
+
"require": "./script/mod.js"
|
|
24
17
|
}
|
|
25
18
|
},
|
|
26
19
|
"scripts": {
|
|
@@ -28,13 +21,13 @@
|
|
|
28
21
|
},
|
|
29
22
|
"dependencies": {
|
|
30
23
|
"async-mutex": "0.4.0",
|
|
31
|
-
"@deno/shim-deno": "~0.
|
|
24
|
+
"@deno/shim-deno": "~0.16.1",
|
|
32
25
|
"@deno/shim-crypto": "~0.3.1",
|
|
33
26
|
"ws": "^8.13.0"
|
|
34
27
|
},
|
|
35
28
|
"devDependencies": {
|
|
36
29
|
"@types/node": "^18.11.9",
|
|
37
|
-
"
|
|
30
|
+
"picocolors": "^1.0.0",
|
|
38
31
|
"@types/ws": "^8.5.4"
|
|
39
32
|
}
|
|
40
33
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { default as WebSocket } from "ws";
|
|
5
|
+
export { default as WebSocket } from "ws";
|
|
6
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "WebSocket" | "crypto" | "Deno"> & {
|
|
7
|
+
Deno: typeof Deno;
|
|
8
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
9
|
+
WebSocket: typeof WebSocket;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { default as WebSocket } from "ws";
|
|
5
|
+
export { default as WebSocket } from "ws";
|
|
6
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "WebSocket" | "crypto" | "Deno"> & {
|
|
7
|
+
Deno: typeof Deno;
|
|
8
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
9
|
+
WebSocket: typeof WebSocket;
|
|
10
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { MaybePromise } from "../types.js";
|
|
2
|
+
import * as types from "../tl/2_types.js";
|
|
3
|
+
import * as functions from "../tl/3_functions.js";
|
|
4
|
+
import { ClientAbstract } from "./client_abstract.js";
|
|
5
|
+
import { Session } from "../session/session.js";
|
|
6
|
+
import { DC, TransportProvider } from "../transport/transport_provider.js";
|
|
7
|
+
export interface AuthorizeUserParams<S = string, N = {
|
|
8
|
+
first: S;
|
|
9
|
+
last: S;
|
|
10
|
+
}> {
|
|
11
|
+
phone: S | (() => MaybePromise<S>);
|
|
12
|
+
code: S | (() => MaybePromise<S>);
|
|
13
|
+
password: S | (() => MaybePromise<S>);
|
|
14
|
+
names: N | (() => MaybePromise<N>);
|
|
15
|
+
}
|
|
16
|
+
export type UpdatesHandler = null | ((client: Client, update: types.Updates) => MaybePromise<void>);
|
|
17
|
+
export declare class Client extends ClientAbstract {
|
|
18
|
+
readonly session: Session;
|
|
19
|
+
readonly apiId: number;
|
|
20
|
+
readonly apiHash: string;
|
|
21
|
+
private sessionId;
|
|
22
|
+
private state;
|
|
23
|
+
private promises;
|
|
24
|
+
private toAcknowledge;
|
|
25
|
+
updatesHandler: UpdatesHandler;
|
|
26
|
+
readonly appVersion: string;
|
|
27
|
+
readonly deviceModel: string;
|
|
28
|
+
readonly langCode: string;
|
|
29
|
+
readonly langPack: string;
|
|
30
|
+
readonly systemLangCode: string;
|
|
31
|
+
readonly systemVersion: string;
|
|
32
|
+
constructor(session?: Session, apiId?: number, apiHash?: string, params?: {
|
|
33
|
+
transportProvider?: TransportProvider;
|
|
34
|
+
appVersion?: string;
|
|
35
|
+
deviceModel?: string;
|
|
36
|
+
langCode?: string;
|
|
37
|
+
langPack?: string;
|
|
38
|
+
systemLangCode?: string;
|
|
39
|
+
systemVersion?: string;
|
|
40
|
+
});
|
|
41
|
+
private shouldLoadSession;
|
|
42
|
+
setDc(dc: DC): void;
|
|
43
|
+
connect(): Promise<void>;
|
|
44
|
+
authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
45
|
+
private receiveLoop;
|
|
46
|
+
private pingLoop;
|
|
47
|
+
invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
|
|
48
|
+
invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>;
|
|
49
|
+
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Connection } from "../connection/connection.js";
|
|
2
|
+
import { Transport } from "../transport/transport.js";
|
|
3
|
+
import { DC } from "../transport/transport_provider.js";
|
|
4
|
+
export declare abstract class ClientAbstract {
|
|
5
|
+
protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
|
|
6
|
+
protected connection: Connection;
|
|
7
|
+
protected transport: Transport;
|
|
8
|
+
private _dcId;
|
|
9
|
+
protected connected: boolean;
|
|
10
|
+
constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
|
|
11
|
+
get dcId(): number;
|
|
12
|
+
setDc(dc: DC): void;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
reconnect(dc?: DC): Promise<void>;
|
|
15
|
+
disconnect(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Function } from "../tl/3_functions.js";
|
|
2
|
+
import { ClientAbstract } from "./client_abstract.js";
|
|
3
|
+
export declare class ClientPlain extends ClientAbstract {
|
|
4
|
+
invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
|
|
5
|
+
createAuthKey(): Promise<{
|
|
6
|
+
authKey: Uint8Array;
|
|
7
|
+
salt: bigint;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
@@ -7,6 +7,7 @@ const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
|
7
7
|
const _0_buffer_js_1 = require("../utilities/0_buffer.js");
|
|
8
8
|
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
9
9
|
const _1_auth_js_1 = require("../utilities/1_auth.js");
|
|
10
|
+
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
10
11
|
const _1_message_js_1 = require("../utilities/1_message.js");
|
|
11
12
|
const _2_types_js_1 = require("../tl/2_types.js");
|
|
12
13
|
const _3_functions_js_1 = require("../tl/3_functions.js");
|
|
@@ -14,7 +15,7 @@ const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
|
14
15
|
const client_abstract_js_1 = require("./client_abstract.js");
|
|
15
16
|
class ClientPlain extends client_abstract_js_1.ClientAbstract {
|
|
16
17
|
async invoke(function_) {
|
|
17
|
-
await this.transport.send((0, _1_message_js_1.packUnencryptedMessage)(function_.serialize()));
|
|
18
|
+
await this.transport.send((0, _1_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize]()));
|
|
18
19
|
const buffer = await this.transport.receive();
|
|
19
20
|
if (buffer.length == 4) {
|
|
20
21
|
const int = (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, true);
|
|
@@ -63,7 +64,7 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
|
|
|
63
64
|
newNonce,
|
|
64
65
|
nonce,
|
|
65
66
|
serverNonce,
|
|
66
|
-
}).serialize(), publicKey);
|
|
67
|
+
})[_1_tl_object_js_1.serialize](), publicKey);
|
|
67
68
|
const dhParams = await this.invoke(new _3_functions_js_1.ReqDHParams({
|
|
68
69
|
nonce,
|
|
69
70
|
serverNonce,
|
|
@@ -91,7 +92,7 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
|
|
|
91
92
|
serverNonce,
|
|
92
93
|
retryId: 0n,
|
|
93
94
|
gB: (0, _0_buffer_js_1.bufferFromBigInt)(gB, 256, false, false),
|
|
94
|
-
}).serialize();
|
|
95
|
+
})[_1_tl_object_js_1.serialize]();
|
|
95
96
|
let dataWithHash = (0, _0_buffer_js_1.concat)(await (0, _0_hash_js_1.sha1)(data), data);
|
|
96
97
|
while (dataWithHash.length % 16 != 0) {
|
|
97
98
|
dataWithHash = (0, _0_buffer_js_1.concat)(dataWithHash, new Uint8Array(1));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MaybePromise } from "../types.js";
|
|
2
|
+
export declare abstract class Connection {
|
|
3
|
+
abstract open(): MaybePromise<void>;
|
|
4
|
+
abstract read(p: Uint8Array): MaybePromise<void>;
|
|
5
|
+
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
6
|
+
abstract close(): MaybePromise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Connection } from "./connection.js";
|
|
2
|
+
export declare class ConnectionWebSocket implements Connection {
|
|
3
|
+
private webSocket;
|
|
4
|
+
private rMutex;
|
|
5
|
+
private wMutex;
|
|
6
|
+
private buffer;
|
|
7
|
+
private nextResolve;
|
|
8
|
+
constructor(url: string | URL);
|
|
9
|
+
open(): Promise<void>;
|
|
10
|
+
read(p: Uint8Array): Promise<void>;
|
|
11
|
+
write(p: Uint8Array): Promise<void>;
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
|
@@ -62,7 +62,9 @@ class ConnectionWebSocket {
|
|
|
62
62
|
this.webSocket.onmessage = async (e) => {
|
|
63
63
|
// deno-lint-ignore no-explicit-any
|
|
64
64
|
const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
|
|
65
|
-
|
|
65
|
+
for (const byte of data) {
|
|
66
|
+
this.buffer.push(byte);
|
|
67
|
+
}
|
|
66
68
|
if (this.nextResolve != null && this.buffer.length >= this.nextResolve[0]) {
|
|
67
69
|
this.nextResolve[1]();
|
|
68
70
|
this.nextResolve = null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DC } from "./transport/transport_provider.js";
|
|
2
|
+
export declare const ackThreshold = 10;
|
|
3
|
+
export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
4
|
+
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
|
+
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
|
+
export declare const LAYER = 158;
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto Unstable <v1.0.0";
|
|
8
|
+
export declare const DEFAULT_DEVICE_MODEL = "Krutaya Device";
|
|
9
|
+
export declare const DEFAULT_LANG_CODE = "en";
|
|
10
|
+
export declare const DEFAULT_LANG_PACK = "";
|
|
11
|
+
export declare const DEFAULT_SYSTEM_LANG_CODE = "en";
|
|
12
|
+
export declare const DEFAULT_SYSTEM_VERSION = "1.0";
|