@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,119 @@
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 DC_MAPPING_PROD = {
9
+ 1: {
10
+ main: {
11
+ id: 1,
12
+ ipAddress: "149.154.175.56",
13
+ port: 443
14
+ },
15
+ media: {
16
+ id: 1,
17
+ ipAddress: "149.154.175.211",
18
+ port: 443
19
+ }
20
+ },
21
+ 2: {
22
+ main: {
23
+ id: 2,
24
+ ipAddress: "149.154.167.41",
25
+ port: 443
26
+ },
27
+ media: {
28
+ id: 2,
29
+ ipAddress: "149.154.167.35",
30
+ port: 443
31
+ }
32
+ },
33
+ 3: {
34
+ main: {
35
+ id: 3,
36
+ ipAddress: "149.154.175.100",
37
+ port: 443
38
+ },
39
+ media: {
40
+ id: 3,
41
+ ipAddress: "149.154.175.100",
42
+ port: 443
43
+ }
44
+ },
45
+ 4: {
46
+ main: {
47
+ id: 4,
48
+ ipAddress: "149.154.167.91",
49
+ port: 443
50
+ },
51
+ media: {
52
+ id: 4,
53
+ ipAddress: "149.154.167.255",
54
+ port: 443
55
+ }
56
+ },
57
+ 5: {
58
+ main: {
59
+ id: 5,
60
+ ipAddress: "91.108.56.179",
61
+ port: 443
62
+ },
63
+ media: {
64
+ id: 5,
65
+ ipAddress: "149.154.171.255",
66
+ port: 443
67
+ }
68
+ }
69
+ };
70
+ const DC_MAPPING_TEST = {
71
+ 1: {
72
+ main: {
73
+ id: 1,
74
+ ipAddress: "149.154.175.10",
75
+ port: 80,
76
+ testMode: true
77
+ },
78
+ media: {
79
+ id: 1,
80
+ ipAddress: "149.154.175.10",
81
+ port: 80,
82
+ testMode: true
83
+ }
84
+ },
85
+ 2: {
86
+ main: {
87
+ id: 2,
88
+ ipAddress: "149.154.167.40",
89
+ port: 443,
90
+ testMode: true
91
+ },
92
+ media: {
93
+ id: 2,
94
+ ipAddress: "149.154.167.40",
95
+ port: 443,
96
+ testMode: true
97
+ }
98
+ },
99
+ 3: {
100
+ main: {
101
+ id: 3,
102
+ ipAddress: "149.154.175.117",
103
+ port: 443,
104
+ testMode: true
105
+ },
106
+ media: {
107
+ id: 3,
108
+ ipAddress: "149.154.175.117",
109
+ port: 443,
110
+ testMode: true
111
+ }
112
+ }
113
+ };
114
+ function isTestDc(ip) {
115
+ return Object.values(DC_MAPPING_TEST).some((dc) => dc.main.ipAddress === ip || dc.media.ipAddress === ip);
116
+ }
117
+ exports.DC_MAPPING_PROD = DC_MAPPING_PROD;
118
+ exports.DC_MAPPING_TEST = DC_MAPPING_TEST;
119
+ exports.isTestDc = isTestDc;
@@ -0,0 +1,114 @@
1
+ const DC_MAPPING_PROD = {
2
+ 1: {
3
+ main: {
4
+ id: 1,
5
+ ipAddress: "149.154.175.56",
6
+ port: 443
7
+ },
8
+ media: {
9
+ id: 1,
10
+ ipAddress: "149.154.175.211",
11
+ port: 443
12
+ }
13
+ },
14
+ 2: {
15
+ main: {
16
+ id: 2,
17
+ ipAddress: "149.154.167.41",
18
+ port: 443
19
+ },
20
+ media: {
21
+ id: 2,
22
+ ipAddress: "149.154.167.35",
23
+ port: 443
24
+ }
25
+ },
26
+ 3: {
27
+ main: {
28
+ id: 3,
29
+ ipAddress: "149.154.175.100",
30
+ port: 443
31
+ },
32
+ media: {
33
+ id: 3,
34
+ ipAddress: "149.154.175.100",
35
+ port: 443
36
+ }
37
+ },
38
+ 4: {
39
+ main: {
40
+ id: 4,
41
+ ipAddress: "149.154.167.91",
42
+ port: 443
43
+ },
44
+ media: {
45
+ id: 4,
46
+ ipAddress: "149.154.167.255",
47
+ port: 443
48
+ }
49
+ },
50
+ 5: {
51
+ main: {
52
+ id: 5,
53
+ ipAddress: "91.108.56.179",
54
+ port: 443
55
+ },
56
+ media: {
57
+ id: 5,
58
+ ipAddress: "149.154.171.255",
59
+ port: 443
60
+ }
61
+ }
62
+ };
63
+ const DC_MAPPING_TEST = {
64
+ 1: {
65
+ main: {
66
+ id: 1,
67
+ ipAddress: "149.154.175.10",
68
+ port: 80,
69
+ testMode: true
70
+ },
71
+ media: {
72
+ id: 1,
73
+ ipAddress: "149.154.175.10",
74
+ port: 80,
75
+ testMode: true
76
+ }
77
+ },
78
+ 2: {
79
+ main: {
80
+ id: 2,
81
+ ipAddress: "149.154.167.40",
82
+ port: 443,
83
+ testMode: true
84
+ },
85
+ media: {
86
+ id: 2,
87
+ ipAddress: "149.154.167.40",
88
+ port: 443,
89
+ testMode: true
90
+ }
91
+ },
92
+ 3: {
93
+ main: {
94
+ id: 3,
95
+ ipAddress: "149.154.175.117",
96
+ port: 443,
97
+ testMode: true
98
+ },
99
+ media: {
100
+ id: 3,
101
+ ipAddress: "149.154.175.117",
102
+ port: 443,
103
+ testMode: true
104
+ }
105
+ }
106
+ };
107
+ function isTestDc(ip) {
108
+ return Object.values(DC_MAPPING_TEST).some((dc) => dc.main.ipAddress === ip || dc.media.ipAddress === ip);
109
+ }
110
+ export {
111
+ DC_MAPPING_PROD,
112
+ DC_MAPPING_TEST,
113
+ isTestDc
114
+ };
@@ -0,0 +1,30 @@
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 utils_js = require("@mtcute/core/utils.js");
9
+ const convert = require("../telethon/convert.cjs");
10
+ const parse = require("./parse.cjs");
11
+ const serialize = require("./serialize.cjs");
12
+ function convertFromGramjsSession(session) {
13
+ if (typeof session === "string") {
14
+ session = parse.parseGramjsSession(session);
15
+ }
16
+ return convert.convertFromTelethonSession(session);
17
+ }
18
+ function convertToGramjsSession(session) {
19
+ if (typeof session === "string") {
20
+ session = utils_js.readStringSession(session);
21
+ }
22
+ return serialize.serializeGramjsSession({
23
+ dcId: session.primaryDcs.main.id,
24
+ ipAddress: session.primaryDcs.main.ipAddress,
25
+ port: session.primaryDcs.main.port,
26
+ authKey: session.authKey
27
+ });
28
+ }
29
+ exports.convertFromGramjsSession = convertFromGramjsSession;
30
+ exports.convertToGramjsSession = convertToGramjsSession;
@@ -0,0 +1,25 @@
1
+ import { readStringSession } from "@mtcute/core/utils.js";
2
+ import { convertFromTelethonSession } from "../telethon/convert.js";
3
+ import { parseGramjsSession } from "./parse.js";
4
+ import { serializeGramjsSession } from "./serialize.js";
5
+ function convertFromGramjsSession(session) {
6
+ if (typeof session === "string") {
7
+ session = parseGramjsSession(session);
8
+ }
9
+ return convertFromTelethonSession(session);
10
+ }
11
+ function convertToGramjsSession(session) {
12
+ if (typeof session === "string") {
13
+ session = readStringSession(session);
14
+ }
15
+ return serializeGramjsSession({
16
+ dcId: session.primaryDcs.main.id,
17
+ ipAddress: session.primaryDcs.main.ipAddress,
18
+ port: session.primaryDcs.main.port,
19
+ authKey: session.authKey
20
+ });
21
+ }
22
+ export {
23
+ convertFromGramjsSession,
24
+ convertToGramjsSession
25
+ };
@@ -0,0 +1,33 @@
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 utils = require("@fuman/utils");
9
+ const core = require("@mtcute/core");
10
+ function parseGramjsSession(session) {
11
+ if (session[0] !== "1") {
12
+ throw new core.MtArgumentError(`Invalid session string (version = ${session[0]})`);
13
+ }
14
+ session = session.slice(1);
15
+ const data = utils.base64.decode(session);
16
+ const dv = utils.typed.toDataView(data);
17
+ const dcId = dv.getUint8(0);
18
+ const ipSize = dv.getUint16(1);
19
+ let pos = 3 + ipSize;
20
+ const ip = utils.utf8.decoder.decode(data.subarray(3, pos));
21
+ const port = dv.getUint16(pos);
22
+ pos += 2;
23
+ const authKey = data.subarray(pos, pos + 256);
24
+ return {
25
+ dcId,
26
+ ipAddress: ip,
27
+ ipv6: ip.includes(":"),
28
+ // dumb check but gramjs does this
29
+ port,
30
+ authKey
31
+ };
32
+ }
33
+ exports.parseGramjsSession = parseGramjsSession;
@@ -0,0 +1,28 @@
1
+ import { base64, typed, utf8 } from "@fuman/utils";
2
+ import { MtArgumentError } from "@mtcute/core";
3
+ function parseGramjsSession(session) {
4
+ if (session[0] !== "1") {
5
+ throw new MtArgumentError(`Invalid session string (version = ${session[0]})`);
6
+ }
7
+ session = session.slice(1);
8
+ const data = base64.decode(session);
9
+ const dv = typed.toDataView(data);
10
+ const dcId = dv.getUint8(0);
11
+ const ipSize = dv.getUint16(1);
12
+ let pos = 3 + ipSize;
13
+ const ip = utf8.decoder.decode(data.subarray(3, pos));
14
+ const port = dv.getUint16(pos);
15
+ pos += 2;
16
+ const authKey = data.subarray(pos, pos + 256);
17
+ return {
18
+ dcId,
19
+ ipAddress: ip,
20
+ ipv6: ip.includes(":"),
21
+ // dumb check but gramjs does this
22
+ port,
23
+ authKey
24
+ };
25
+ }
26
+ export {
27
+ parseGramjsSession
28
+ };
@@ -0,0 +1,26 @@
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 utils = require("@fuman/utils");
9
+ const core = require("@mtcute/core");
10
+ function serializeGramjsSession(session) {
11
+ if (session.authKey.length !== 256) {
12
+ throw new core.MtArgumentError("authKey must be 256 bytes long");
13
+ }
14
+ const ipEncoded = utils.utf8.encoder.encode(session.ipAddress);
15
+ const u8 = new Uint8Array(261 + ipEncoded.length);
16
+ const dv = utils.typed.toDataView(u8);
17
+ dv.setUint8(0, session.dcId);
18
+ dv.setUint16(1, ipEncoded.length);
19
+ u8.set(ipEncoded, 3);
20
+ let pos = 3 + ipEncoded.length;
21
+ dv.setUint16(pos, session.port);
22
+ pos += 2;
23
+ u8.set(session.authKey, pos);
24
+ return `1${utils.base64.encode(u8)}`;
25
+ }
26
+ exports.serializeGramjsSession = serializeGramjsSession;
@@ -0,0 +1,21 @@
1
+ import { utf8, typed, base64 } from "@fuman/utils";
2
+ import { MtArgumentError } from "@mtcute/core";
3
+ function serializeGramjsSession(session) {
4
+ if (session.authKey.length !== 256) {
5
+ throw new MtArgumentError("authKey must be 256 bytes long");
6
+ }
7
+ const ipEncoded = utf8.encoder.encode(session.ipAddress);
8
+ const u8 = new Uint8Array(261 + ipEncoded.length);
9
+ const dv = typed.toDataView(u8);
10
+ dv.setUint8(0, session.dcId);
11
+ dv.setUint16(1, ipEncoded.length);
12
+ u8.set(ipEncoded, 3);
13
+ let pos = 3 + ipEncoded.length;
14
+ dv.setUint16(pos, session.port);
15
+ pos += 2;
16
+ u8.set(session.authKey, pos);
17
+ return `1${base64.encode(u8)}`;
18
+ }
19
+ export {
20
+ serializeGramjsSession
21
+ };
@@ -0,0 +1,33 @@
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 utils_js = require("@mtcute/core/utils.js");
9
+ const dcs = require("../dcs.cjs");
10
+ const parse = require("./parse.cjs");
11
+ const serialize = require("./serialize.cjs");
12
+ function convertFromMtkrutoSession(session) {
13
+ if (typeof session === "string") {
14
+ session = parse.parseMtkrutoSession(session);
15
+ }
16
+ return {
17
+ version: 3,
18
+ primaryDcs: (session.isTest ? dcs.DC_MAPPING_TEST : dcs.DC_MAPPING_PROD)[session.dcId],
19
+ authKey: session.authKey
20
+ };
21
+ }
22
+ function convertToMtkrutoSession(session) {
23
+ if (typeof session === "string") {
24
+ session = utils_js.readStringSession(session);
25
+ }
26
+ return serialize.serializeMtkrutoSession({
27
+ dcId: session.primaryDcs.main.id,
28
+ isTest: session.primaryDcs.main.testMode ?? false,
29
+ authKey: session.authKey
30
+ });
31
+ }
32
+ exports.convertFromMtkrutoSession = convertFromMtkrutoSession;
33
+ exports.convertToMtkrutoSession = convertToMtkrutoSession;
@@ -0,0 +1,28 @@
1
+ import { readStringSession } from "@mtcute/core/utils.js";
2
+ import { DC_MAPPING_TEST, DC_MAPPING_PROD } from "../dcs.js";
3
+ import { parseMtkrutoSession } from "./parse.js";
4
+ import { serializeMtkrutoSession } from "./serialize.js";
5
+ function convertFromMtkrutoSession(session) {
6
+ if (typeof session === "string") {
7
+ session = parseMtkrutoSession(session);
8
+ }
9
+ return {
10
+ version: 3,
11
+ primaryDcs: (session.isTest ? DC_MAPPING_TEST : DC_MAPPING_PROD)[session.dcId],
12
+ authKey: session.authKey
13
+ };
14
+ }
15
+ function convertToMtkrutoSession(session) {
16
+ if (typeof session === "string") {
17
+ session = readStringSession(session);
18
+ }
19
+ return serializeMtkrutoSession({
20
+ dcId: session.primaryDcs.main.id,
21
+ isTest: session.primaryDcs.main.testMode ?? false,
22
+ authKey: session.authKey
23
+ });
24
+ }
25
+ export {
26
+ convertFromMtkrutoSession,
27
+ convertToMtkrutoSession
28
+ };
@@ -0,0 +1,31 @@
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 utils = require("@fuman/utils");
9
+ const core = require("@mtcute/core");
10
+ const utils_js = require("@mtcute/core/utils.js");
11
+ const rle = require("../utils/rle.cjs");
12
+ function parseMtkrutoSession(session) {
13
+ const data = rle.telegramRleDecode(utils.base64.decode(session, true));
14
+ const reader = utils_js.TlBinaryReader.manual(data);
15
+ let dcIdStr = reader.string();
16
+ const authKey = reader.bytes();
17
+ const isTest = dcIdStr.endsWith("-test");
18
+ if (isTest) {
19
+ dcIdStr = dcIdStr.slice(0, -5);
20
+ }
21
+ const dcId = Number(dcIdStr);
22
+ if (Number.isNaN(dcId)) {
23
+ throw new core.MtArgumentError(`Invalid DC ID: ${dcIdStr}`);
24
+ }
25
+ return {
26
+ dcId,
27
+ isTest,
28
+ authKey
29
+ };
30
+ }
31
+ exports.parseMtkrutoSession = parseMtkrutoSession;
@@ -0,0 +1,26 @@
1
+ import { base64 } from "@fuman/utils";
2
+ import { MtArgumentError } from "@mtcute/core";
3
+ import { TlBinaryReader } from "@mtcute/core/utils.js";
4
+ import { telegramRleDecode } from "../utils/rle.js";
5
+ function parseMtkrutoSession(session) {
6
+ const data = telegramRleDecode(base64.decode(session, true));
7
+ const reader = TlBinaryReader.manual(data);
8
+ let dcIdStr = reader.string();
9
+ const authKey = reader.bytes();
10
+ const isTest = dcIdStr.endsWith("-test");
11
+ if (isTest) {
12
+ dcIdStr = dcIdStr.slice(0, -5);
13
+ }
14
+ const dcId = Number(dcIdStr);
15
+ if (Number.isNaN(dcId)) {
16
+ throw new MtArgumentError(`Invalid DC ID: ${dcIdStr}`);
17
+ }
18
+ return {
19
+ dcId,
20
+ isTest,
21
+ authKey
22
+ };
23
+ }
24
+ export {
25
+ parseMtkrutoSession
26
+ };
@@ -0,0 +1,18 @@
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 utils = require("@fuman/utils");
9
+ const utils_js = require("@mtcute/core/utils.js");
10
+ const rle = require("../utils/rle.cjs");
11
+ function serializeMtkrutoSession(session) {
12
+ const dcIdStr = `${session.dcId}${session.isTest ? "-test" : ""}`;
13
+ const writer = utils_js.TlBinaryWriter.manual(session.authKey.length + dcIdStr.length + 8);
14
+ writer.string(dcIdStr);
15
+ writer.bytes(session.authKey);
16
+ return utils.base64.encode(rle.telegramRleEncode(writer.result()), true);
17
+ }
18
+ exports.serializeMtkrutoSession = serializeMtkrutoSession;
@@ -0,0 +1,13 @@
1
+ import { base64 } from "@fuman/utils";
2
+ import { TlBinaryWriter } from "@mtcute/core/utils.js";
3
+ import { telegramRleEncode } from "../utils/rle.js";
4
+ function serializeMtkrutoSession(session) {
5
+ const dcIdStr = `${session.dcId}${session.isTest ? "-test" : ""}`;
6
+ const writer = TlBinaryWriter.manual(session.authKey.length + dcIdStr.length + 8);
7
+ writer.string(dcIdStr);
8
+ writer.bytes(session.authKey);
9
+ return base64.encode(telegramRleEncode(writer.result()), true);
10
+ }
11
+ export {
12
+ serializeMtkrutoSession
13
+ };
@@ -0,0 +1,42 @@
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 utils_js = require("@mtcute/core/utils.js");
9
+ const dcs = require("../dcs.cjs");
10
+ const parse = require("./parse.cjs");
11
+ const serialize = require("./serialize.cjs");
12
+ function convertFromPyrogramSession(session) {
13
+ if (typeof session === "string") {
14
+ session = parse.parsePyrogramSession(session);
15
+ }
16
+ return {
17
+ version: 3,
18
+ primaryDcs: (session.isTest ? dcs.DC_MAPPING_TEST : dcs.DC_MAPPING_PROD)[session.dcId],
19
+ authKey: session.authKey,
20
+ self: {
21
+ userId: session.userId,
22
+ isBot: session.isBot,
23
+ isPremium: false,
24
+ usernames: []
25
+ }
26
+ };
27
+ }
28
+ function convertToPyrogramSession(session, params) {
29
+ if (typeof session === "string") {
30
+ session = utils_js.readStringSession(session);
31
+ }
32
+ return serialize.serializePyrogramSession({
33
+ apiId: params?.apiId,
34
+ isBot: session.self?.isBot ?? false,
35
+ isTest: session.primaryDcs.main.testMode ?? false,
36
+ userId: session.self?.userId ?? 0,
37
+ dcId: session.primaryDcs.main.id,
38
+ authKey: session.authKey
39
+ });
40
+ }
41
+ exports.convertFromPyrogramSession = convertFromPyrogramSession;
42
+ exports.convertToPyrogramSession = convertToPyrogramSession;
@@ -0,0 +1,37 @@
1
+ import { readStringSession } from "@mtcute/core/utils.js";
2
+ import { DC_MAPPING_TEST, DC_MAPPING_PROD } from "../dcs.js";
3
+ import { parsePyrogramSession } from "./parse.js";
4
+ import { serializePyrogramSession } from "./serialize.js";
5
+ function convertFromPyrogramSession(session) {
6
+ if (typeof session === "string") {
7
+ session = parsePyrogramSession(session);
8
+ }
9
+ return {
10
+ version: 3,
11
+ primaryDcs: (session.isTest ? DC_MAPPING_TEST : DC_MAPPING_PROD)[session.dcId],
12
+ authKey: session.authKey,
13
+ self: {
14
+ userId: session.userId,
15
+ isBot: session.isBot,
16
+ isPremium: false,
17
+ usernames: []
18
+ }
19
+ };
20
+ }
21
+ function convertToPyrogramSession(session, params) {
22
+ if (typeof session === "string") {
23
+ session = readStringSession(session);
24
+ }
25
+ return serializePyrogramSession({
26
+ apiId: params?.apiId,
27
+ isBot: session.self?.isBot ?? false,
28
+ isTest: session.primaryDcs.main.testMode ?? false,
29
+ userId: session.self?.userId ?? 0,
30
+ dcId: session.primaryDcs.main.id,
31
+ authKey: session.authKey
32
+ });
33
+ }
34
+ export {
35
+ convertFromPyrogramSession,
36
+ convertToPyrogramSession
37
+ };