@mtkruto/node 0.0.968 → 0.0.970

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,11 +1,11 @@
1
1
  import { initTgCrypto } from "../deps.js";
2
- import { DEFAULT_INITIAL_DC } from "../constants.js";
2
+ import { INITIAL_DC } from "../constants.js";
3
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 = webSocketTransportProvider({ initialDc: DEFAULT_INITIAL_DC }), cdn = false) {
8
+ constructor(transportProvider = webSocketTransportProvider({ initialDc: INITIAL_DC }), cdn = false) {
9
9
  Object.defineProperty(this, "transportProvider", {
10
10
  enumerable: true,
11
11
  configurable: true,
@@ -1,7 +1,10 @@
1
1
  import { Function } from "../tl/3_functions.js";
2
+ import { TransportProvider } from "../transport/2_transport_provider.js";
2
3
  import { ClientAbstract } from "./1_client_abstract.js";
3
4
  export declare class ClientPlain extends ClientAbstract {
5
+ private readonly publicKeys;
4
6
  private lastMsgId;
7
+ constructor(transportProvider: TransportProvider, publicKeys?: import("../constants.js").PublicKeys);
5
8
  invoke<T extends Function<unknown>>(function_: T): Promise<T["__R"]>;
6
9
  createAuthKey(): Promise<{
7
10
  authKey: Uint8Array;
@@ -1,5 +1,5 @@
1
1
  import { assertEquals, assertInstanceOf, debug, factorize, ige256Decrypt, ige256Encrypt } from "../deps.js";
2
- import { publicKeys } from "../constants.js";
2
+ import { PUBLIC_KEYS } 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
5
  import { UNREACHABLE } from "../utilities/0_control.js";
@@ -13,8 +13,14 @@ import { ClientAbstract } from "./1_client_abstract.js";
13
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);
16
+ constructor(transportProvider, publicKeys = PUBLIC_KEYS) {
17
+ super(transportProvider);
18
+ Object.defineProperty(this, "publicKeys", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: publicKeys
23
+ });
18
24
  Object.defineProperty(this, "lastMsgId", {
19
25
  enumerable: true,
20
26
  configurable: true,
@@ -64,10 +70,10 @@ export class ClientPlain extends ClientAbstract {
64
70
  let publicKeyFingerprint;
65
71
  let publicKey;
66
72
  for (const fingerprint of resPq.serverPublicKeyFingerprints) {
67
- const maybePublicKey = publicKeys.get(fingerprint);
73
+ const maybePublicKey = this.publicKeys.find(([k]) => (k == fingerprint));
68
74
  if (maybePublicKey) {
69
75
  publicKeyFingerprint = fingerprint;
70
- publicKey = maybePublicKey;
76
+ publicKey = maybePublicKey[1];
71
77
  break;
72
78
  }
73
79
  }
@@ -1,3 +1,4 @@
1
+ import { PublicKeys } from "../constants.js";
1
2
  import { MaybePromise } from "../utilities/0_types.js";
2
3
  import * as types from "../tl/2_types.js";
3
4
  import * as functions from "../tl/3_functions.js";
@@ -58,6 +59,7 @@ export interface ClientParams {
58
59
  * The system_version parameter to be passed to initConnection when calling `authorize`.
59
60
  */
60
61
  systemVersion?: string;
62
+ publicKeys?: PublicKeys;
61
63
  }
62
64
  export interface ForwardMessagesParams {
63
65
  messageThreadId?: number;
@@ -85,6 +87,7 @@ export declare class Client extends ClientAbstract {
85
87
  readonly langPack: string;
86
88
  readonly systemLangCode: string;
87
89
  readonly systemVersion: string;
90
+ private readonly publicKeys?;
88
91
  /**
89
92
  * Constructs the client.
90
93
  *
@@ -1,5 +1,5 @@
1
1
  import { debug, gunzip, Mutex } from "../deps.js";
2
- import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
2
+ import { ACK_THRESHOLD, APP_VERSION, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
4
4
  import { UNREACHABLE } from "../utilities/0_control.js";
5
5
  import { sha1 } from "../utilities/0_hash.js";
@@ -153,6 +153,12 @@ export class Client extends ClientAbstract {
153
153
  writable: true,
154
154
  value: void 0
155
155
  });
156
+ Object.defineProperty(this, "publicKeys", {
157
+ enumerable: true,
158
+ configurable: true,
159
+ writable: true,
160
+ value: void 0
161
+ });
156
162
  Object.defineProperty(this, "storageInited", {
157
163
  enumerable: true,
158
164
  configurable: true,
@@ -184,12 +190,13 @@ export class Client extends ClientAbstract {
184
190
  value: new Mutex()
185
191
  });
186
192
  this.parseMode = params?.parseMode ?? ParseMode.None;
187
- this.appVersion = params?.appVersion ?? DEFAULT_APP_VERSION;
188
- this.deviceModel = params?.deviceModel ?? DEFAULT_DEVICE_MODEL;
189
- this.langCode = params?.langCode ?? DEFAULT_LANG_CODE;
190
- this.langPack = params?.langPack ?? DEFAULT_LANG_PACK;
191
- this.systemLangCode = params?.systemLangCode ?? DEFAULT_SYSTEM_LANG_CODE;
192
- this.systemVersion = params?.systemVersion ?? DEFAULT_SYSTEM_VERSION;
193
+ this.appVersion = params?.appVersion ?? APP_VERSION;
194
+ this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
195
+ this.langCode = params?.langCode ?? LANG_CODE;
196
+ this.langPack = params?.langPack ?? LANG_PACK;
197
+ this.systemLangCode = params?.systemLangCode ?? SYSTEM_LANG_CODE;
198
+ this.systemVersion = params?.systemVersion ?? SYSTEM_VERSION;
199
+ this.publicKeys = params?.publicKeys;
193
200
  }
194
201
  /**
195
202
  * Sets the DC and resets the auth key stored in the session provider
@@ -226,7 +233,7 @@ export class Client extends ClientAbstract {
226
233
  }
227
234
  const authKey = await this.storage.getAuthKey();
228
235
  if (authKey == null) {
229
- const plain = new ClientPlain(this.transportProvider);
236
+ const plain = new ClientPlain(this.transportProvider, this.publicKeys);
230
237
  const dc = await this.storage.getDc();
231
238
  if (dc != null) {
232
239
  plain.setDc(dc);
@@ -458,7 +465,7 @@ export class Client extends ClientAbstract {
458
465
  }
459
466
  while (this.connected) {
460
467
  try {
461
- if (this.toAcknowledge.size >= ackThreshold) {
468
+ if (this.toAcknowledge.size >= ACK_THRESHOLD) {
462
469
  await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
463
470
  this.toAcknowledge.clear();
464
471
  }
@@ -1,15 +1,16 @@
1
1
  import { DC } from "./transport/2_transport_provider.js";
2
- export declare const ackThreshold = 10;
3
- export declare const publicKeys: Map<bigint, [bigint, bigint]>;
2
+ export declare const ACK_THRESHOLD = 10;
3
+ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
+ export declare const PUBLIC_KEYS: PublicKeys;
4
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
- export declare const DEFAULT_INITIAL_DC: DC;
6
+ export declare const INITIAL_DC: DC;
6
7
  export declare const LAYER = 160;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.968";
8
- export declare const DEFAULT_DEVICE_MODEL: string;
9
- export declare const DEFAULT_LANG_CODE: string;
10
- export declare const DEFAULT_LANG_PACK = "";
11
- export declare const DEFAULT_SYSTEM_LANG_CODE: string;
12
- export declare const DEFAULT_SYSTEM_VERSION: string;
8
+ export declare const APP_VERSION = "MTKruto 0.0.970";
9
+ export declare const DEVICE_MODEL: string;
10
+ export declare const LANG_CODE: string;
11
+ export declare const LANG_PACK = "";
12
+ export declare const SYSTEM_LANG_CODE: string;
13
+ export declare const SYSTEM_VERSION: string;
13
14
  export declare const USERNAME_TTL = 86400;
14
15
  export declare const STICKER_SET_NAME_TTL = 172800;
15
16
  export declare const MAX_CHAT_ID = 999999999999;
package/esm/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as dntShim from "./_dnt.shims.js";
2
- export const ackThreshold = 10;
3
- export const publicKeys = new Map([
2
+ export const ACK_THRESHOLD = 10;
3
+ export const PUBLIC_KEYS = Object.freeze([
4
4
  [
5
5
  1562291298945373506n,
6
6
  [
@@ -50,26 +50,18 @@ export const publicKeys = new Map([
50
50
  0x010001n,
51
51
  ],
52
52
  ],
53
- // Piltover
54
- [
55
- -5746138571559360724n,
56
- [
57
- 26007219673003768186863565706940772901187119797549016801229858995725553827566821957407312503173782965285118977548255274803204174826509270586421841734996746493071723679186583391927378886693846518017621303145594627156874011707147548520576401963675756312298478878474644101348427872255774246965916073553469761183250044599310582333625453447885100318336864215713703860033765477732305055537755094341310278183464296754000479758644167423888581130401586546401934096183449791147912201040435037926911688179080223967863256047196705714611239523210563418382771999824529581206920323901890386681875893623076449827387008128524246269437n,
58
- 0x010001n,
59
- ],
60
- ],
61
53
  ]);
62
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
- export const DEFAULT_INITIAL_DC = "2-test";
55
+ export const INITIAL_DC = "2-test";
64
56
  export const LAYER = 160;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.968";
57
+ export const APP_VERSION = "MTKruto 0.0.970";
66
58
  // @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];
69
- export const DEFAULT_LANG_PACK = "";
70
- export const DEFAULT_SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
59
+ export const 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;
60
+ export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
61
+ export const LANG_PACK = "";
62
+ export const SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
71
63
  // @ts-ignore: lib
72
- export const DEFAULT_SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
64
+ export const SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
73
65
  export const USERNAME_TTL = 86400;
74
66
  export const STICKER_SET_NAME_TTL = 172800;
75
67
  export const MAX_CHAT_ID = 999999999999;
package/esm/mod.d.ts CHANGED
@@ -23,4 +23,4 @@ export * from "./transport/0_transport.js";
23
23
  export * from "./transport/2_transport_provider.js";
24
24
  export * from "./connection/0_connection.js";
25
25
  export * from "./connection/1_connection_web_socket.js";
26
- export { DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "./constants.js";
26
+ export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./constants.js";
package/esm/mod.js CHANGED
@@ -20,4 +20,4 @@ export * from "./transport/0_transport.js";
20
20
  export * from "./transport/2_transport_provider.js";
21
21
  export * from "./connection/0_connection.js";
22
22
  export * from "./connection/1_connection_web_socket.js";
23
- export { DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "./constants.js";
23
+ export { APP_VERSION, DEVICE_MODEL, INITIAL_DC, LANG_CODE, LANG_PACK, LAYER, SYSTEM_LANG_CODE, SYSTEM_VERSION } from "./constants.js";
@@ -20,7 +20,7 @@ export function analyzeOptionalParam(ntype) {
20
20
  assertFalse(isNaN(bitIndex));
21
21
  return { flagField, bitIndex };
22
22
  }
23
- function serializeSingleParam(writer, value, type, ntype) {
23
+ function serializeSingleParam(writer, value, type, ntype, debugInfo) {
24
24
  const valueRepr = value == null ? null : value.constructor.name;
25
25
  if (isTLObjectConstructor(type)) {
26
26
  if ((type.name == "TypeX" && value instanceof TLObject) ||
@@ -29,7 +29,7 @@ function serializeSingleParam(writer, value, type, ntype) {
29
29
  return;
30
30
  }
31
31
  else {
32
- throw new TypeError(`Expected ${type.name} but received ${valueRepr}`);
32
+ throw new TypeError(`Expected ${type.name} but received ${valueRepr} ${debugInfo}`);
33
33
  }
34
34
  }
35
35
  if (type == Uint8Array) {
@@ -37,7 +37,7 @@ function serializeSingleParam(writer, value, type, ntype) {
37
37
  writer.writeBytes(value);
38
38
  }
39
39
  else {
40
- throw new TypeError(`Expected Uint8Array but received ${valueRepr}`);
40
+ throw new TypeError(`Expected Uint8Array but received ${valueRepr} ${debugInfo}`);
41
41
  }
42
42
  }
43
43
  switch (type) {
@@ -54,7 +54,7 @@ function serializeSingleParam(writer, value, type, ntype) {
54
54
  }
55
55
  }
56
56
  else {
57
- throw new TypeError(`Expected bigint but received ${valueRepr}`);
57
+ throw new TypeError(`Expected bigint but received ${valueRepr} ${debugInfo}`);
58
58
  }
59
59
  break;
60
60
  case "boolean":
@@ -67,7 +67,7 @@ function serializeSingleParam(writer, value, type, ntype) {
67
67
  }
68
68
  }
69
69
  else {
70
- throw new TypeError(`Expected boolean but received ${valueRepr}`);
70
+ throw new TypeError(`Expected boolean but received ${valueRepr} ${debugInfo}`);
71
71
  }
72
72
  break;
73
73
  case "number":
@@ -80,7 +80,7 @@ function serializeSingleParam(writer, value, type, ntype) {
80
80
  writer.writeInt32(value);
81
81
  }
82
82
  else {
83
- throw new TypeError(`Expected number but received ${valueRepr}`);
83
+ throw new TypeError(`Expected number but received ${valueRepr} ${debugInfo}`);
84
84
  }
85
85
  break;
86
86
  case "string":
@@ -99,7 +99,7 @@ function serializeSingleParam(writer, value, type, ntype) {
99
99
  break;
100
100
  case "true":
101
101
  if (value !== true) {
102
- throw new TypeError(`Expected true but received ${valueRepr}`);
102
+ throw new TypeError(`Expected true but received ${valueRepr} ${debugInfo}`);
103
103
  }
104
104
  }
105
105
  }
@@ -114,10 +114,11 @@ export class TLObject {
114
114
  [serialize]() {
115
115
  const writer = new TLRawWriter();
116
116
  writer.writeInt32(this[id], false);
117
- for (const [value, type, ntype] of this[params]) {
117
+ for (const [i, [value, type, ntype]] of this[params].entries()) {
118
118
  if (isOptionalParam(ntype) && value == null) {
119
119
  continue;
120
120
  }
121
+ const debugInfo = `[${i}]`;
121
122
  if (type == flags) {
122
123
  let flags = 0;
123
124
  const flagField_ = value;
@@ -142,11 +143,11 @@ export class TLObject {
142
143
  writer.writeInt32(0x1CB5C415); // vector constructor
143
144
  writer.writeInt32(value.length);
144
145
  for (const item of value) {
145
- serializeSingleParam(writer, item, itemsType, ntype);
146
+ serializeSingleParam(writer, item, itemsType, ntype, debugInfo);
146
147
  }
147
148
  continue;
148
149
  }
149
- serializeSingleParam(writer, value, type, ntype);
150
+ serializeSingleParam(writer, value, type, ntype, debugInfo);
150
151
  }
151
152
  return writer.buffer;
152
153
  }