@mtkruto/node 0.0.831 → 0.0.834

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.
Files changed (59) hide show
  1. package/esm/client/client.js +24 -8
  2. package/esm/client/client_abstract.d.ts +1 -1
  3. package/esm/client/client_abstract.js +3 -8
  4. package/esm/client/client_plain.js +8 -7
  5. package/esm/connection/connection.d.ts +1 -0
  6. package/esm/connection/connection_web_socket.d.ts +1 -0
  7. package/esm/connection/connection_web_socket.js +3 -0
  8. package/esm/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  9. package/esm/deps/deno.land/std@0.69.0/fmt/colors.js +224 -0
  10. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  11. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +71 -0
  12. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  13. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +112 -0
  14. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  15. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +2 -0
  16. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +39 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +1 -0
  20. package/esm/deps.d.ts +3 -1
  21. package/esm/deps.js +3 -1
  22. package/package.json +8 -6
  23. package/script/client/client.js +23 -7
  24. package/script/client/client_abstract.d.ts +1 -1
  25. package/script/client/client_abstract.js +3 -8
  26. package/script/client/client_plain.js +7 -6
  27. package/script/connection/connection.d.ts +1 -0
  28. package/script/connection/connection_web_socket.d.ts +1 -0
  29. package/script/connection/connection_web_socket.js +3 -0
  30. package/script/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  31. package/script/deps/deno.land/std@0.69.0/fmt/colors.js +298 -0
  32. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  33. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +98 -0
  34. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  35. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +141 -0
  36. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  37. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +32 -0
  38. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  39. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +43 -0
  40. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  41. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +17 -0
  42. package/script/deps.d.ts +3 -1
  43. package/script/deps.js +5 -2
  44. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/fmt/colors.d.ts +0 -0
  45. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/fmt/colors.js +0 -0
  46. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_diff.d.ts +0 -0
  47. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_diff.js +0 -0
  48. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_format.d.ts +0 -0
  49. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_format.js +0 -0
  50. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/asserts.d.ts +0 -0
  51. /package/esm/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/asserts.js +0 -0
  52. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/fmt/colors.d.ts +0 -0
  53. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/fmt/colors.js +0 -0
  54. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_diff.d.ts +0 -0
  55. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_diff.js +0 -0
  56. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_format.d.ts +0 -0
  57. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/_format.js +0 -0
  58. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/asserts.d.ts +0 -0
  59. /package/script/deps/deno.land/{std@0.186.0 → std@0.190.0}/testing/asserts.js +0 -0
