@mtkruto/node 0.0.832 → 0.0.835

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 (127) hide show
  1. package/esm/client/client.d.ts +7 -2
  2. package/esm/client/client.js +66 -13
  3. package/esm/client/client_abstract.d.ts +2 -2
  4. package/esm/client/client_abstract.js +3 -8
  5. package/esm/client/client_plain.js +8 -7
  6. package/esm/connection/connection.d.ts +2 -1
  7. package/esm/connection/connection_web_socket.d.ts +1 -0
  8. package/esm/connection/connection_web_socket.js +3 -0
  9. package/esm/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  10. package/esm/deps/deno.land/std@0.69.0/fmt/colors.js +224 -0
  11. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  12. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +71 -0
  13. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  14. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +112 -0
  15. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  16. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +2 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +39 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  20. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +1 -0
  21. package/esm/deps.d.ts +2 -0
  22. package/esm/deps.js +2 -0
  23. package/esm/storage/storage.d.ts +1 -1
  24. package/esm/storage/storage_local_storage.d.ts +1 -1
  25. package/esm/storage/storage_memory.d.ts +1 -1
  26. package/esm/storage/storage_session_storage.d.ts +1 -1
  27. package/esm/transport/transport.d.ts +1 -1
  28. package/esm/types/0_chat_administrator_rights.d.ts +17 -0
  29. package/esm/types/0_chat_administrator_rights.js +38 -0
  30. package/esm/types/0_chat_photo.d.ts +24 -0
  31. package/esm/types/0_chat_photo.js +28 -0
  32. package/esm/types/0_force_reply.d.ts +8 -0
  33. package/esm/types/0_force_reply.js +17 -0
  34. package/esm/types/0_keyboard_button_poll_type.d.ts +3 -0
  35. package/esm/types/0_login_url.d.ts +6 -0
  36. package/esm/types/0_login_url.js +1 -0
  37. package/esm/types/0_message_entity.d.ts +1 -1
  38. package/esm/types/0_message_entity.js +2 -2
  39. package/esm/types/0_reply_keyboard_remove.d.ts +7 -0
  40. package/esm/types/0_reply_keyboard_remove.js +8 -0
  41. package/esm/types/0_web_app_info.d.ts +4 -0
  42. package/esm/types/0_web_app_info.js +3 -0
  43. package/esm/types/1_chat.d.ts +60 -0
  44. package/esm/types/1_chat.js +70 -0
  45. package/esm/types/1_inline_keyboard_button.d.ts +33 -0
  46. package/esm/types/1_inline_keyboard_button.js +63 -0
  47. package/esm/types/1_keyboard_button.d.ts +43 -0
  48. package/esm/types/1_keyboard_button.js +133 -0
  49. package/esm/types/1_user.d.ts +19 -0
  50. package/esm/types/1_user.js +25 -0
  51. package/esm/types/2_inline_keyboard_markup.d.ts +7 -0
  52. package/esm/types/2_inline_keyboard_markup.js +25 -0
  53. package/esm/types/2_reply_keyboard_markup.d.ts +12 -0
  54. package/esm/types/2_reply_keyboard_markup.js +37 -0
  55. package/esm/types/3_message.d.ts +22 -0
  56. package/esm/types/3_message.js +87 -0
  57. package/esm/utilities/0_control.d.ts +1 -0
  58. package/esm/utilities/0_control.js +3 -0
  59. package/esm/utilities/0_object.d.ts +1 -0
  60. package/esm/utilities/0_object.js +14 -0
  61. package/esm/utilities/0_types.js +1 -0
  62. package/package.json +8 -6
  63. package/script/client/client.d.ts +7 -2
  64. package/script/client/client.js +65 -12
  65. package/script/client/client_abstract.d.ts +2 -2
  66. package/script/client/client_abstract.js +3 -8
  67. package/script/client/client_plain.js +7 -6
  68. package/script/connection/connection.d.ts +2 -1
  69. package/script/connection/connection_web_socket.d.ts +1 -0
  70. package/script/connection/connection_web_socket.js +3 -0
  71. package/script/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  72. package/script/deps/deno.land/std@0.69.0/fmt/colors.js +298 -0
  73. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  74. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +98 -0
  75. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  76. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +141 -0
  77. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  78. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +32 -0
  79. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  80. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +43 -0
  81. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  82. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +17 -0
  83. package/script/deps.d.ts +2 -0
  84. package/script/deps.js +4 -1
  85. package/script/storage/storage.d.ts +1 -1
  86. package/script/storage/storage_local_storage.d.ts +1 -1
  87. package/script/storage/storage_memory.d.ts +1 -1
  88. package/script/storage/storage_session_storage.d.ts +1 -1
  89. package/script/transport/transport.d.ts +1 -1
  90. package/script/types/0_chat_administrator_rights.d.ts +17 -0
  91. package/script/types/0_chat_administrator_rights.js +66 -0
  92. package/script/types/0_chat_photo.d.ts +24 -0
  93. package/script/types/0_chat_photo.js +55 -0
  94. package/script/types/0_force_reply.d.ts +8 -0
  95. package/script/types/0_force_reply.js +45 -0
  96. package/script/types/0_keyboard_button_poll_type.d.ts +3 -0
  97. package/script/types/0_login_url.d.ts +6 -0
  98. package/script/types/0_login_url.js +2 -0
  99. package/script/types/0_message_entity.d.ts +1 -1
  100. package/script/types/0_message_entity.js +2 -2
  101. package/script/types/0_reply_keyboard_remove.d.ts +7 -0
  102. package/script/types/0_reply_keyboard_remove.js +36 -0
  103. package/script/types/0_web_app_info.d.ts +4 -0
  104. package/script/types/0_web_app_info.js +7 -0
  105. package/script/types/1_chat.d.ts +60 -0
  106. package/script/types/1_chat.js +97 -0
  107. package/script/types/1_inline_keyboard_button.d.ts +33 -0
  108. package/script/types/1_inline_keyboard_button.js +91 -0
  109. package/script/types/1_keyboard_button.d.ts +43 -0
  110. package/script/types/1_keyboard_button.js +161 -0
  111. package/script/types/1_user.d.ts +19 -0
  112. package/script/types/1_user.js +52 -0
  113. package/script/types/2_inline_keyboard_markup.d.ts +7 -0
  114. package/script/types/2_inline_keyboard_markup.js +53 -0
  115. package/script/types/2_reply_keyboard_markup.d.ts +12 -0
  116. package/script/types/2_reply_keyboard_markup.js +65 -0
  117. package/script/types/3_message.d.ts +22 -0
  118. package/script/types/3_message.js +114 -0
  119. package/script/utilities/0_control.d.ts +1 -0
  120. package/script/utilities/0_control.js +7 -0
  121. package/script/utilities/0_object.d.ts +1 -0
  122. package/script/utilities/0_object.js +18 -0
  123. package/script/utilities/0_types.js +2 -0
  124. /package/esm/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  125. /package/esm/{types.d.ts → utilities/0_types.d.ts} +0 -0
  126. /package/script/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  127. /package/script/{types.d.ts → utilities/0_types.d.ts} +0 -0
