@mtkruto/node 0.0.965 → 0.0.967

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.
@@ -1,7 +1,7 @@
1
1
  import { Message } from "../tl/6_message.js";
2
2
  import { MessageContainer } from "../tl/7_message_container.js";
3
- export declare function getMessageId(): bigint;
4
- export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
3
+ export declare function getMessageId(lastMsgId: bigint): bigint;
4
+ export declare function packUnencryptedMessage(data: Uint8Array, messageId: bigint): Uint8Array;
5
5
  export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
6
6
  messageId: bigint;
7
7
  message: Uint8Array;
@@ -8,8 +8,7 @@ import { Message } from "../tl/6_message.js";
8
8
  import { MessageContainer } from "../tl/7_message_container.js";
9
9
  import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
10
10
  import { sha256 } from "../utilities/0_hash.js";
11
- let lastMsgId = 0n;
12
- export function getMessageId() {
11
+ export function getMessageId(lastMsgId) {
13
12
  const now = new Date().getTime() / 1000 + 0;
14
13
  const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
15
14
  let newMsgId = (BigInt(Math.floor(now)) <<
@@ -18,11 +17,10 @@ export function getMessageId() {
18
17
  if (lastMsgId >= (newMsgId)) {
19
18
  newMsgId = lastMsgId + 4n;
20
19
  }
21
- lastMsgId = newMsgId;
22
20
  return newMsgId;
23
21
  }
24
- export function packUnencryptedMessage(data) {
25
- const message = concat(bufferFromBigInt(0x00, 8), bufferFromBigInt(getMessageId(), 8), bufferFromBigInt(data.length, 4), data);
22
+ export function packUnencryptedMessage(data, messageId) {
23
+ const message = concat(bufferFromBigInt(0x00, 8), bufferFromBigInt(messageId, 8), bufferFromBigInt(data.length, 4), data);
26
24
  return message;
27
25
  }
28
26
  export function unpackUnencryptedMessage(buffer) {
@@ -1,6 +1,7 @@
1
1
  import { Function } from "../tl/3_functions.js";
2
2
  import { ClientAbstract } from "./1_client_abstract.js";
3
3
  export declare class ClientPlain extends ClientAbstract {
4
+ private lastMsgId;
4
5
  invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
5
6
  createAuthKey(): Promise<{
6
7
  authKey: Uint8Array;
@@ -10,11 +10,21 @@ import { ClientDHInnerData, DHGenOK, PQInnerDataDC, ResPQ, ServerDHInnerData, Se
10
10
  import { ReqDHParams, ReqPQMulti, SetClientDHParams } from "../tl/3_functions.js";
11
11
  import { TLReader } from "../tl/3_tl_reader.js";
12
12
  import { ClientAbstract } from "./1_client_abstract.js";
13
- import { packUnencryptedMessage, unpackUnencryptedMessage } from "./0_message.js";
13
+ import { getMessageId, packUnencryptedMessage, unpackUnencryptedMessage } from "./0_message.js";
14
14
  const d = debug("ClientPlain/createAuthKey");
15
15
  export class ClientPlain extends ClientAbstract {
16
+ constructor() {
17
+ super(...arguments);
18
+ Object.defineProperty(this, "lastMsgId", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: 0n
23
+ });
24
+ }
16
25
  async invoke(function_) {
17
- await this.transport.send(packUnencryptedMessage(function_[serialize]()));
26
+ const msgId = this.lastMsgId = getMessageId(this.lastMsgId);
27
+ await this.transport.send(packUnencryptedMessage(function_[serialize](), msgId));
18
28
  const buffer = await this.transport.receive();
19
29
  if (buffer.length == 4) {
20
30
  const int = bigIntFromBuffer(buffer, true, true);
@@ -131,6 +131,7 @@ export declare class Client extends ClientAbstract {
131
131
  authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
132
132
  private receiveLoop;
133
133
  private pingLoop;
134
+ private lastMsgId;
134
135
  /**
135
136
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
136
137
  * to be connected.
@@ -159,6 +159,12 @@ export class Client extends ClientAbstract {
159
159
  writable: true,
160
160
  value: false
161
161
  });
162
+ Object.defineProperty(this, "lastMsgId", {
163
+ enumerable: true,
164
+ configurable: true,
165
+ writable: true,
166
+ value: 0n
167
+ });
162
168
  Object.defineProperty(this, "updateApplicationMutex", {
163
169
  enumerable: true,
164
170
  configurable: true,
@@ -558,7 +564,8 @@ export class Client extends ClientAbstract {
558
564
  seqNo++;
559
565
  this.state.seqNo++;
560
566
  }
561
- const message = new Message_(getMessageId(), seqNo, function_);
567
+ const messageId = this.lastMsgId = getMessageId(this.lastMsgId);
568
+ const message = new Message_(messageId, seqNo, function_);
562
569
  await this.transport.send(await encryptMessage(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
563
570
  const d_ = () => d("invoked %s", function_.constructor.name);
564
571
  if (noWait) {
@@ -61,7 +61,7 @@ export class ConnectionWebSocket {
61
61
  return;
62
62
  }
63
63
  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());
64
+ 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
65
  for (const byte of data) {
66
66
  this.buffer.push(byte);
67
67
  }
@@ -140,6 +140,5 @@ export class ConnectionWebSocket {
140
140
  throw new Error("Connection not open");
141
141
  }
142
142
  this.webSocket.close(1000, "method");
143
- console.trace("close called");
144
143
  }
145
144
  }
@@ -4,7 +4,7 @@ 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 0.0.965";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.967";
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
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.965";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.967";
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];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.965",
5
+ "version": "0.0.967",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1,7 +1,7 @@
1
1
  import { Message } from "../tl/6_message.js";
2
2
  import { MessageContainer } from "../tl/7_message_container.js";
3
- export declare function getMessageId(): bigint;
4
- export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
3
+ export declare function getMessageId(lastMsgId: bigint): bigint;
4
+ export declare function packUnencryptedMessage(data: Uint8Array, messageId: bigint): Uint8Array;
5
5
  export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
6
6
  messageId: bigint;
7
7
  message: Uint8Array;
@@ -11,8 +11,7 @@ const _6_message_js_1 = require("../tl/6_message.js");
11
11
  const _7_message_container_js_1 = require("../tl/7_message_container.js");
12
12
  const _0_buffer_js_1 = require("../utilities/0_buffer.js");
13
13
  const _0_hash_js_1 = require("../utilities/0_hash.js");
14
- let lastMsgId = 0n;
15
- function getMessageId() {
14
+ function getMessageId(lastMsgId) {
16
15
  const now = new Date().getTime() / 1000 + 0;
17
16
  const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
18
17
  let newMsgId = (BigInt(Math.floor(now)) <<
@@ -21,12 +20,11 @@ function getMessageId() {
21
20
  if (lastMsgId >= (newMsgId)) {
22
21
  newMsgId = lastMsgId + 4n;
23
22
  }
24
- lastMsgId = newMsgId;
25
23
  return newMsgId;
26
24
  }
27
25
  exports.getMessageId = getMessageId;
28
- function packUnencryptedMessage(data) {
29
- const message = (0, _0_buffer_js_1.concat)((0, _0_buffer_js_1.bufferFromBigInt)(0x00, 8), (0, _0_buffer_js_1.bufferFromBigInt)(getMessageId(), 8), (0, _0_buffer_js_1.bufferFromBigInt)(data.length, 4), data);
26
+ function packUnencryptedMessage(data, messageId) {
27
+ const message = (0, _0_buffer_js_1.concat)((0, _0_buffer_js_1.bufferFromBigInt)(0x00, 8), (0, _0_buffer_js_1.bufferFromBigInt)(messageId, 8), (0, _0_buffer_js_1.bufferFromBigInt)(data.length, 4), data);
30
28
  return message;
31
29
  }
32
30
  exports.packUnencryptedMessage = packUnencryptedMessage;
@@ -1,6 +1,7 @@
1
1
  import { Function } from "../tl/3_functions.js";
2
2
  import { ClientAbstract } from "./1_client_abstract.js";
3
3
  export declare class ClientPlain extends ClientAbstract {
4
+ private lastMsgId;
4
5
  invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
5
6
  createAuthKey(): Promise<{
6
7
  authKey: Uint8Array;
@@ -16,8 +16,18 @@ 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(...arguments);
21
+ Object.defineProperty(this, "lastMsgId", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: 0n
26
+ });
27
+ }
19
28
  async invoke(function_) {
20
- await this.transport.send((0, _0_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize]()));
29
+ const msgId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
30
+ await this.transport.send((0, _0_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize](), msgId));
21
31
  const buffer = await this.transport.receive();
22
32
  if (buffer.length == 4) {
23
33
  const int = (0, _0_bigint_js_1.bigIntFromBuffer)(buffer, true, true);
@@ -131,6 +131,7 @@ export declare class Client extends ClientAbstract {
131
131
  authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
132
132
  private receiveLoop;
133
133
  private pingLoop;
134
+ private lastMsgId;
134
135
  /**
135
136
  * Invokes a function waiting and returning its reply if the second parameter is not `true`. Requires the client
136
137
  * to be connected.
@@ -185,6 +185,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
185
185
  writable: true,
186
186
  value: false
187
187
  });
188
+ Object.defineProperty(this, "lastMsgId", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: 0n
193
+ });
188
194
  Object.defineProperty(this, "updateApplicationMutex", {
189
195
  enumerable: true,
190
196
  configurable: true,
@@ -584,7 +590,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
584
590
  seqNo++;
585
591
  this.state.seqNo++;
586
592
  }
587
- const message = new _6_message_js_1.Message((0, _0_message_js_1.getMessageId)(), seqNo, function_);
593
+ const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
594
+ const message = new _6_message_js_1.Message(messageId, seqNo, function_);
588
595
  await this.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
589
596
  const d_ = () => d("invoked %s", function_.constructor.name);
590
597
  if (noWait) {
@@ -87,7 +87,7 @@ class ConnectionWebSocket {
87
87
  return;
88
88
  }
89
89
  const release = await mutex.acquire();
90
- 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());
90
+ 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());
91
91
  for (const byte of data) {
92
92
  this.buffer.push(byte);
93
93
  }
@@ -166,7 +166,6 @@ class ConnectionWebSocket {
166
166
  throw new Error("Connection not open");
167
167
  }
168
168
  this.webSocket.close(1000, "method");
169
- console.trace("close called");
170
169
  }
171
170
  }
172
171
  exports.ConnectionWebSocket = ConnectionWebSocket;
@@ -4,7 +4,7 @@ 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 0.0.965";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.967";
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 = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.965";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.967";
92
92
  // @ts-ignore: lib
93
93
  exports.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;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];