@@ -0,0 +1,112 @@
1
+ import * as dntShim from "../../../../../_dnt.shims.js";
2
+ import { generateColor } from "./colors.js";
3
+ import { format } from "./format.js";
4
+ export class Debugger {
5
+ constructor(manager, namespace) {
6
+ Object.defineProperty(this, "manager", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: void 0
11
+ });
12
+ Object.defineProperty(this, "ns", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "color", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "last", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "enabled", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ this.manager = manager;
37
+ this.ns = namespace;
38
+ this.color = generateColor(namespace);
39
+ this.last = 0;
40
+ this.enabled = manager.enabled.some((r) => r.test(namespace));
41
+ }
42
+ log(fmt, ...args) {
43
+ if (!this.enabled)
44
+ return;
45
+ const diff = Date.now() - (this.last || Date.now());
46
+ fmt = format(fmt, ...args);
47
+ console.debug(...this.color(this.ns), fmt, ...this.color(`+${diff}ms`));
48
+ this.last = Date.now();
49
+ }
50
+ }
51
+ class DebugManager {
52
+ constructor(enabled) {
53
+ Object.defineProperty(this, "debuggers", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ Object.defineProperty(this, "enabled", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ this.debuggers = new Map();
66
+ this.enabled = enabled ?? [];
67
+ }
68
+ }
69
+ function extract(opts) {
70
+ if (!opts || opts.length === 0)
71
+ return [];
72
+ opts = opts.replace(/\s/g, "").replace(/\*/g, ".+");
73
+ return opts.split(",").map((rule) => new RegExp(`^${rule}$`));
74
+ }
75
+ let manager;
76
+ export function withoutEnv(enabled) {
77
+ if (!enabled)
78
+ enabled = [];
79
+ if (typeof enabled === "string")
80
+ enabled = extract(enabled);
81
+ manager = new DebugManager(enabled);
82
+ }
83
+ // @ts-ignore: lib
84
+ const isDeno = typeof dntShim.Deno !== "undefined" &&
85
+ typeof dntShim.dntGlobalThis !== "undefined";
86
+ // @ts-ignore: lib
87
+ const isNode = typeof process !== "undefined" &&
88
+ typeof dntShim.dntGlobalThis === "undefined";
89
+ function getOpts() {
90
+ if (isDeno) {
91
+ // @ts-ignore: lib
92
+ return dntShim.Deno.env.get("DEBUG");
93
+ }
94
+ else if (isNode) {
95
+ // @ts-ignore: lib
96
+ return process.env.DEBUG;
97
+ }
98
+ else {
99
+ // @ts-ignore: lib
100
+ return globalThis.DEBUG;
101
+ }
102
+ }
103
+ export function debug(namespace) {
104
+ if (!manager)
105
+ manager = new DebugManager(extract(getOpts()));
106
+ const dbg = new Debugger(manager, namespace);
107
+ manager.debuggers.set(namespace, dbg);
108
+ const de = Object.assign(dbg.log.bind(dbg), {
109
+ self: dbg,
110
+ });
111
+ return de;
112
+ }
@@ -0,0 +1,2 @@
1
+ export * as colors from "../../../../deno.land/std@0.69.0/fmt/colors.js";
2
+ export { default as inspect } from "object-inspect";
@@ -0,0 +1,2 @@
1
+ export * as colors from "../../../../deno.land/std@0.69.0/fmt/colors.js";
2
+ export { default as inspect } from "object-inspect";
@@ -0,0 +1 @@
1
+ export declare function format(f: string, ...args: unknown[]): string;
@@ -0,0 +1,39 @@
1
+ import { inspect } from "./deps.js";
2
+ export function format(f, ...args) {
3
+ let i = 0;
4
+ const len = args.length;
5
+ let str = String(f).replace(/%[sdjoO%]/g, (x) => {
6
+ if (x === "%%")
7
+ return "%";
8
+ if (i >= len)
9
+ return x;
10
+ switch (x) {
11
+ case "%s":
12
+ return String(args[i++]);
13
+ case "%d":
14
+ return Number(args[i++]).toString();
15
+ case "%o":
16
+ return inspect(args[i++]).split("\n").map((_) => _.trim()).join(" ");
17
+ case "%O":
18
+ return inspect(args[i++]);
19
+ case "%j":
20
+ try {
21
+ return JSON.stringify(args[i++]);
22
+ }
23
+ catch {
24
+ return "[Circular]";
25
+ }
26
+ default:
27
+ return x;
28
+ }
29
+ });
30
+ for (const x of args.splice(i)) {
31
+ if (x === null || !(typeof x === "object" && x !== null)) {
32
+ str += " " + x;
33
+ }
34
+ else {
35
+ str += " " + inspect(x);
36
+ }
37
+ }
38
+ return str;
39
+ }
@@ -0,0 +1 @@
1
+ export * from "./debug.js";
@@ -0,0 +1 @@
1
+ export * from "./debug.js";
package/esm/deps.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- export * from "./deps/deno.land/std@0.186.0/testing/asserts.js";
1
+ export * from "./deps/deno.land/std@0.190.0/testing/asserts.js";
2
2
  export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.1.3/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js";
4
4
  export { Mutex } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
+ import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
7
+ export declare const debug: typeof debug_;
package/esm/deps.js CHANGED
@@ -1,5 +1,7 @@
1
- export * from "./deps/deno.land/std@0.186.0/testing/asserts.js";
1
+ export * from "./deps/deno.land/std@0.190.0/testing/asserts.js";
2
2
  export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.1.3/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js";
4
4
  export { Mutex } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
6
+ import { debug as debug_ } from "./deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js";
7
+ export const debug = (v) => debug_(`mtkruto__${v}`);
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.831",
5
+ "version": "0.0.834",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -10,6 +10,12 @@
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/MTKruto/MTKruto.git"
12
12
  },
13
+ "devDependencies": {
14
+ "@types/node": "^18.11.9",
15
+ "picocolors": "^1.0.0",
16
+ "@types/ws": "^8.5.4",
17
+ "@types/object-inspect": "^1.8.1"
18
+ },
13
19
  "exports": {
14
20
  ".": {
15
21
  "import": "./esm/mod.js",
@@ -21,13 +27,9 @@
21
27
  },
22
28
  "dependencies": {
23
29
  "async-mutex": "0.4.0",
30
+ "object-inspect": "1.12.3",
24
31
  "@deno/shim-deno": "~0.16.1",
25
32
  "@deno/shim-crypto": "~0.3.1",
26
33
  "ws": "^8.13.0"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^18.11.9",
30
- "picocolors": "^1.0.0",
31
- "@types/ws": "^8.5.4"
32
34
  }
33
35
  }
@@ -42,6 +42,7 @@ const client_plain_js_1 = require("./client_plain.js");
42
42
  const storage_memory_js_1 = require("../storage/storage_memory.js");
43
43
  const _0_hash_js_1 = require("../utilities/0_hash.js");
44
44
  const _0_message_entity_js_1 = require("../types/0_message_entity.js");
45
+ const d = (0, deps_js_1.debug)("client");
45
46
  exports.restartAuth = Symbol();
46
47
  var ParseMode;
47
48
  (function (ParseMode) {
@@ -226,7 +227,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
226
227
  if (dc == null) {
227
228
  await this.storage.setDc(constants_js_1.DEFAULT_INITIAL_DC);
228
229
  }
229
- // logger().debug("Client connected");
230
+ d("enrypted client connected");
230
231
  this.receiveLoop();
231
232
  this.pingLoop();
232
233
  }
@@ -254,6 +255,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
254
255
  if (!this.apiHash) {
255
256
  throw new Error("apiHash not set");
256
257
  }
258
+ d("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
257
259
  await this.invoke(new functions.InitConnection({
258
260
  apiId: this.apiId,
259
261
  appVersion: this.appVersion,
@@ -267,6 +269,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
267
269
  systemLangCode: this.systemLangCode,
268
270
  systemVersion: this.systemVersion,
269
271
  }));
272
+ d("connection inited");
270
273
  const handlePassword = async (err) => {
271
274
  params = params;
272
275
  if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
@@ -277,6 +280,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
277
280
  const password = typeof params.password === "string" ? params.password : await params.password();
278
281
  const input = await (0, _1_password_js_1.checkPassword)(password, ap);
279
282
  await this.invoke(new functions.AuthCheckPassword({ password: input }));
283
+ d("authorized as user");
280
284
  break;
281
285
  }
282
286
  catch (err) {
@@ -299,6 +303,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
299
303
  };
300
304
  try {
301
305
  await this.invoke(new functions.UpdatesGetState());
306
+ d("already authorized");
302
307
  return;
303
308
  }
304
309
  catch (err) {
@@ -311,6 +316,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
311
316
  try {
312
317
  if (params instanceof types.AuthExportedAuthorization) {
313
318
  await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
319
+ d("authorization imported");
314
320
  }
315
321
  else if (typeof params == "object") {
316
322
  while (true) {
@@ -326,6 +332,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
326
332
  phoneNumber,
327
333
  settings: new types.CodeSettings(),
328
334
  }));
335
+ d("verification code sent");
329
336
  if (sentCode instanceof types.AuthSentCode) {
330
337
  while (true) {
331
338
  const phoneCode = typeof params.code === "string" ? params.code : await params.code();
@@ -336,6 +343,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
336
343
  }
337
344
  else {
338
345
  signedIn = true;
346
+ d("authorized as user");
339
347
  break;
340
348
  }
341
349
  }
@@ -369,6 +377,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
369
377
  }
370
378
  else {
371
379
  await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
380
+ d("authorized as bot");
372
381
  }
373
382
  }
374
383
  catch (err) {
@@ -380,6 +389,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
380
389
  newDc += "-test";
381
390
  }
382
391
  await this.reconnect(newDc);
392
+ d("migrated to DC%s", newDc);
383
393
  if (typeof params === "object" && phoneNumber != null) {
384
394
  params = Object.assign({}, params);
385
395
  params.phone = phoneNumber;
@@ -420,8 +430,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
420
430
  try {
421
431
  decrypted = await (0, _1_message_js_1.decryptMessage)(buffer, this.auth.key, this.auth.id, this.sessionId);
422
432
  }
423
- catch (_err) {
424
- // logger().error(`Failed to decrypt message: ${err}`);
433
+ catch (err) {
434
+ d("failed to decrypt message: %o", err);
425
435
  continue;
426
436
  }
427
437
  const messages = decrypted instanceof _6_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
@@ -430,7 +440,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
430
440
  if (body instanceof types.GZIPPacked) {
431
441
  body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
432
442
  }
433
- // logger().debug(`Received ${body.constructor.name}`);
443
+ d("received %s", body.constructor.name);
434
444
  if (body instanceof types.Updates) {
435
445
  this.processUpdates(body);
436
446
  }
@@ -439,6 +449,12 @@ class Client extends client_abstract_js_1.ClientAbstract {
439
449
  if (result instanceof types.GZIPPacked) {
440
450
  result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
441
451
  }
452
+ if (result instanceof types.RPCError) {
453
+ d("RPCResult: %d %s", result.errorCode, result.errorMessage);
454
+ }
455
+ else {
456
+ d("RPCResult: %s", result.constructor.name);
457
+ }
442
458
  const promise = this.promises.get(message.body.messageId);
443
459
  if (promise) {
444
460
  if (result instanceof types.RPCError) {
@@ -480,8 +496,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
480
496
  try {
481
497
  await this.invoke(new functions.Ping({ pingId: (0, _0_bigint_js_1.getRandomBigInt)(8, true, false) }));
482
498
  }
483
- catch (_err) {
484
- // logger().error(`Failed to invoke ping: ${err}`);
499
+ catch (err) {
500
+ d("ping loop error: %o", err);
485
501
  }
486
502
  await new Promise((r) => setTimeout(r, 60 * 1000));
487
503
  }
@@ -497,7 +513,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
497
513
  }
498
514
  const message = new _5_message_js_1.Message((0, _1_message_js_1.getMessageId)(), seqNo, function_);
499
515
  await this.transport.send(await (0, _1_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
500
- // logger().debug(`Invoked ${function_.constructor.name}`);
516
+ d("invoked %s", function_.constructor.name);
501
517
  if (noWait) {
502
518
  return;
503
519
  }
@@ -7,10 +7,10 @@ export declare abstract class ClientAbstract {
7
7
  protected connection: Connection;
8
8
  protected transport: Transport;
9
9
  private _dcId;
10
- protected connected: boolean;
11
10
  constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
12
11
  get dcId(): number;
13
12
  setDc(dc: DC): MaybePromise<void>;
13
+ get connected(): boolean;
14
14
  connect(): Promise<void>;
15
15
  reconnect(dc?: DC): Promise<void>;
16
16
  disconnect(): Promise<void>;
@@ -30,12 +30,6 @@ class ClientAbstract {
30
30
  writable: true,
31
31
  value: void 0
32
32
  });
33
- Object.defineProperty(this, "connected", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: false
38
- });
39
33
  const { connection, transport, dcId } = transportProvider({ cdn: false });
40
34
  this.connection = connection;
41
35
  this.transport = transport;
@@ -51,11 +45,13 @@ class ClientAbstract {
51
45
  this.transport = transport;
52
46
  this._dcId = dcId;
53
47
  }
48
+ get connected() {
49
+ return this.connection.connected;
50
+ }
54
51
  async connect() {
55
52
  await (0, deps_js_1.initTgCrypto)();
56
53
  await this.connection.open();
57
54
  await this.transport.initialize();
58
- this.connected = true;
59
55
  }
60
56
  async reconnect(dc) {
61
57
  await this.disconnect();
@@ -67,7 +63,6 @@ class ClientAbstract {
67
63
  async disconnect() {
68
64
  await this.transport.deinitialize();
69
65
  await this.connection.close();
70
- this.connected = false;
71
66
  }
72
67
  }
73
68
  exports.ClientAbstract = ClientAbstract;
@@ -13,6 +13,7 @@ const _2_types_js_1 = require("../tl/2_types.js");
13
13
  const _3_functions_js_1 = require("../tl/3_functions.js");
14
14
  const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
15
15
  const client_abstract_js_1 = require("./client_abstract.js");
16
+ const d = (0, deps_js_1.debug)("auth_key_creation");
16
17
  class ClientPlain extends client_abstract_js_1.ClientAbstract {
17
18
  async invoke(function_) {
18
19
  await this.transport.send((0, _1_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize]()));
@@ -29,14 +30,14 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
29
30
  }
30
31
  async createAuthKey() {
31
32
  const nonce = (0, _0_bigint_js_1.getRandomBigInt)(16, false, true);
32
- // logger().debug("Auth key creation started");
33
+ d("auth key creation started");
33
34
  const resPq = await this.invoke(new _3_functions_js_1.ReqPQMulti({ nonce }));
34
35
  (0, deps_js_1.assertInstanceOf)(resPq, _2_types_js_1.ResPQ);
35
36
  (0, deps_js_1.assertEquals)(resPq.nonce, nonce);
36
- // logger().debug("Got res_pq");
37
+ d("got res_pq");
37
38
  const pq_ = (0, _0_bigint_js_1.bigIntFromBuffer)(resPq.pq, false, false);
38
39
  const [p_, q_] = (0, deps_js_1.factorize)(pq_);
39
- // logger().debug("Factorized pq");
40
+ d("factorized pq");
40
41
  const p = (0, _0_buffer_js_1.bufferFromBigInt)(p_, 4, false, false);
41
42
  const q = (0, _0_buffer_js_1.bufferFromBigInt)(q_, 4, false, false);
42
43
  let publicKeyFingerprint;
@@ -74,7 +75,7 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
74
75
  encryptedData,
75
76
  }));
76
77
  (0, deps_js_1.assertInstanceOf)(dhParams, _2_types_js_1.ServerDHParamsOK);
77
- // logger().debug("Got server_DH_params_ok");
78
+ d("got server_DH_params_ok");
78
79
  const newNonce_ = (0, _0_buffer_js_1.bufferFromBigInt)(newNonce, 32, true, true);
79
80
  const serverNonce_ = (0, _0_buffer_js_1.bufferFromBigInt)(serverNonce, 16, true, true);
80
81
  const tmpAesKey = (0, _0_buffer_js_1.concat)(await (0, _0_hash_js_1.sha1)((0, _0_buffer_js_1.concat)(newNonce_, serverNonce_)), (await (0, _0_hash_js_1.sha1)((0, _0_buffer_js_1.concat)(serverNonce_, newNonce_))).slice(0, 0 + 12));
@@ -100,12 +101,12 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
100
101
  encryptedData = (0, deps_js_1.ige256Encrypt)(dataWithHash, tmpAesKey, tmpAesIv);
101
102
  const dhGenOk = await this.invoke(new _3_functions_js_1.SetClientDHParams({ nonce, serverNonce, encryptedData }));
102
103
  (0, deps_js_1.assertInstanceOf)(dhGenOk, _2_types_js_1.DHGenOK);
103
- // logger().debug("Got dh_gen_ok");
104
+ d("got dh_gen_ok");
104
105
  const serverNonceSlice = serverNonce_.slice(0, 8);
105
106
  const salt = newNonce_.slice(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
106
107
  const authKey_ = (0, _0_bigint_js_1.modExp)(gA, b, dhPrime);
107
108
  const authKey = (0, _0_buffer_js_1.bufferFromBigInt)(authKey_, 256, false, false);
108
- // logger().debug("Auth key created");
109
+ d("auth key created");
109
110
  return {
110
111
  authKey,
111
112
  salt: (0, _0_bigint_js_1.bigIntFromBuffer)(salt, true, false),
@@ -1,5 +1,6 @@
1
1
  import { MaybePromise } from "../types.js";
2
2
  export declare abstract class Connection {
3
+ abstract get connected(): boolean;
3
4
  abstract open(): MaybePromise<void>;
4
5
  abstract read(p: Uint8Array): MaybePromise<void>;
5
6
  abstract write(p: Uint8Array): MaybePromise<void>;
@@ -6,6 +6,7 @@ export declare class ConnectionWebSocket implements Connection {
6
6
  private buffer;
7
7
  private nextResolve;
8
8
  constructor(url: string | URL);
9
+ get connected(): boolean;
9
10
  open(): Promise<void>;
10
11
  read(p: Uint8Array): Promise<void>;
11
12
  write(p: Uint8Array): Promise<void>;
@@ -72,6 +72,9 @@ class ConnectionWebSocket {
72
72
  };
73
73
  this.webSocket.onerror = console.error;
74
74
  }
75
+ get connected() {
76
+ return this.webSocket.readyState == dntShim.WebSocket.OPEN;
77
+ }
75
78
  async open() {
76
79
  while (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
77
80
  if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
@@ -0,0 +1,77 @@
1
+ /** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */
2
+ interface Rgb {
3
+ r: number;
4
+ g: number;
5
+ b: number;
6
+ }
7
+ export declare function setColorEnabled(value: boolean): void;
8
+ export declare function getColorEnabled(): boolean;
9
+ export declare function reset(str: string): string;
10
+ export declare function bold(str: string): string;
11
+ export declare function dim(str: string): string;
12
+ export declare function italic(str: string): string;
13
+ export declare function underline(str: string): string;
14
+ export declare function inverse(str: string): string;
15
+ export declare function hidden(str: string): string;
16
+ export declare function strikethrough(str: string): string;
17
+ export declare function black(str: string): string;
18
+ export declare function red(str: string): string;
19
+ export declare function green(str: string): string;
20
+ export declare function yellow(str: string): string;
21
+ export declare function blue(str: string): string;
22
+ export declare function magenta(str: string): string;
23
+ export declare function cyan(str: string): string;
24
+ export declare function white(str: string): string;
25
+ export declare function gray(str: string): string;
26
+ export declare function brightBlack(str: string): string;
27
+ export declare function brightRed(str: string): string;
28
+ export declare function brightGreen(str: string): string;
29
+ export declare function brightYellow(str: string): string;
30
+ export declare function brightBlue(str: string): string;
31
+ export declare function brightMagenta(str: string): string;
32
+ export declare function brightCyan(str: string): string;
33
+ export declare function brightWhite(str: string): string;
34
+ export declare function bgBlack(str: string): string;
35
+ export declare function bgRed(str: string): string;
36
+ export declare function bgGreen(str: string): string;
37
+ export declare function bgYellow(str: string): string;
38
+ export declare function bgBlue(str: string): string;
39
+ export declare function bgMagenta(str: string): string;
40
+ export declare function bgCyan(str: string): string;
41
+ export declare function bgWhite(str: string): string;
42
+ export declare function bgBrightBlack(str: string): string;
43
+ export declare function bgBrightRed(str: string): string;
44
+ export declare function bgBrightGreen(str: string): string;
45
+ export declare function bgBrightYellow(str: string): string;
46
+ export declare function bgBrightBlue(str: string): string;
47
+ export declare function bgBrightMagenta(str: string): string;
48
+ export declare function bgBrightCyan(str: string): string;
49
+ export declare function bgBrightWhite(str: string): string;
50
+ /** Set text color using paletted 8bit colors.
51
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */
52
+ export declare function rgb8(str: string, color: number): string;
53
+ /** Set background color using paletted 8bit colors.
54
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */
55
+ export declare function bgRgb8(str: string, color: number): string;
56
+ /** Set text color using 24bit rgb.
57
+ * `color` can be a number in range `0x000000` to `0xffffff` or
58
+ * an `Rgb`.
59
+ *
60
+ * To produce the color magenta:
61
+ *
62
+ * rgba24("foo", 0xff00ff);
63
+ * rgba24("foo", {r: 255, g: 0, b: 255});
64
+ */
65
+ export declare function rgb24(str: string, color: number | Rgb): string;
66
+ /** Set background color using 24bit rgb.
67
+ * `color` can be a number in range `0x000000` to `0xffffff` or
68
+ * an `Rgb`.
69
+ *
70
+ * To produce the color magenta:
71
+ *
72
+ * bgRgba24("foo", 0xff00ff);
73
+ * bgRgba24("foo", {r: 255, g: 0, b: 255});
74
+ */
75
+ export declare function bgRgb24(str: string, color: number | Rgb): string;
76
+ export declare function stripColor(string: string): string;
77
+ export {};