@mtkruto/node 0.0.75 → 0.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/client.js +8 -0
- package/esm/constants.js +1 -0
- package/esm/tl/3_tl_reader.js +8 -0
- package/esm/tl/3_tl_writer.js +11 -1
- package/esm/tl/5_message.js +17 -2
- package/package.json +1 -1
- package/script/client/client.js +8 -0
- package/script/constants.js +2 -1
- package/script/tl/3_tl_reader.js +8 -0
- package/script/tl/3_tl_writer.js +11 -1
- package/script/tl/5_message.js +16 -1
- package/types/constants.d.ts +1 -0
- package/types/tl/1_tl_object.d.ts +1 -0
- package/types/tl/3_tl_reader.d.ts +3 -1
- package/types/tl/3_tl_writer.d.ts +2 -2
- package/types/tl/4_rpc_result.d.ts +3 -3
- package/types/tl/5_message.d.ts +3 -3
package/esm/client/client.js
CHANGED
|
@@ -86,8 +86,10 @@ export class Client extends ClientAbstract {
|
|
|
86
86
|
let decrypted;
|
|
87
87
|
try {
|
|
88
88
|
decrypted = await decryptMessage(buffer, this.session.authKey, this.sessionId);
|
|
89
|
+
console.log({ decrypted });
|
|
89
90
|
}
|
|
90
91
|
catch (_err) {
|
|
92
|
+
console.log("failed to decrypt msg", { _err });
|
|
91
93
|
// logger().error(`Failed to decrypt message: ${err}`);
|
|
92
94
|
continue;
|
|
93
95
|
}
|
|
@@ -97,6 +99,10 @@ export class Client extends ClientAbstract {
|
|
|
97
99
|
if (body instanceof types.GZIPPacked) {
|
|
98
100
|
body = new TLReader(gunzip(body.packedData)).readObject();
|
|
99
101
|
}
|
|
102
|
+
console.log("---");
|
|
103
|
+
console.log("message.body", message.body.constructor.name);
|
|
104
|
+
console.log("body", body.constructor.name);
|
|
105
|
+
console.log("---");
|
|
100
106
|
// logger().debug(`Received ${body.constructor.name}`);
|
|
101
107
|
if (body instanceof types.Updates) {
|
|
102
108
|
this.updatesHandler?.(this, body);
|
|
@@ -106,6 +112,7 @@ export class Client extends ClientAbstract {
|
|
|
106
112
|
if (result instanceof types.GZIPPacked) {
|
|
107
113
|
result = new TLReader(gunzip(result.packedData)).readObject();
|
|
108
114
|
}
|
|
115
|
+
// console.log(result.constructor.name)
|
|
109
116
|
const promise = this.promises.get(message.body.messageId);
|
|
110
117
|
if (promise) {
|
|
111
118
|
if (result instanceof types.RPCError) {
|
|
@@ -153,6 +160,7 @@ export class Client extends ClientAbstract {
|
|
|
153
160
|
if (!this.session.authKey) {
|
|
154
161
|
throw new Error("Not connected");
|
|
155
162
|
}
|
|
163
|
+
console.log("invoking", function_.constructor.name);
|
|
156
164
|
let seqNo = this.state.seqNo * 2;
|
|
157
165
|
if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
|
|
158
166
|
seqNo++;
|
package/esm/constants.js
CHANGED
package/esm/tl/3_tl_reader.js
CHANGED
|
@@ -7,6 +7,14 @@ export class TLReader extends TLRawReader {
|
|
|
7
7
|
if (!id) {
|
|
8
8
|
id = this.readInt32(false);
|
|
9
9
|
}
|
|
10
|
+
if (id == 0x1CB5C415) {
|
|
11
|
+
const count = this.readInt32();
|
|
12
|
+
const items = new Array();
|
|
13
|
+
for (let i = 0; i < count; i++) {
|
|
14
|
+
items.push(this.readObject());
|
|
15
|
+
}
|
|
16
|
+
return items;
|
|
17
|
+
}
|
|
10
18
|
const constructor = map.get(id);
|
|
11
19
|
if (constructor) {
|
|
12
20
|
return deserialize(this, constructor[paramDesc], constructor);
|
package/esm/tl/3_tl_writer.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { VECTOR_CONSTRUCTOR } from "../constants.js";
|
|
1
2
|
import { TLRawWriter } from "./0_tl_raw_writer.js";
|
|
2
3
|
export class TLWriter extends TLRawWriter {
|
|
3
4
|
writeObject(object) {
|
|
4
|
-
|
|
5
|
+
if (Array.isArray(object)) {
|
|
6
|
+
this.writeInt32(VECTOR_CONSTRUCTOR, false);
|
|
7
|
+
this.writeInt32(object.length);
|
|
8
|
+
for (const item of object) {
|
|
9
|
+
this.writeObject(item);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.write(object.serialize());
|
|
14
|
+
}
|
|
5
15
|
return this;
|
|
6
16
|
}
|
|
7
17
|
}
|
package/esm/tl/5_message.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { id
|
|
1
|
+
import { id } 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";
|
|
5
|
+
// TODO: test
|
|
6
|
+
function calculateLength(object) {
|
|
7
|
+
let length = 0;
|
|
8
|
+
if (Array.isArray(object)) {
|
|
9
|
+
length += 32 / 8; // vector constructor
|
|
10
|
+
length += 32 / 8; // number of items
|
|
11
|
+
for (const item of object) {
|
|
12
|
+
length += calculateLength(item);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
length += object.serialize().length;
|
|
17
|
+
}
|
|
18
|
+
return length;
|
|
19
|
+
}
|
|
5
20
|
export class Message {
|
|
6
21
|
constructor(id, seqNo, body) {
|
|
7
22
|
Object.defineProperty(this, "id", {
|
|
@@ -30,7 +45,7 @@ export class Message {
|
|
|
30
45
|
return new TLWriter()
|
|
31
46
|
.writeInt64(this.id)
|
|
32
47
|
.writeInt32(this.seqNo)
|
|
33
|
-
.writeInt32(this.body
|
|
48
|
+
.writeInt32(calculateLength(this.body))
|
|
34
49
|
.writeObject(this.body)
|
|
35
50
|
.buffer;
|
|
36
51
|
}
|
package/package.json
CHANGED
package/script/client/client.js
CHANGED
|
@@ -112,8 +112,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
112
112
|
let decrypted;
|
|
113
113
|
try {
|
|
114
114
|
decrypted = await (0, _1_message_js_1.decryptMessage)(buffer, this.session.authKey, this.sessionId);
|
|
115
|
+
console.log({ decrypted });
|
|
115
116
|
}
|
|
116
117
|
catch (_err) {
|
|
118
|
+
console.log("failed to decrypt msg", { _err });
|
|
117
119
|
// logger().error(`Failed to decrypt message: ${err}`);
|
|
118
120
|
continue;
|
|
119
121
|
}
|
|
@@ -123,6 +125,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
123
125
|
if (body instanceof types.GZIPPacked) {
|
|
124
126
|
body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
|
|
125
127
|
}
|
|
128
|
+
console.log("---");
|
|
129
|
+
console.log("message.body", message.body.constructor.name);
|
|
130
|
+
console.log("body", body.constructor.name);
|
|
131
|
+
console.log("---");
|
|
126
132
|
// logger().debug(`Received ${body.constructor.name}`);
|
|
127
133
|
if (body instanceof types.Updates) {
|
|
128
134
|
this.updatesHandler?.(this, body);
|
|
@@ -132,6 +138,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
132
138
|
if (result instanceof types.GZIPPacked) {
|
|
133
139
|
result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
|
|
134
140
|
}
|
|
141
|
+
// console.log(result.constructor.name)
|
|
135
142
|
const promise = this.promises.get(message.body.messageId);
|
|
136
143
|
if (promise) {
|
|
137
144
|
if (result instanceof types.RPCError) {
|
|
@@ -179,6 +186,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
|
|
|
179
186
|
if (!this.session.authKey) {
|
|
180
187
|
throw new Error("Not connected");
|
|
181
188
|
}
|
|
189
|
+
console.log("invoking", function_.constructor.name);
|
|
182
190
|
let seqNo = this.state.seqNo * 2;
|
|
183
191
|
if (!(function_ instanceof functions.Ping) && !(function_ instanceof types.MsgsAck)) {
|
|
184
192
|
seqNo++;
|
package/script/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publicKeys = exports.ackThreshold = void 0;
|
|
3
|
+
exports.VECTOR_CONSTRUCTOR = exports.publicKeys = exports.ackThreshold = void 0;
|
|
4
4
|
exports.ackThreshold = 10;
|
|
5
5
|
exports.publicKeys = new Map([
|
|
6
6
|
[
|
|
@@ -61,3 +61,4 @@ exports.publicKeys = new Map([
|
|
|
61
61
|
],
|
|
62
62
|
],
|
|
63
63
|
]);
|
|
64
|
+
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
package/script/tl/3_tl_reader.js
CHANGED
|
@@ -10,6 +10,14 @@ class TLReader extends _0_tl_raw_reader_js_1.TLRawReader {
|
|
|
10
10
|
if (!id) {
|
|
11
11
|
id = this.readInt32(false);
|
|
12
12
|
}
|
|
13
|
+
if (id == 0x1CB5C415) {
|
|
14
|
+
const count = this.readInt32();
|
|
15
|
+
const items = new Array();
|
|
16
|
+
for (let i = 0; i < count; i++) {
|
|
17
|
+
items.push(this.readObject());
|
|
18
|
+
}
|
|
19
|
+
return items;
|
|
20
|
+
}
|
|
13
21
|
const constructor = _2_types_js_1.map.get(id);
|
|
14
22
|
if (constructor) {
|
|
15
23
|
return (0, _3_tl_object_deserializer_js_1.deserialize)(this, constructor[_1_tl_object_js_1.paramDesc], constructor);
|
package/script/tl/3_tl_writer.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TLWriter = void 0;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
4
5
|
const _0_tl_raw_writer_js_1 = require("./0_tl_raw_writer.js");
|
|
5
6
|
class TLWriter extends _0_tl_raw_writer_js_1.TLRawWriter {
|
|
6
7
|
writeObject(object) {
|
|
7
|
-
|
|
8
|
+
if (Array.isArray(object)) {
|
|
9
|
+
this.writeInt32(constants_js_1.VECTOR_CONSTRUCTOR, false);
|
|
10
|
+
this.writeInt32(object.length);
|
|
11
|
+
for (const item of object) {
|
|
12
|
+
this.writeObject(item);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.write(object.serialize());
|
|
17
|
+
}
|
|
8
18
|
return this;
|
|
9
19
|
}
|
|
10
20
|
}
|
package/script/tl/5_message.js
CHANGED
|
@@ -5,6 +5,21 @@ const _1_tl_object_js_1 = require("./1_tl_object.js");
|
|
|
5
5
|
const _3_tl_reader_js_1 = require("./3_tl_reader.js");
|
|
6
6
|
const _3_tl_writer_js_1 = require("./3_tl_writer.js");
|
|
7
7
|
const _4_rpc_result_js_1 = require("./4_rpc_result.js");
|
|
8
|
+
// TODO: test
|
|
9
|
+
function calculateLength(object) {
|
|
10
|
+
let length = 0;
|
|
11
|
+
if (Array.isArray(object)) {
|
|
12
|
+
length += 32 / 8; // vector constructor
|
|
13
|
+
length += 32 / 8; // number of items
|
|
14
|
+
for (const item of object) {
|
|
15
|
+
length += calculateLength(item);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
length += object.serialize().length;
|
|
20
|
+
}
|
|
21
|
+
return length;
|
|
22
|
+
}
|
|
8
23
|
class Message {
|
|
9
24
|
constructor(id, seqNo, body) {
|
|
10
25
|
Object.defineProperty(this, "id", {
|
|
@@ -33,7 +48,7 @@ class Message {
|
|
|
33
48
|
return new _3_tl_writer_js_1.TLWriter()
|
|
34
49
|
.writeInt64(this.id)
|
|
35
50
|
.writeInt32(this.seqNo)
|
|
36
|
-
.writeInt32(this.body
|
|
51
|
+
.writeInt32(calculateLength(this.body))
|
|
37
52
|
.writeObject(this.body)
|
|
38
53
|
.buffer;
|
|
39
54
|
}
|
package/types/constants.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare abstract class TLObject {
|
|
|
28
28
|
get [length](): number;
|
|
29
29
|
serialize(): Uint8Array;
|
|
30
30
|
}
|
|
31
|
+
export type MaybeVectorTLObject = TLObject | Array<MaybeVectorTLObject | TLObject>;
|
|
31
32
|
export interface TLObjectConstructor<T = TLObject> {
|
|
32
33
|
new (params: Record<string, Param>): T;
|
|
33
34
|
[paramDesc]: ParamDesc;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TLRawReader } from "./0_tl_raw_reader.js";
|
|
2
|
+
import { TLObject } from "./1_tl_object.js";
|
|
3
|
+
export type ReadObject = TLObject | Array<ReadObject | TLObject>;
|
|
2
4
|
export declare class TLReader extends TLRawReader {
|
|
3
|
-
readObject(id?: number):
|
|
5
|
+
readObject(id?: number): ReadObject;
|
|
4
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TLRawWriter } from "./0_tl_raw_writer.js";
|
|
2
|
-
import {
|
|
2
|
+
import { MaybeVectorTLObject } from "./1_tl_object.js";
|
|
3
3
|
export declare class TLWriter extends TLRawWriter {
|
|
4
|
-
writeObject(object:
|
|
4
|
+
writeObject(object: MaybeVectorTLObject): this;
|
|
5
5
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { id,
|
|
1
|
+
import { id, MaybeVectorTLObject } from "./1_tl_object.js";
|
|
2
2
|
export declare class RPCResult {
|
|
3
3
|
readonly messageId: bigint;
|
|
4
|
-
readonly result:
|
|
4
|
+
readonly result: MaybeVectorTLObject;
|
|
5
5
|
static get [id](): number;
|
|
6
|
-
constructor(messageId: bigint, result:
|
|
6
|
+
constructor(messageId: bigint, result: MaybeVectorTLObject);
|
|
7
7
|
static deserialize(buffer: Uint8Array): RPCResult;
|
|
8
8
|
}
|
package/types/tl/5_message.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeVectorTLObject } from "./1_tl_object.js";
|
|
2
2
|
import { TLReader } from "./3_tl_reader.js";
|
|
3
3
|
import { RPCResult } from "./4_rpc_result.js";
|
|
4
4
|
export declare class Message {
|
|
5
5
|
readonly id: bigint;
|
|
6
6
|
readonly seqNo: number;
|
|
7
|
-
readonly body:
|
|
8
|
-
constructor(id: bigint, seqNo: number, body:
|
|
7
|
+
readonly body: MaybeVectorTLObject | RPCResult;
|
|
8
|
+
constructor(id: bigint, seqNo: number, body: MaybeVectorTLObject | RPCResult);
|
|
9
9
|
serialize(): Uint8Array;
|
|
10
10
|
static deserialize(reader: TLReader): Message;
|
|
11
11
|
}
|