@mtcute/convert 0.17.0 → 0.18.0

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 (113) hide show
  1. package/convert/src/dcs.cjs +119 -0
  2. package/convert/src/dcs.js +114 -0
  3. package/convert/src/gramjs/convert.cjs +30 -0
  4. package/convert/src/gramjs/convert.js +25 -0
  5. package/convert/src/gramjs/parse.cjs +33 -0
  6. package/convert/src/gramjs/parse.js +28 -0
  7. package/convert/src/gramjs/serialize.cjs +26 -0
  8. package/convert/src/gramjs/serialize.js +21 -0
  9. package/convert/src/mtkruto/convert.cjs +33 -0
  10. package/convert/src/mtkruto/convert.js +28 -0
  11. package/convert/src/mtkruto/parse.cjs +31 -0
  12. package/convert/src/mtkruto/parse.js +26 -0
  13. package/convert/src/mtkruto/serialize.cjs +18 -0
  14. package/convert/src/mtkruto/serialize.js +13 -0
  15. package/convert/src/pyrogram/convert.cjs +42 -0
  16. package/convert/src/pyrogram/convert.js +37 -0
  17. package/convert/src/pyrogram/parse.cjs +52 -0
  18. package/convert/src/pyrogram/parse.js +47 -0
  19. package/convert/src/pyrogram/serialize.cjs +40 -0
  20. package/convert/src/pyrogram/serialize.js +35 -0
  21. package/convert/src/tdesktop/convert.cjs +66 -0
  22. package/convert/src/tdesktop/convert.js +61 -0
  23. package/convert/src/tdesktop/qt-bundle.cjs +11 -0
  24. package/convert/src/tdesktop/qt-bundle.js +6 -0
  25. package/convert/src/tdesktop/qt-reader.cjs +38 -0
  26. package/convert/src/tdesktop/qt-reader.js +33 -0
  27. package/convert/src/tdesktop/qt-writer.cjs +34 -0
  28. package/convert/src/tdesktop/qt-writer.js +29 -0
  29. package/convert/src/tdesktop/tdata.cjs +359 -0
  30. package/convert/src/tdesktop/tdata.js +332 -0
  31. package/convert/src/telethon/convert.cjs +47 -0
  32. package/convert/src/telethon/convert.js +42 -0
  33. package/convert/src/telethon/parse.cjs +39 -0
  34. package/convert/src/telethon/parse.js +34 -0
  35. package/convert/src/telethon/serialize.cjs +34 -0
  36. package/convert/src/telethon/serialize.js +29 -0
  37. package/convert/src/utils/crypto.cjs +53 -0
  38. package/convert/src/utils/crypto.js +26 -0
  39. package/convert/src/utils/rle.cjs +49 -0
  40. package/convert/src/utils/rle.js +44 -0
  41. package/dcs.d.cts +4 -0
  42. package/gramjs/__fixtures__/session.d.cts +1 -0
  43. package/gramjs/convert.d.cts +4 -0
  44. package/gramjs/convert.test.d.cts +1 -0
  45. package/gramjs/index.d.cts +4 -0
  46. package/gramjs/parse.d.cts +2 -0
  47. package/gramjs/parse.test.d.cts +1 -0
  48. package/gramjs/serialize.d.cts +2 -0
  49. package/gramjs/serialize.test.d.cts +1 -0
  50. package/gramjs/types.d.cts +7 -0
  51. package/index.cjs +41 -488
  52. package/index.d.cts +1 -0
  53. package/index.d.ts +1 -0
  54. package/index.js +20 -467
  55. package/mtkruto/__fixtures__/session.d.cts +1 -0
  56. package/mtkruto/convert.d.cts +4 -0
  57. package/mtkruto/convert.test.d.cts +1 -0
  58. package/mtkruto/index.d.cts +4 -0
  59. package/mtkruto/parse.d.cts +2 -0
  60. package/mtkruto/parse.test.d.cts +1 -0
  61. package/mtkruto/serialize.d.cts +2 -0
  62. package/mtkruto/serialize.test.d.cts +1 -0
  63. package/mtkruto/types.d.cts +5 -0
  64. package/node/src/utils/crypto.cjs +75 -0
  65. package/node/src/utils/crypto.js +69 -0
  66. package/node/src/utils.cjs +34 -0
  67. package/node/src/utils.js +7 -0
  68. package/package.json +12 -9
  69. package/pyrogram/__fixtures__/session.d.cts +1 -0
  70. package/pyrogram/__fixtures__/session_old.d.cts +1 -0
  71. package/pyrogram/convert.d.cts +6 -0
  72. package/pyrogram/convert.test.d.cts +1 -0
  73. package/pyrogram/index.d.cts +4 -0
  74. package/pyrogram/parse.d.cts +2 -0
  75. package/pyrogram/parse.test.d.cts +1 -0
  76. package/pyrogram/serialize.d.cts +2 -0
  77. package/pyrogram/serialize.test.d.cts +1 -0
  78. package/pyrogram/types.d.cts +8 -0
  79. package/tdesktop/convert.d.cts +5 -0
  80. package/tdesktop/convert.d.ts +5 -0
  81. package/tdesktop/index.d.cts +5 -0
  82. package/tdesktop/index.d.ts +5 -0
  83. package/tdesktop/qt-bundle.d.cts +3 -0
  84. package/tdesktop/qt-bundle.d.ts +3 -0
  85. package/tdesktop/qt-reader.d.cts +6 -0
  86. package/tdesktop/qt-reader.d.ts +6 -0
  87. package/tdesktop/qt-writer.d.cts +6 -0
  88. package/tdesktop/qt-writer.d.ts +6 -0
  89. package/tdesktop/tdata.d.cts +65 -0
  90. package/tdesktop/tdata.d.ts +65 -0
  91. package/tdesktop/tdata.test.d.cts +1 -0
  92. package/tdesktop/tdata.test.d.ts +1 -0
  93. package/tdesktop/types.d.cts +22 -0
  94. package/tdesktop/types.d.ts +22 -0
  95. package/telethon/__fixtures__/session.d.cts +1 -0
  96. package/telethon/__fixtures__/session_v6.d.cts +1 -0
  97. package/telethon/convert.d.cts +4 -0
  98. package/telethon/convert.test.d.cts +1 -0
  99. package/telethon/index.d.cts +4 -0
  100. package/telethon/parse.d.cts +2 -0
  101. package/telethon/parse.test.d.cts +1 -0
  102. package/telethon/serialize.d.cts +2 -0
  103. package/telethon/serialize.test.d.cts +1 -0
  104. package/telethon/types.d.cts +7 -0
  105. package/types.d.cts +0 -0
  106. package/utils/crypto.d.cts +9 -0
  107. package/utils/crypto.d.ts +9 -0
  108. package/utils/fs.d.cts +11 -0
  109. package/utils/fs.d.ts +11 -0
  110. package/utils/rle.d.cts +3 -0
  111. package/wasm/src/index.cjs +64 -0
  112. package/wasm/src/index.js +59 -0
  113. package/utils/ip.d.ts +0 -3
