@mtkruto/node 0.0.78 → 0.0.801

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,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Session = void 0;
4
+ const _0_hash_js_1 = require("../utilities/0_hash.js");
5
+ const _0_bigint_js_1 = require("../utilities/0_bigint.js");
4
6
  class Session {
5
7
  constructor() {
6
8
  Object.defineProperty(this, "dc", {
@@ -9,12 +11,30 @@ class Session {
9
11
  writable: true,
10
12
  value: null
11
13
  });
12
- Object.defineProperty(this, "authKey", {
14
+ Object.defineProperty(this, "_authKeyId", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: Promise.resolve(null)
19
+ });
20
+ Object.defineProperty(this, "_authKey", {
13
21
  enumerable: true,
14
22
  configurable: true,
15
23
  writable: true,
16
24
  value: null
17
25
  });
18
26
  }
27
+ get authKeyId() {
28
+ return this._authKeyId;
29
+ }
30
+ set authKey(authKey) {
31
+ this._authKey = authKey;
32
+ if (authKey != null) {
33
+ this._authKeyId = (0, _0_hash_js_1.sha1)(authKey).then((hash) => (0, _0_bigint_js_1.bigIntFromBuffer)(hash.slice(-8), true, false));
34
+ }
35
+ }
36
+ get authKey() {
37
+ return this._authKey;
38
+ }
19
39
  }
20
40
  exports.Session = Session;
@@ -2,7 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bufferFromBigInt = exports.concat = void 0;
4
4
  function concat(...buffers) {
5
- return new Uint8Array(buffers.map((v) => Array.from(v)).flat());
5
+ const bytes = new Array();
6
+ for (const buffer of buffers) {
7
+ bytes.push(...buffer);
8
+ }
9
+ const buffer = new Uint8Array(bytes);
10
+ return buffer;
6
11
  }
7
12
  exports.concat = concat;
8
13
  const bufferFromHexString = (hexString) => Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
@@ -9,12 +9,8 @@ const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
9
9
  const _4_rpc_result_js_1 = require("../tl/4_rpc_result.js");
10
10
  const _5_message_js_1 = require("../tl/5_message.js");
11
11
  const _6_message_container_js_1 = require("../tl/6_message_container.js");
12
- const _0_bigint_js_1 = require("./0_bigint.js");
13
12
  const _0_buffer_js_1 = require("./0_buffer.js");
14
13
  const _0_hash_js_1 = require("./0_hash.js");
15
- async function getAuthKeyId(authKey) {
16
- return (0, _0_bigint_js_1.bigIntFromBuffer)((await (0, _0_hash_js_1.sha1)(authKey)).slice(-8), true, false);
17
- }
18
14
  let lastMsgId = 0n;
19
15
  function getMessageId() {
20
16
  const now = new Date().getTime() / 1000 + 0;
@@ -43,9 +39,8 @@ function unpackUnencryptedMessage(buffer) {
43
39
  return { messageId, message };
44
40
  }
45
41
  exports.unpackUnencryptedMessage = unpackUnencryptedMessage;
46
- async function encryptMessage(message, authKey, salt, sessionId) {
42
+ async function encryptMessage(message, authKey, authKeyId, salt, sessionId) {
47
43
  const encoded = message.body.serialize();
48
- const authKeyId = await getAuthKeyId(authKey);
49
44
  const payloadWriter = new _0_tl_raw_writer_js_1.TLRawWriter();
50
45
  payloadWriter.writeInt64(salt);
51
46
  payloadWriter.writeInt64(sessionId);
@@ -73,8 +68,7 @@ async function encryptMessage(message, authKey, salt, sessionId) {
73
68
  return messageWriter.buffer;
74
69
  }
75
70
  exports.encryptMessage = encryptMessage;
76
- async function decryptMessage(buffer, authKey, _sessionId) {
77
- const authKeyId = await getAuthKeyId(authKey);
71
+ async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
78
72
  const reader = new _3_tl_reader_js_1.TLReader(buffer);
79
73
  (0, deps_js_1.assertEquals)(reader.readInt64(false), authKeyId);
80
74
  const messageKey_ = reader.readInt128();
@@ -3,19 +3,45 @@ 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 { Session } from "../session/session.js";
6
- import { TransportProvider } from "../transport/transport_provider.js";
6
+ import { DC, TransportProvider } from "../transport/transport_provider.js";
7
+ export interface AuthorizeUserParams<S = string, N = {
8
+ first: S;
9
+ last: S;
10
+ }> {
11
+ phone: S | (() => MaybePromise<S>);
12
+ code: S | (() => MaybePromise<S>);
13
+ password: S | (() => MaybePromise<S>);
14
+ names: N | (() => MaybePromise<N>);
15
+ }
7
16
  export type UpdatesHandler = null | ((client: Client, update: types.Updates) => MaybePromise<void>);
8
17
  export declare class Client extends ClientAbstract {
9
18
  readonly session: Session;
19
+ readonly apiId: number;
20
+ readonly apiHash: string;
10
21
  private sessionId;
11
22
  private state;
12
23
  private promises;
13
24
  private toAcknowledge;
14
25
  updatesHandler: UpdatesHandler;
15
- constructor(session?: Session, params?: {
26
+ readonly appVersion: string;
27
+ readonly deviceModel: string;
28
+ readonly langCode: string;
29
+ readonly langPack: string;
30
+ readonly systemLangCode: string;
31
+ readonly systemVersion: string;
32
+ constructor(session?: Session, apiId?: number, apiHash?: string, params?: {
16
33
  transportProvider?: TransportProvider;
34
+ appVersion?: string;
35
+ deviceModel?: string;
36
+ langCode?: string;
37
+ langPack?: string;
38
+ systemLangCode?: string;
39
+ systemVersion?: string;
17
40
  });
41
+ private shouldLoadSession;
42
+ setDc(dc: DC): void;
18
43
  connect(): Promise<void>;
44
+ authorize(params: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
19
45
  private receiveLoop;
20
46
  private pingLoop;
21
47
  invoke<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
@@ -1,12 +1,16 @@
1
1
  import { Connection } from "../connection/connection.js";
2
2
  import { Transport } from "../transport/transport.js";
3
+ import { DC } from "../transport/transport_provider.js";
3
4
  export declare abstract class ClientAbstract {
4
5
  protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
5
6
  protected connection: Connection;
6
7
  protected transport: Transport;
7
- dcId: number;
8
+ private _dcId;
8
9
  protected connected: boolean;
9
10
  constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
11
+ get dcId(): number;
12
+ setDc(dc: DC): void;
10
13
  connect(): Promise<void>;
14
+ reconnect(dc?: DC): Promise<void>;
11
15
  disconnect(): Promise<void>;
12
16
  }
@@ -3,3 +3,10 @@ export declare const ackThreshold = 10;
3
3
  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
+ export declare const LAYER = 158;
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto Unstable <v1.0.0";
8
+ export declare const DEFAULT_DEVICE_MODEL = "Krutaya Device";
9
+ export declare const DEFAULT_LANG_CODE = "en";
10
+ export declare const DEFAULT_LANG_PACK = "";
11
+ export declare const DEFAULT_SYSTEM_LANG_CODE = "en";
12
+ export declare const DEFAULT_SYSTEM_VERSION = "1.0";
package/types/mod.d.ts CHANGED
@@ -20,4 +20,4 @@ export * from "./transport/transport.js";
20
20
  export * from "./transport/transport_provider.js";
21
21
  export * from "./connection/connection.js";
22
22
  export * from "./connection/connection_web_socket.js";
23
- export { DEFAULT_INITIAL_DC } from "./constants.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";
@@ -1,8 +1,12 @@
1
1
  import { MaybePromise } from "../types.js";
2
- import { TransportProviderParams } from "../transport/transport_provider.js";
2
+ import { DC } from "../transport/transport_provider.js";
3
3
  export declare abstract class Session {
4
- dc: TransportProviderParams["dc"] | null;
5
- authKey: Uint8Array | null;
4
+ dc: DC | null;
5
+ private _authKeyId;
6
+ private _authKey;
6
7
  abstract load(): MaybePromise<void>;
7
8
  abstract save(): MaybePromise<void>;
9
+ get authKeyId(): Promise<bigint | null>;
10
+ set authKey(authKey: Uint8Array | null);
11
+ get authKey(): Uint8Array | null;
8
12
  }