@@ -1,10 +1,14 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import * as types from "../tl/2_types.js";
3
3
  import * as functions from "../tl/3_functions.js";
4
4
  import { ClientAbstract } from "./client_abstract.js";
5
5
  import { Storage } from "../storage/storage.js";
6
6
  import { DC, TransportProvider } from "../transport/transport_provider.js";
7
7
  import { MessageEntity } from "../types/0_message_entity.js";
8
+ import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
9
+ import { ForceReply } from "../types/0_force_reply.js";
10
+ import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
11
+ import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
8
12
  export declare const restartAuth: unique symbol;
9
13
  export declare enum ParseMode {
10
14
  None = "none",
@@ -136,5 +140,6 @@ export declare class Client extends ClientAbstract {
136
140
  replyToMessageId?: number;
137
141
  messageThreadId?: number;
138
142
  sendAs?: number | string;
139
- }): Promise<types.TypeUpdates>;
143
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
144
+ }): Promise<import("../types/3_message.js").Message>;
140
145
  }
@@ -1,6 +1,8 @@
1
- import { gunzip } from "../deps.js";
1
+ import { debug, gunzip } from "../deps.js";
2
2
  import { ackThreshold, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
4
+ import { UNREACHABLE } from "../utilities/0_control.js";
5
+ import { sha1 } from "../utilities/0_hash.js";
4
6
  import { parseHtml } from "../utilities/0_html.js";
5
7
  import { decryptMessage, encryptMessage, getMessageId } from "../utilities/1_message.js";
6
8
  import { checkPassword } from "../utilities/1_password.js";
@@ -14,8 +16,13 @@ import { MessageContainer } from "../tl/6_message_container.js";
14
16
  import { ClientAbstract } from "./client_abstract.js";
15
17
  import { ClientPlain } from "./client_plain.js";
16
18
  import { StorageMemory } from "../storage/storage_memory.js";
17
- import { sha1 } from "../utilities/0_hash.js";
18
19
  import { messageEntityToTlObject } from "../types/0_message_entity.js";
20
+ import { replyKeyboardRemoveToTlObject } from "../types/0_reply_keyboard_remove.js";
21
+ import { forceReplyToTlObject } from "../types/0_force_reply.js";
22
+ import { replyKeyboardMarkupToTlObject } from "../types/2_reply_keyboard_markup.js";
23
+ import { inlineKeyboardMarkupToTlObject } from "../types/2_inline_keyboard_markup.js";
24
+ import { constructMessage } from "../types/3_message.js";
25
+ const d = debug("client");
19
26
  export const restartAuth = Symbol();
20
27
  export var ParseMode;
21
28
  (function (ParseMode) {
@@ -200,7 +207,7 @@ export class Client extends ClientAbstract {
200
207
  if (dc == null) {
201
208
  await this.storage.setDc(DEFAULT_INITIAL_DC);
202
209
  }
203
- // logger().debug("Client connected");
210
+ d("enrypted client connected");
204
211
  this.receiveLoop();
205
212
  this.pingLoop();
206
213
  }
@@ -228,6 +235,7 @@ export class Client extends ClientAbstract {
228
235
  if (!this.apiHash) {
229
236
  throw new Error("apiHash not set");
230
237
  }
238
+ d("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
231
239
  await this.invoke(new functions.InitConnection({
232
240
  apiId: this.apiId,
233
241
  appVersion: this.appVersion,
@@ -241,6 +249,7 @@ export class Client extends ClientAbstract {
241
249
  systemLangCode: this.systemLangCode,
242
250
  systemVersion: this.systemVersion,
243
251
  }));
252
+ d("connection inited");
244
253
  const handlePassword = async (err) => {
245
254
  params = params;
246
255
  if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
@@ -251,6 +260,7 @@ export class Client extends ClientAbstract {
251
260
  const password = typeof params.password === "string" ? params.password : await params.password();
252
261
  const input = await checkPassword(password, ap);
253
262
  await this.invoke(new functions.AuthCheckPassword({ password: input }));
263
+ d("authorized as user");
254
264
  break;
255
265
  }
256
266
  catch (err) {
@@ -273,6 +283,7 @@ export class Client extends ClientAbstract {
273
283
  };
274
284
  try {
275
285
  await this.invoke(new functions.UpdatesGetState());
286
+ d("already authorized");
276
287
  return;
277
288
  }
278
289
  catch (err) {
@@ -285,6 +296,7 @@ export class Client extends ClientAbstract {
285
296
  try {
286
297
  if (params instanceof types.AuthExportedAuthorization) {
287
298
  await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
299
+ d("authorization imported");
288
300
  }
289
301
  else if (typeof params == "object") {
290
302
  while (true) {
@@ -300,6 +312,7 @@ export class Client extends ClientAbstract {
300
312
  phoneNumber,
301
313
  settings: new types.CodeSettings(),
302
314
  }));
315
+ d("verification code sent");
303
316
  if (sentCode instanceof types.AuthSentCode) {
304
317
  while (true) {
305
318
  const phoneCode = typeof params.code === "string" ? params.code : await params.code();
@@ -310,6 +323,7 @@ export class Client extends ClientAbstract {
310
323
  }
311
324
  else {
312
325
  signedIn = true;
326
+ d("authorized as user");
313
327
  break;
314
328
  }
315
329
  }
@@ -343,6 +357,7 @@ export class Client extends ClientAbstract {
343
357
  }
344
358
  else {
345
359
  await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
360
+ d("authorized as bot");
346
361
  }
347
362
  }
348
363
  catch (err) {
@@ -354,6 +369,7 @@ export class Client extends ClientAbstract {
354
369
  newDc += "-test";
355
370
  }
356
371
  await this.reconnect(newDc);
372
+ d("migrated to DC%s", newDc);
357
373
  if (typeof params === "object" && phoneNumber != null) {
358
374
  params = Object.assign({}, params);
359
375
  params.phone = phoneNumber;
@@ -394,8 +410,8 @@ export class Client extends ClientAbstract {
394
410
  try {
395
411
  decrypted = await decryptMessage(buffer, this.auth.key, this.auth.id, this.sessionId);
396
412
  }
397
- catch (_err) {
398
- // logger().error(`Failed to decrypt message: ${err}`);
413
+ catch (err) {
414
+ d("failed to decrypt message: %o", err);
399
415
  continue;
400
416
  }
401
417
  const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
@@ -404,7 +420,7 @@ export class Client extends ClientAbstract {
404
420
  if (body instanceof types.GZIPPacked) {
405
421
  body = new TLReader(gunzip(body.packedData)).readObject();
406
422
  }
407
- // logger().debug(`Received ${body.constructor.name}`);
423
+ d("received %s", body.constructor.name);
408
424
  if (body instanceof types.Updates) {
409
425
  this.processUpdates(body);
410
426
  }
@@ -413,6 +429,12 @@ export class Client extends ClientAbstract {
413
429
  if (result instanceof types.GZIPPacked) {
414
430
  result = new TLReader(gunzip(result.packedData)).readObject();
415
431
  }
432
+ if (result instanceof types.RPCError) {
433
+ d("RPCResult: %d %s", result.errorCode, result.errorMessage);
434
+ }
435
+ else {
436
+ d("RPCResult: %s", result.constructor.name);
437
+ }
416
438
  const promise = this.promises.get(message.body.messageId);
417
439
  if (promise) {
418
440
  if (result instanceof types.RPCError) {
@@ -454,8 +476,8 @@ export class Client extends ClientAbstract {
454
476
  try {
455
477
  await this.invoke(new functions.Ping({ pingId: getRandomBigInt(8, true, false) }));
456
478
  }
457
- catch (_err) {
458
- // logger().error(`Failed to invoke ping: ${err}`);
479
+ catch (err) {
480
+ d("ping loop error: %o", err);
459
481
  }
460
482
  await new Promise((r) => setTimeout(r, 60 * 1000));
461
483
  }
@@ -471,7 +493,7 @@ export class Client extends ClientAbstract {
471
493
  }
472
494
  const message = new Message(getMessageId(), seqNo, function_);
473
495
  await this.transport.send(await encryptMessage(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
474
- // logger().debug(`Invoked ${function_.constructor.name}`);
496
+ d("invoked %s", function_.constructor.name);
475
497
  if (noWait) {
476
498
  return;
477
499
  }
@@ -565,7 +587,7 @@ export class Client extends ClientAbstract {
565
587
  channelId = resolved.peer.channelId;
566
588
  }
567
589
  else {
568
- throw new Error("Unreachable");
590
+ UNREACHABLE();
569
591
  }
570
592
  }
571
593
  if (userId) {
@@ -577,7 +599,7 @@ export class Client extends ClientAbstract {
577
599
  return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
578
600
  }
579
601
  else {
580
- throw new Error("Unreachable");
602
+ UNREACHABLE();
581
603
  }
582
604
  }
583
605
  }
@@ -612,6 +634,27 @@ export class Client extends ClientAbstract {
612
634
  }
613
635
  }
614
636
  }
637
+ let replyMarkup = undefined;
638
+ if (params?.replyMarkup) {
639
+ if ("inlineKeyboard" in params.replyMarkup) {
640
+ replyMarkup = await inlineKeyboardMarkupToTlObject(params.replyMarkup, async (v) => {
641
+ const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
642
+ return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
643
+ });
644
+ }
645
+ else if ("keyboard" in params.replyMarkup) {
646
+ replyMarkup = replyKeyboardMarkupToTlObject(params.replyMarkup);
647
+ }
648
+ else if ("removeKeyboard" in params.replyMarkup) {
649
+ replyMarkup = replyKeyboardRemoveToTlObject(params.replyMarkup);
650
+ }
651
+ else if ("forceReply" in params.replyMarkup) {
652
+ replyMarkup = forceReplyToTlObject(params.replyMarkup);
653
+ }
654
+ else {
655
+ throw new Error("The replyMarkup parameter has an unexpected type");
656
+ }
657
+ }
615
658
  const peer = await this.getInputPeer(chatId);
616
659
  const randomId = getRandomId();
617
660
  const message = text;
@@ -622,7 +665,7 @@ export class Client extends ClientAbstract {
622
665
  const topMsgId = params?.messageThreadId;
623
666
  const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
624
667
  const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
625
- return await this.invoke(new functions.MessagesSendMessage({
668
+ const updates = await this.invoke(new functions.MessagesSendMessage({
626
669
  peer,
627
670
  randomId,
628
671
  message,
@@ -633,6 +676,16 @@ export class Client extends ClientAbstract {
633
676
  topMsgId,
634
677
  sendAs,
635
678
  entities,
636
- }));
679
+ replyMarkup,
680
+ })).then((v) => v[as](types.Updates));
681
+ for (const update of updates.updates) {
682
+ if (update instanceof types.UpdateNewMessage) {
683
+ return constructMessage(update.message[as](types.Message), updates.users, updates.chats);
684
+ }
685
+ else if (update instanceof types.UpdateNewChannelMessage) {
686
+ return constructMessage(update.message[as](types.Message), updates.users, updates.chats);
687
+ }
688
+ }
689
+ UNREACHABLE();
637
690
  }
638
691
  }
@@ -1,16 +1,16 @@
1
+ import { MaybePromise } from "../utilities/0_types.js";
1
2
  import { Connection } from "../connection/connection.js";
2
3
  import { Transport } from "../transport/transport.js";
3
4
  import { DC } from "../transport/transport_provider.js";
4
- import { MaybePromise } from "../types.js";
5
5
  export declare abstract class ClientAbstract {
6
6
  protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
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>;
@@ -27,12 +27,6 @@ export class ClientAbstract {
27
27
  writable: true,
28
28
  value: void 0
29
29
  });
30
- Object.defineProperty(this, "connected", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: false
35
- });
36
30
  const { connection, transport, dcId } = transportProvider({ cdn: false });
37
31
  this.connection = connection;
38
32
  this.transport = transport;
@@ -48,11 +42,13 @@ export class ClientAbstract {
48
42
  this.transport = transport;
49
43
  this._dcId = dcId;
50
44
  }
45
+ get connected() {
46
+ return this.connection.connected;
47
+ }
51
48
  async connect() {
52
49
  await initTgCrypto();
53
50
  await this.connection.open();
54
51
  await this.transport.initialize();
55
- this.connected = true;
56
52
  }
57
53
  async reconnect(dc) {
58
54
  await this.disconnect();
@@ -64,6 +60,5 @@ export class ClientAbstract {
64
60
  async disconnect() {
65
61
  await this.transport.deinitialize();
66
62
  await this.connection.close();
67
- this.connected = false;
68
63
  }
69
64
  }
@@ -1,4 +1,4 @@
1
- import { assertEquals, assertInstanceOf, factorize, ige256Decrypt, ige256Encrypt } from "../deps.js";
1
+ import { assertEquals, assertInstanceOf, debug, factorize, ige256Decrypt, ige256Encrypt } from "../deps.js";
2
2
  import { publicKeys } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, modExp } from "../utilities/0_bigint.js";
4
4
  import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
@@ -10,6 +10,7 @@ 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 "./client_abstract.js";
13
+ const d = debug("auth_key_creation");
13
14
  export class ClientPlain extends ClientAbstract {
14
15
  async invoke(function_) {
15
16
  await this.transport.send(packUnencryptedMessage(function_[serialize]()));
@@ -26,14 +27,14 @@ export class ClientPlain extends ClientAbstract {
26
27
  }
27
28
  async createAuthKey() {
28
29
  const nonce = getRandomBigInt(16, false, true);
29
- // logger().debug("Auth key creation started");
30
+ d("auth key creation started");
30
31
  const resPq = await this.invoke(new ReqPQMulti({ nonce }));
31
32
  assertInstanceOf(resPq, ResPQ);
32
33
  assertEquals(resPq.nonce, nonce);
33
- // logger().debug("Got res_pq");
34
+ d("got res_pq");
34
35
  const pq_ = bigIntFromBuffer(resPq.pq, false, false);
35
36
  const [p_, q_] = factorize(pq_);
36
- // logger().debug("Factorized pq");
37
+ d("factorized pq");
37
38
  const p = bufferFromBigInt(p_, 4, false, false);
38
39
  const q = bufferFromBigInt(q_, 4, false, false);
39
40
  let publicKeyFingerprint;
@@ -71,7 +72,7 @@ export class ClientPlain extends ClientAbstract {
71
72
  encryptedData,
72
73
  }));
73
74
  assertInstanceOf(dhParams, ServerDHParamsOK);
74
- // logger().debug("Got server_DH_params_ok");
75
+ d("got server_DH_params_ok");
75
76
  const newNonce_ = bufferFromBigInt(newNonce, 32, true, true);
76
77
  const serverNonce_ = bufferFromBigInt(serverNonce, 16, true, true);
77
78
  const tmpAesKey = concat(await sha1(concat(newNonce_, serverNonce_)), (await sha1(concat(serverNonce_, newNonce_))).slice(0, 0 + 12));
@@ -97,12 +98,12 @@ export class ClientPlain extends ClientAbstract {
97
98
  encryptedData = ige256Encrypt(dataWithHash, tmpAesKey, tmpAesIv);
98
99
  const dhGenOk = await this.invoke(new SetClientDHParams({ nonce, serverNonce, encryptedData }));
99
100
  assertInstanceOf(dhGenOk, DHGenOK);
100
- // logger().debug("Got dh_gen_ok");
101
+ d("got dh_gen_ok");
101
102
  const serverNonceSlice = serverNonce_.slice(0, 8);
102
103
  const salt = newNonce_.slice(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
103
104
  const authKey_ = modExp(gA, b, dhPrime);
104
105
  const authKey = bufferFromBigInt(authKey_, 256, false, false);
105
- // logger().debug("Auth key created");
106
+ d("auth key created");
106
107
  return {
107
108
  authKey,
108
109
  salt: bigIntFromBuffer(salt, true, false),
@@ -1,5 +1,6 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_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>;
@@ -46,6 +46,9 @@ export class ConnectionWebSocket {
46
46
  };
47
47
  this.webSocket.onerror = console.error;
48
48
  }
49
+ get connected() {
50
+ return this.webSocket.readyState == dntShim.WebSocket.OPEN;
51
+ }
49
52
  async open() {
50
53
  while (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
51
54
  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 {};