@@ -0,0 +1,34 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const crypto = require("./utils/crypto.cjs");
9
+ const utils_js = require("@mtcute/core/utils.js");
10
+ function _interopNamespaceDefault(e) {
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== "default") {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+ const utils_js__namespace = /* @__PURE__ */ _interopNamespaceDefault(utils_js);
27
+ exports.BaseNodeCryptoProvider = crypto.BaseNodeCryptoProvider;
28
+ exports.NodeCryptoProvider = crypto.NodeCryptoProvider;
29
+ Object.keys(utils_js).forEach((k) => {
30
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
31
+ enumerable: true,
32
+ get: () => utils_js[k]
33
+ });
34
+ });
@@ -0,0 +1,7 @@
1
+ import { BaseNodeCryptoProvider, NodeCryptoProvider } from "./utils/crypto.js";
2
+ import * as utils_js from "@mtcute/core/utils.js";
3
+ export * from "@mtcute/core/utils.js";
4
+ export {
5
+ BaseNodeCryptoProvider,
6
+ NodeCryptoProvider
7
+ };
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@mtcute/convert",
3
3
  "type": "module",
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "description": "Cross-library session conversion utilities",
6
- "author": "alina sireneva <alina@tei.su>",
7
6
  "license": "MIT",
8
- "sideEffects": false,
7
+ "dependencies": {
8
+ "@mtcute/core": "^0.18.0",
9
+ "@fuman/utils": "0.0.4",
10
+ "@fuman/net": "0.0.4",
11
+ "@fuman/io": "0.0.4"
12
+ },
9
13
  "exports": {
10
14
  ".": {
11
15
  "import": {
@@ -18,13 +22,12 @@
18
22
  }
19
23
  }
20
24
  },
21
- "scripts": {},
22
- "dependencies": {
23
- "@mtcute/core": "^0.17.0"
24
- },
25
+ "author": "alina sireneva <alina@tei.su>",
26
+ "sideEffects": false,
25
27
  "homepage": "https://mtcute.dev",
26
28
  "repository": {
27
29
  "type": "git",
28
- "url": "https://github.com/mtcute/mtcute"
29
- }
30
+ "url": "git+https://github.com/mtcute/mtcute.git"
31
+ },
32
+ "scripts": {}
30
33
  }
@@ -0,0 +1 @@
1
+ export declare const PYROGRAM_TEST_SESSION = "AgAyyvcBTk6KssqikKPxEhxfXJpkoFIgQ_o8VpCk_4g0tcHe0rVCXx34AaDKvaNOlbkJOZ4jA3AI8iDYkI2opuifbM_7S2u9MMdnrjfg5jpfkXfI9-wF8DK_UBGIe1zk_Ibn0IHLRz-lkb-QqZNhh8O8Ggb8cieamatEYwLrkjkZR7JG53q76F0ktUd22L6_bUlp9p_qgXqBg8vZdkIIs9T1OiShw2X6TNO0lYqfJVaczMVQcT9Zt0FiyrAMpovFuT7-96OFKWcQ9gzrs_SHfz9HrQgBwvNSdkVziXTtxLJXsaNz3smGeyh-CEuEgdF3enIECnzftlvvUClLN_ylcPir1bi4_wAAAAEqEi1JAA";
@@ -0,0 +1 @@
1
+ export declare const PYROGRAM_TEST_SESSION_OLD = "AgEWdHMtuA1pC01YkNiHpL1bC0yBC3wzGZCwSRWKlA_a69RhePUN3M51NpnwSXrW3pZV9FS8WjAwUkA23uT_49t8c7Umw3ihhKD6-hTpZ5wXC2MuC0EsF0-Z6WshYhT3gmN6QhEt0jlXo5cW1BJ3MYmXtsTWNf_hJfd3_wF_ZFa58ntVV-3qd08wQRhiL_IxM7L5YazjPw0dg2z92CqRARku_oq5D29V6W6bo8T-SLzF_ujj5ZcAQL25mJtCcXfhhjp9atxcrqnKzEs05xyrehnlJZKoGmnX0mF2P_6wUHqZC9tcTBUV4AmFcbuy7m_4SYLnJ8MbftNs7aWHHNcB1R4fAAAAASoSLUkA";
@@ -0,0 +1,6 @@
1
+ import { StringSessionData } from '@mtcute/core/utils.js';
2
+ import { PyrogramSession } from './types.js';
3
+ export declare function convertFromPyrogramSession(session: PyrogramSession | string): StringSessionData;
4
+ export declare function convertToPyrogramSession(session: StringSessionData | string, params?: {
5
+ apiId?: number;
6
+ }): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './convert.js';
2
+ export * from './parse.js';
3
+ export * from './serialize.js';
4
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ import { PyrogramSession } from './types.js';
2
+ export declare function parsePyrogramSession(session: string): PyrogramSession;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { PyrogramSession } from './types.js';
2
+ export declare function serializePyrogramSession(session: PyrogramSession): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface PyrogramSession {
2
+ apiId?: number;
3
+ dcId: number;
4
+ isTest: boolean;
5
+ authKey: Uint8Array;
6
+ userId: number;
7
+ isBot: boolean;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { MaybeArray } from '@fuman/utils';
2
+ import { TdataOptions, Tdata } from './tdata.js';
3
+ import { StringSessionData } from '@mtcute/core/utils.js';
4
+ export declare function convertFromTdata(tdata: Tdata | TdataOptions, accountIdx?: number): Promise<StringSessionData>;
5
+ export declare function convertToTdata(sessions: MaybeArray<StringSessionData | string>, tdata: Tdata | TdataOptions): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { MaybeArray } from '@fuman/utils';
2
+ import { TdataOptions, Tdata } from './tdata.js';
3
+ import { StringSessionData } from '@mtcute/core/utils.js';
4
+ export declare function convertFromTdata(tdata: Tdata | TdataOptions, accountIdx?: number): Promise<StringSessionData>;
5
+ export declare function convertToTdata(sessions: MaybeArray<StringSessionData | string>, tdata: Tdata | TdataOptions): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import * as qt from './qt-bundle.js';
2
+ export { qt };
3
+ export * from './convert.js';
4
+ export * from './tdata.js';
5
+ export * from './types.js';
@@ -0,0 +1,5 @@
1
+ import * as qt from './qt-bundle.js';
2
+ export { qt };
3
+ export * from './convert.js';
4
+ export * from './tdata.js';
5
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ import * as read from './qt-reader.js';
2
+ import * as write from './qt-writer.js';
3
+ export { read, write };
@@ -0,0 +1,3 @@
1
+ import * as read from './qt-reader.js';
2
+ import * as write from './qt-writer.js';
3
+ export { read, write };
@@ -0,0 +1,6 @@
1
+ import { ISyncReadable } from '@fuman/io';
2
+ import { Long } from '@mtcute/core';
3
+ export declare function readQByteArray(readable: ISyncReadable): Uint8Array;
4
+ export declare function readLong(readable: ISyncReadable): Long;
5
+ export declare function readCharArray(readable: ISyncReadable): Uint8Array;
6
+ export declare function readQString(readable: ISyncReadable): string;
@@ -0,0 +1,6 @@
1
+ import { ISyncReadable } from '@fuman/io';
2
+ import { Long } from '@mtcute/core';
3
+ export declare function readQByteArray(readable: ISyncReadable): Uint8Array;
4
+ export declare function readLong(readable: ISyncReadable): Long;
5
+ export declare function readCharArray(readable: ISyncReadable): Uint8Array;
6
+ export declare function readQString(readable: ISyncReadable): string;
@@ -0,0 +1,6 @@
1
+ import { ISyncWritable } from '@fuman/io';
2
+ import { Long } from '@mtcute/core';
3
+ export declare function writeQByteArray(into: ISyncWritable, buf: Uint8Array): void;
4
+ export declare function writeLong(into: ISyncWritable, long: Long): void;
5
+ export declare function writeCharArray(into: ISyncWritable, buf: Uint8Array): void;
6
+ export declare function writeQString(into: ISyncWritable, str: string): void;
@@ -0,0 +1,6 @@
1
+ import { ISyncWritable } from '@fuman/io';
2
+ import { Long } from '@mtcute/core';
3
+ export declare function writeQByteArray(into: ISyncWritable, buf: Uint8Array): void;
4
+ export declare function writeLong(into: ISyncWritable, long: Long): void;
5
+ export declare function writeCharArray(into: ISyncWritable, buf: Uint8Array): void;
6
+ export declare function writeQString(into: ISyncWritable, str: string): void;
@@ -0,0 +1,65 @@
1
+ import { INodeFsLike } from '../utils/fs.js';
2
+ import { InputTdKeyData, TdKeyData, TdMtpAuthorization } from './types.js';
3
+ import { IExtendedCryptoProvider } from '../utils/crypto.js';
4
+ export interface TdataOptions {
5
+ /** Full path to the tdata directory */
6
+ path: string;
7
+ /**
8
+ * File system to use for reading/writing.
9
+ *
10
+ * @default `import('node:fs/promises')`
11
+ */
12
+ fs?: INodeFsLike;
13
+ /**
14
+ * Crypto functions to use for encryption/decryption.
15
+ *
16
+ * @default `node:crypto`-based implementation
17
+ */
18
+ crypto?: IExtendedCryptoProvider;
19
+ /**
20
+ * Whether to ignore TDF version mismatch.
21
+ * If set to `true`, the version will be ignored and the file will be read as is,
22
+ * however the probability of errors is higher.
23
+ */
24
+ ignoreVersion?: boolean;
25
+ /**
26
+ * Whether the host machine has LE processor (default true, try changing in case of errors)
27
+ */
28
+ le?: boolean;
29
+ /**
30
+ * Value of -key cli parameter.
31
+ * Defaults to `data`
32
+ */
33
+ dataKey?: string;
34
+ /**
35
+ * Local passcode
36
+ */
37
+ passcode?: string;
38
+ }
39
+ export declare class Tdata {
40
+ #private;
41
+ readonly options: TdataOptions;
42
+ readonly fs: INodeFsLike;
43
+ readonly crypto: IExtendedCryptoProvider;
44
+ private constructor();
45
+ readonly keyData: TdKeyData;
46
+ static open(options: TdataOptions): Promise<Tdata>;
47
+ static create(options: TdataOptions & {
48
+ keyData: InputTdKeyData;
49
+ }): Promise<Tdata>;
50
+ getDataName(idx: number): string;
51
+ readFile(filename: string): Promise<[number, Uint8Array]>;
52
+ writeFile(filename: string, data: Uint8Array, mkdir?: boolean): Promise<void>;
53
+ createLocalKey(salt: Uint8Array, passcode?: string): Promise<Uint8Array>;
54
+ decryptLocal(encrypted: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
55
+ encryptLocal(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
56
+ readKeyData(): Promise<TdKeyData>;
57
+ writeKeyData(keyData: TdKeyData): Promise<void>;
58
+ computeDataNameKey(accountIdx: number): Promise<Uint8Array>;
59
+ computeDataNameKeyHex(accountIdx: number): Promise<string>;
60
+ readEncryptedFile(filename: string): Promise<[number, Uint8Array]>;
61
+ writeEncryptedFile(filename: string, data: Uint8Array, mkdir?: boolean): Promise<void>;
62
+ readMtpAuthorization(accountIdx?: number): Promise<TdMtpAuthorization>;
63
+ writeMtpAuthorization(auth: TdMtpAuthorization, accountIdx?: number): Promise<void>;
64
+ writeEmptyMapFile(accountIdx: number): Promise<void>;
65
+ }
@@ -0,0 +1,65 @@
1
+ import { INodeFsLike } from '../utils/fs.js';
2
+ import { InputTdKeyData, TdKeyData, TdMtpAuthorization } from './types.js';
3
+ import { IExtendedCryptoProvider } from '../utils/crypto.js';
4
+ export interface TdataOptions {
5
+ /** Full path to the tdata directory */
6
+ path: string;
7
+ /**
8
+ * File system to use for reading/writing.
9
+ *
10
+ * @default `import('node:fs/promises')`
11
+ */
12
+ fs?: INodeFsLike;
13
+ /**
14
+ * Crypto functions to use for encryption/decryption.
15
+ *
16
+ * @default `node:crypto`-based implementation
17
+ */
18
+ crypto?: IExtendedCryptoProvider;
19
+ /**
20
+ * Whether to ignore TDF version mismatch.
21
+ * If set to `true`, the version will be ignored and the file will be read as is,
22
+ * however the probability of errors is higher.
23
+ */
24
+ ignoreVersion?: boolean;
25
+ /**
26
+ * Whether the host machine has LE processor (default true, try changing in case of errors)
27
+ */
28
+ le?: boolean;
29
+ /**
30
+ * Value of -key cli parameter.
31
+ * Defaults to `data`
32
+ */
33
+ dataKey?: string;
34
+ /**
35
+ * Local passcode
36
+ */
37
+ passcode?: string;
38
+ }
39
+ export declare class Tdata {
40
+ #private;
41
+ readonly options: TdataOptions;
42
+ readonly fs: INodeFsLike;
43
+ readonly crypto: IExtendedCryptoProvider;
44
+ private constructor();
45
+ readonly keyData: TdKeyData;
46
+ static open(options: TdataOptions): Promise<Tdata>;
47
+ static create(options: TdataOptions & {
48
+ keyData: InputTdKeyData;
49
+ }): Promise<Tdata>;
50
+ getDataName(idx: number): string;
51
+ readFile(filename: string): Promise<[number, Uint8Array]>;
52
+ writeFile(filename: string, data: Uint8Array, mkdir?: boolean): Promise<void>;
53
+ createLocalKey(salt: Uint8Array, passcode?: string): Promise<Uint8Array>;
54
+ decryptLocal(encrypted: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
55
+ encryptLocal(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
56
+ readKeyData(): Promise<TdKeyData>;
57
+ writeKeyData(keyData: TdKeyData): Promise<void>;
58
+ computeDataNameKey(accountIdx: number): Promise<Uint8Array>;
59
+ computeDataNameKeyHex(accountIdx: number): Promise<string>;
60
+ readEncryptedFile(filename: string): Promise<[number, Uint8Array]>;
61
+ writeEncryptedFile(filename: string, data: Uint8Array, mkdir?: boolean): Promise<void>;
62
+ readMtpAuthorization(accountIdx?: number): Promise<TdMtpAuthorization>;
63
+ writeMtpAuthorization(auth: TdMtpAuthorization, accountIdx?: number): Promise<void>;
64
+ writeEmptyMapFile(accountIdx: number): Promise<void>;
65
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Long } from '@mtcute/core';
2
+ export interface TdAuthKey {
3
+ dcId: number;
4
+ key: Uint8Array;
5
+ }
6
+ export interface TdMtpAuthorization {
7
+ userId: Long;
8
+ mainDcId: number;
9
+ authKeys: TdAuthKey[];
10
+ authKeysToDestroy: TdAuthKey[];
11
+ }
12
+ export interface InputTdKeyData {
13
+ localKey?: Uint8Array;
14
+ version?: number;
15
+ count: number;
16
+ order: number[];
17
+ active: number;
18
+ }
19
+ export interface TdKeyData extends InputTdKeyData {
20
+ version: number;
21
+ localKey: Uint8Array;
22
+ }
@@ -0,0 +1,22 @@
1
+ import { Long } from '@mtcute/core';
2
+ export interface TdAuthKey {
3
+ dcId: number;
4
+ key: Uint8Array;
5
+ }
6
+ export interface TdMtpAuthorization {
7
+ userId: Long;
8
+ mainDcId: number;
9
+ authKeys: TdAuthKey[];
10
+ authKeysToDestroy: TdAuthKey[];
11
+ }
12
+ export interface InputTdKeyData {
13
+ localKey?: Uint8Array;
14
+ version?: number;
15
+ count: number;
16
+ order: number[];
17
+ active: number;
18
+ }
19
+ export interface TdKeyData extends InputTdKeyData {
20
+ version: number;
21
+ localKey: Uint8Array;
22
+ }
@@ -0,0 +1 @@
1
+ export declare const TELETHON_TEST_SESSION = "1ApWapygAUChJS1_xwUK01Is4cOvQa1JKTn1POabdMUCfLmXNYFUyvG3v9Z_qbFNFp3zYP--3aVpTYI2DpB2Ib46p_bwSC0j1QEjvdQxJj26cVj8NfslrCkYrdV3glOhdczSq08kp31eqBGXMPhA7wy7DOcSLLAoy-Jf3Q_V_Q3y2a8_64ArFJe8PFfSqkdO56VQutajNLscFUtTQXUQFLJ7ft6vIl__UOc9tpQZEiFW7jWmID79WkfYLHFjuChTVKGMLDa8YcZj6z5Sq-pXPE9VbAbJ5L1JRqXOey3QGtZgJeIEww_WWD5nMMUfhLIydD2i7eDmVoUE5EIZPpsevJmjiGLw4vJk=";
@@ -0,0 +1 @@
1
+ export declare const TELETHON_TEST_SESSION_V6 = "1ASABCyjyPfABAAAAAAAAAA4Bu4pveAFWSE51_trKsrRQeMvGXMl8fI6NsGaWqdrXXeqyaXne9qNthqnrBmH56kHfOhFUCPSoVzNNrGgnQr67AYQbkhpP_Yml2EDd8epdc6Gywh4q2NBgYyW6VBT8UKg89-FebYTO6n47I1cJMGsSZ1ddxEOpIpHXsSmPdGBSTz6uaHbLYo0jnxd59PQn4H4dKb8FxuOQsUVa3vY_o79HMVMQRVT1IksUKFg5gAe5ZJ0yx6W4pMviVbC-TYZC0HInmv2fFMv-S3rQyg1C7qpU-Gbo1P6UZC4KZGmu2pMJooFNyfRbFgl3BI5Z-FNx9TKu4UFrF9G6Q0l8PjPXOZm4j-c=";
@@ -0,0 +1,4 @@
1
+ import { StringSessionData } from '@mtcute/core/utils.js';
2
+ import { TelethonSession } from './types.js';
3
+ export declare function convertFromTelethonSession(session: TelethonSession | string): StringSessionData;
4
+ export declare function convertToTelethonSession(session: StringSessionData | string): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './convert.js';
2
+ export * from './parse.js';
3
+ export * from './serialize.js';
4
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ import { TelethonSession } from './types.js';
2
+ export declare function parseTelethonSession(session: string): TelethonSession;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { TelethonSession } from './types.js';
2
+ export declare function serializeTelethonSession(session: TelethonSession): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface TelethonSession {
2
+ dcId: number;
3
+ ipAddress: string;
4
+ ipv6: boolean;
5
+ port: number;
6
+ authKey: Uint8Array;
7
+ }
package/types.d.cts ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ import { MaybePromise } from '@fuman/utils';
2
+ import { ICryptoProvider } from '@mtcute/core/utils.js';
3
+ export interface IExtendedCryptoProvider extends ICryptoProvider {
4
+ createHash(algorithm: 'md5' | 'sha512'): MaybePromise<{
5
+ update(data: Uint8Array): MaybePromise<void>;
6
+ digest(): MaybePromise<Uint8Array>;
7
+ }>;
8
+ }
9
+ export declare function getDefaultCryptoProvider(): Promise<IExtendedCryptoProvider>;
@@ -0,0 +1,9 @@
1
+ import { MaybePromise } from '@fuman/utils';
2
+ import { ICryptoProvider } from '@mtcute/core/utils.js';
3
+ export interface IExtendedCryptoProvider extends ICryptoProvider {
4
+ createHash(algorithm: 'md5' | 'sha512'): MaybePromise<{
5
+ update(data: Uint8Array): MaybePromise<void>;
6
+ digest(): MaybePromise<Uint8Array>;
7
+ }>;
8
+ }
9
+ export declare function getDefaultCryptoProvider(): Promise<IExtendedCryptoProvider>;
package/utils/fs.d.cts ADDED
@@ -0,0 +1,11 @@
1
+ export interface INodeFsLike {
2
+ readFile(path: string): Promise<Uint8Array>;
3
+ writeFile(path: string, data: Uint8Array): Promise<void>;
4
+ mkdir(path: string, options?: {
5
+ recursive?: boolean;
6
+ }): Promise<void>;
7
+ stat(path: string): Promise<{
8
+ size: number;
9
+ lastModified: number;
10
+ }>;
11
+ }
package/utils/fs.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface INodeFsLike {
2
+ readFile(path: string): Promise<Uint8Array>;
3
+ writeFile(path: string, data: Uint8Array): Promise<void>;
4
+ mkdir(path: string, options?: {
5
+ recursive?: boolean;
6
+ }): Promise<void>;
7
+ stat(path: string): Promise<{
8
+ size: number;
9
+ lastModified: number;
10
+ }>;
11
+ }
@@ -0,0 +1,3 @@
1
+ export declare function telegramRleEncode(buf: Uint8Array): Uint8Array;
2
+ export declare function telegramRleDecode(buf: Uint8Array): Uint8Array;
3
+ export declare function assertNever(_: never): never;
@@ -0,0 +1,64 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ let wasm;
9
+ let sharedKeyPtr;
10
+ let sharedIvPtr;
11
+ let cachedUint8Memory = null;
12
+ function initCommon() {
13
+ wasm.libdeflate_alloc_compressor(6);
14
+ wasm.libdeflate_alloc_decompressor();
15
+ wasm.__get_shared_out();
16
+ sharedKeyPtr = wasm.__get_shared_key_buffer();
17
+ sharedIvPtr = wasm.__get_shared_iv_buffer();
18
+ }
19
+ function getUint8Memory() {
20
+ if (cachedUint8Memory === null || cachedUint8Memory.byteLength === 0) {
21
+ cachedUint8Memory = new Uint8Array(wasm.memory.buffer);
22
+ }
23
+ return cachedUint8Memory;
24
+ }
25
+ function initSync(module2) {
26
+ if (wasm !== void 0) return;
27
+ if (!(module2 instanceof WebAssembly.Instance)) {
28
+ if (!(module2 instanceof WebAssembly.Module)) {
29
+ module2 = new WebAssembly.Module(module2);
30
+ }
31
+ module2 = new WebAssembly.Instance(module2);
32
+ }
33
+ wasm = module2.exports;
34
+ initCommon();
35
+ }
36
+ function ige256Encrypt(data, key, iv) {
37
+ const ptr = wasm.__malloc(data.length + data.length);
38
+ const inputPtr = ptr;
39
+ const outputPtr = inputPtr + data.length;
40
+ const mem = getUint8Memory();
41
+ mem.set(data, inputPtr);
42
+ mem.set(key, sharedKeyPtr);
43
+ mem.set(iv, sharedIvPtr);
44
+ wasm.ige256_encrypt(inputPtr, data.length, outputPtr);
45
+ const result = mem.slice(outputPtr, outputPtr + data.length);
46
+ wasm.__free(ptr);
47
+ return result;
48
+ }
49
+ function ige256Decrypt(data, key, iv) {
50
+ const ptr = wasm.__malloc(data.length + data.length);
51
+ const inputPtr = ptr;
52
+ const outputPtr = inputPtr + data.length;
53
+ const mem = getUint8Memory();
54
+ mem.set(data, inputPtr);
55
+ mem.set(key, sharedKeyPtr);
56
+ mem.set(iv, sharedIvPtr);
57
+ wasm.ige256_decrypt(inputPtr, data.length, outputPtr);
58
+ const result = mem.slice(outputPtr, outputPtr + data.length);
59
+ wasm.__free(ptr);
60
+ return result;
61
+ }
62
+ exports.ige256Decrypt = ige256Decrypt;
63
+ exports.ige256Encrypt = ige256Encrypt;
64
+ exports.initSync = initSync;
@@ -0,0 +1,59 @@
1
+ let wasm;
2
+ let sharedKeyPtr;
3
+ let sharedIvPtr;
4
+ let cachedUint8Memory = null;
5
+ function initCommon() {
6
+ wasm.libdeflate_alloc_compressor(6);
7
+ wasm.libdeflate_alloc_decompressor();
8
+ wasm.__get_shared_out();
9
+ sharedKeyPtr = wasm.__get_shared_key_buffer();
10
+ sharedIvPtr = wasm.__get_shared_iv_buffer();
11
+ }
12
+ function getUint8Memory() {
13
+ if (cachedUint8Memory === null || cachedUint8Memory.byteLength === 0) {
14
+ cachedUint8Memory = new Uint8Array(wasm.memory.buffer);
15
+ }
16
+ return cachedUint8Memory;
17
+ }
18
+ function initSync(module) {
19
+ if (wasm !== void 0) return;
20
+ if (!(module instanceof WebAssembly.Instance)) {
21
+ if (!(module instanceof WebAssembly.Module)) {
22
+ module = new WebAssembly.Module(module);
23
+ }
24
+ module = new WebAssembly.Instance(module);
25
+ }
26
+ wasm = module.exports;
27
+ initCommon();
28
+ }
29
+ function ige256Encrypt(data, key, iv) {
30
+ const ptr = wasm.__malloc(data.length + data.length);
31
+ const inputPtr = ptr;
32
+ const outputPtr = inputPtr + data.length;
33
+ const mem = getUint8Memory();
34
+ mem.set(data, inputPtr);
35
+ mem.set(key, sharedKeyPtr);
36
+ mem.set(iv, sharedIvPtr);
37
+ wasm.ige256_encrypt(inputPtr, data.length, outputPtr);
38
+ const result = mem.slice(outputPtr, outputPtr + data.length);
39
+ wasm.__free(ptr);
40
+ return result;
41
+ }
42
+ function ige256Decrypt(data, key, iv) {
43
+ const ptr = wasm.__malloc(data.length + data.length);
44
+ const inputPtr = ptr;
45
+ const outputPtr = inputPtr + data.length;
46
+ const mem = getUint8Memory();
47
+ mem.set(data, inputPtr);
48
+ mem.set(key, sharedKeyPtr);
49
+ mem.set(iv, sharedIvPtr);
50
+ wasm.ige256_decrypt(inputPtr, data.length, outputPtr);
51
+ const result = mem.slice(outputPtr, outputPtr + data.length);
52
+ wasm.__free(ptr);
53
+ return result;
54
+ }
55
+ export {
56
+ ige256Decrypt,
57
+ ige256Encrypt,
58
+ initSync
59
+ };
package/utils/ip.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function parseIpFromBytes(data: Uint8Array): string;
2
- export declare function serializeIpv4ToBytes(ip: string, buf: Uint8Array): void;
3
- export declare function serializeIpv6ToBytes(ip: string, buf: Uint8Array): void;