@mtcute/convert 0.8.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.
- package/LICENSE +8 -0
- package/README.md +46 -0
- package/cjs/dcs.d.ts +4 -0
- package/cjs/dcs.js +113 -0
- package/cjs/dcs.js.map +1 -0
- package/cjs/gramjs/convert.d.ts +4 -0
- package/cjs/gramjs/convert.js +29 -0
- package/cjs/gramjs/convert.js.map +1 -0
- package/cjs/gramjs/index.d.ts +4 -0
- package/cjs/gramjs/index.js +21 -0
- package/cjs/gramjs/index.js.map +1 -0
- package/cjs/gramjs/parse.d.ts +2 -0
- package/cjs/gramjs/parse.js +31 -0
- package/cjs/gramjs/parse.js.map +1 -0
- package/cjs/gramjs/serialize.d.ts +2 -0
- package/cjs/gramjs/serialize.js +24 -0
- package/cjs/gramjs/serialize.js.map +1 -0
- package/cjs/gramjs/types.d.ts +7 -0
- package/cjs/gramjs/types.js +3 -0
- package/cjs/gramjs/types.js.map +1 -0
- package/cjs/index.d.ts +5 -0
- package/cjs/index.js +22 -0
- package/cjs/index.js.map +1 -0
- package/cjs/mtkruto/convert.d.ts +4 -0
- package/cjs/mtkruto/convert.js +32 -0
- package/cjs/mtkruto/convert.js.map +1 -0
- package/cjs/mtkruto/index.d.ts +4 -0
- package/cjs/mtkruto/index.js +21 -0
- package/cjs/mtkruto/index.js.map +1 -0
- package/cjs/mtkruto/parse.d.ts +2 -0
- package/cjs/mtkruto/parse.js +28 -0
- package/cjs/mtkruto/parse.js.map +1 -0
- package/cjs/mtkruto/serialize.d.ts +2 -0
- package/cjs/mtkruto/serialize.js +15 -0
- package/cjs/mtkruto/serialize.js.map +1 -0
- package/cjs/mtkruto/types.d.ts +5 -0
- package/cjs/mtkruto/types.js +3 -0
- package/cjs/mtkruto/types.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/pyrogram/convert.d.ts +6 -0
- package/cjs/pyrogram/convert.js +41 -0
- package/cjs/pyrogram/convert.js.map +1 -0
- package/cjs/pyrogram/index.d.ts +4 -0
- package/cjs/pyrogram/index.js +21 -0
- package/cjs/pyrogram/index.js.map +1 -0
- package/cjs/pyrogram/parse.d.ts +2 -0
- package/cjs/pyrogram/parse.js +56 -0
- package/cjs/pyrogram/parse.js.map +1 -0
- package/cjs/pyrogram/serialize.d.ts +2 -0
- package/cjs/pyrogram/serialize.js +40 -0
- package/cjs/pyrogram/serialize.js.map +1 -0
- package/cjs/pyrogram/types.d.ts +8 -0
- package/cjs/pyrogram/types.js +3 -0
- package/cjs/pyrogram/types.js.map +1 -0
- package/cjs/telethon/convert.d.ts +4 -0
- package/cjs/telethon/convert.js +45 -0
- package/cjs/telethon/convert.js.map +1 -0
- package/cjs/telethon/index.d.ts +4 -0
- package/cjs/telethon/index.js +21 -0
- package/cjs/telethon/index.js.map +1 -0
- package/cjs/telethon/parse.d.ts +2 -0
- package/cjs/telethon/parse.js +33 -0
- package/cjs/telethon/parse.js.map +1 -0
- package/cjs/telethon/serialize.d.ts +2 -0
- package/cjs/telethon/serialize.js +34 -0
- package/cjs/telethon/serialize.js.map +1 -0
- package/cjs/telethon/types.d.ts +7 -0
- package/cjs/telethon/types.js +3 -0
- package/cjs/telethon/types.js.map +1 -0
- package/cjs/types.d.ts +1 -0
- package/cjs/types.js +3 -0
- package/cjs/types.js.map +1 -0
- package/cjs/utils/ip.d.ts +3 -0
- package/cjs/utils/ip.js +45 -0
- package/cjs/utils/ip.js.map +1 -0
- package/cjs/utils/rle.d.ts +3 -0
- package/cjs/utils/rle.js +55 -0
- package/cjs/utils/rle.js.map +1 -0
- package/esm/dcs.d.ts +4 -0
- package/esm/dcs.js +109 -0
- package/esm/dcs.js.map +1 -0
- package/esm/gramjs/convert.d.ts +4 -0
- package/esm/gramjs/convert.js +24 -0
- package/esm/gramjs/convert.js.map +1 -0
- package/esm/gramjs/index.d.ts +4 -0
- package/esm/gramjs/index.js +5 -0
- package/esm/gramjs/index.js.map +1 -0
- package/esm/gramjs/parse.d.ts +2 -0
- package/esm/gramjs/parse.js +27 -0
- package/esm/gramjs/parse.js.map +1 -0
- package/esm/gramjs/serialize.d.ts +2 -0
- package/esm/gramjs/serialize.js +20 -0
- package/esm/gramjs/serialize.js.map +1 -0
- package/esm/gramjs/types.d.ts +7 -0
- package/esm/gramjs/types.js +2 -0
- package/esm/gramjs/types.js.map +1 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +6 -0
- package/esm/index.js.map +1 -0
- package/esm/mtkruto/convert.d.ts +4 -0
- package/esm/mtkruto/convert.js +27 -0
- package/esm/mtkruto/convert.js.map +1 -0
- package/esm/mtkruto/index.d.ts +4 -0
- package/esm/mtkruto/index.js +5 -0
- package/esm/mtkruto/index.js.map +1 -0
- package/esm/mtkruto/parse.d.ts +2 -0
- package/esm/mtkruto/parse.js +24 -0
- package/esm/mtkruto/parse.js.map +1 -0
- package/esm/mtkruto/serialize.d.ts +2 -0
- package/esm/mtkruto/serialize.js +11 -0
- package/esm/mtkruto/serialize.js.map +1 -0
- package/esm/mtkruto/types.d.ts +5 -0
- package/esm/mtkruto/types.js +2 -0
- package/esm/mtkruto/types.js.map +1 -0
- package/esm/pyrogram/convert.d.ts +6 -0
- package/esm/pyrogram/convert.js +36 -0
- package/esm/pyrogram/convert.js.map +1 -0
- package/esm/pyrogram/index.d.ts +4 -0
- package/esm/pyrogram/index.js +5 -0
- package/esm/pyrogram/index.js.map +1 -0
- package/esm/pyrogram/parse.d.ts +2 -0
- package/esm/pyrogram/parse.js +52 -0
- package/esm/pyrogram/parse.js.map +1 -0
- package/esm/pyrogram/serialize.d.ts +2 -0
- package/esm/pyrogram/serialize.js +36 -0
- package/esm/pyrogram/serialize.js.map +1 -0
- package/esm/pyrogram/types.d.ts +8 -0
- package/esm/pyrogram/types.js +2 -0
- package/esm/pyrogram/types.js.map +1 -0
- package/esm/telethon/convert.d.ts +4 -0
- package/esm/telethon/convert.js +40 -0
- package/esm/telethon/convert.js.map +1 -0
- package/esm/telethon/index.d.ts +4 -0
- package/esm/telethon/index.js +5 -0
- package/esm/telethon/index.js.map +1 -0
- package/esm/telethon/parse.d.ts +2 -0
- package/esm/telethon/parse.js +29 -0
- package/esm/telethon/parse.js.map +1 -0
- package/esm/telethon/serialize.d.ts +2 -0
- package/esm/telethon/serialize.js +30 -0
- package/esm/telethon/serialize.js.map +1 -0
- package/esm/telethon/types.d.ts +7 -0
- package/esm/telethon/types.js +2 -0
- package/esm/telethon/types.js.map +1 -0
- package/esm/types.d.ts +1 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/esm/utils/ip.d.ts +3 -0
- package/esm/utils/ip.js +39 -0
- package/esm/utils/ip.js.map +1 -0
- package/esm/utils/rle.d.ts +3 -0
- package/esm/utils/rle.js +49 -0
- package/esm/utils/rle.js.map +1 -0
- package/package.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2023 Alina Sireneva
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @mtcute/convert
|
|
2
|
+
|
|
3
|
+
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_convert.html)
|
|
4
|
+
|
|
5
|
+
This package can be used to convert other libraries sessions to/from mtcute sessions
|
|
6
|
+
|
|
7
|
+
Currently only the libraries that support exporting sessions to strings are supported, namely:
|
|
8
|
+
|
|
9
|
+
## [Telethon](https://github.com/LonamiWebs/Telethon)
|
|
10
|
+
|
|
11
|
+
> Telethon v2 seems to have removed the ability to export sessions,
|
|
12
|
+
> so it's currently not supported
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { convertFromTelethonSession } from '@mtcute/convert'
|
|
16
|
+
|
|
17
|
+
const client = new TelegramClient({ ... })
|
|
18
|
+
await client.importSession(convertFromTelethonSession("..."))
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## [Pyrogram](https://github.com/pyrogram/pyrogram)
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { convertFromPyrogramSession } from '@mtcute/convert'
|
|
25
|
+
|
|
26
|
+
const client = new TelegramClient({ ... })
|
|
27
|
+
await client.importSession(convertFromPyrogramSession("..."))
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## [GramJS](https://github.com/gram-js/gramjs)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { convertFromGramjsSession } from '@mtcute/convert'
|
|
34
|
+
|
|
35
|
+
const client = new TelegramClient({ ... })
|
|
36
|
+
await client.importSession(convertFromGramjsSession("..."))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## [MTKruto](https://github.com/MTKruto/MTKruto)
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { convertFromMtkrutoSession } from '@mtcute/convert'
|
|
43
|
+
|
|
44
|
+
const client = new TelegramClient({ ... })
|
|
45
|
+
await client.importSession(convertFromMtkrutoSession("..."))
|
|
46
|
+
```
|
package/cjs/dcs.d.ts
ADDED
package/cjs/dcs.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTestDc = exports.DC_MAPPING_TEST = exports.DC_MAPPING_PROD = void 0;
|
|
4
|
+
// some libraries only store the DCs in the source code, so we need to map them to the correct DCs
|
|
5
|
+
// this may not be very accurate, but it's better than nothing
|
|
6
|
+
// we *could* always map those to the primary dc (the client should handle that gracefully),
|
|
7
|
+
// but imo it's better to be as accurate as possible
|
|
8
|
+
// we'll also only map to ipv4 since that's more portable
|
|
9
|
+
exports.DC_MAPPING_PROD = {
|
|
10
|
+
'1': {
|
|
11
|
+
main: {
|
|
12
|
+
id: 1,
|
|
13
|
+
ipAddress: '149.154.175.56',
|
|
14
|
+
port: 443,
|
|
15
|
+
},
|
|
16
|
+
media: {
|
|
17
|
+
id: 1,
|
|
18
|
+
ipAddress: '149.154.175.211',
|
|
19
|
+
port: 443,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
'2': {
|
|
23
|
+
main: {
|
|
24
|
+
id: 2,
|
|
25
|
+
ipAddress: '149.154.167.41',
|
|
26
|
+
port: 443,
|
|
27
|
+
},
|
|
28
|
+
media: {
|
|
29
|
+
id: 2,
|
|
30
|
+
ipAddress: '149.154.167.35',
|
|
31
|
+
port: 443,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
'3': {
|
|
35
|
+
main: {
|
|
36
|
+
id: 3,
|
|
37
|
+
ipAddress: '149.154.175.100',
|
|
38
|
+
port: 443,
|
|
39
|
+
},
|
|
40
|
+
media: {
|
|
41
|
+
id: 3,
|
|
42
|
+
ipAddress: '149.154.175.100',
|
|
43
|
+
port: 443,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
'4': {
|
|
47
|
+
main: {
|
|
48
|
+
id: 4,
|
|
49
|
+
ipAddress: '149.154.167.91',
|
|
50
|
+
port: 443,
|
|
51
|
+
},
|
|
52
|
+
media: {
|
|
53
|
+
id: 4,
|
|
54
|
+
ipAddress: '149.154.167.255',
|
|
55
|
+
port: 443,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
'5': {
|
|
59
|
+
main: {
|
|
60
|
+
id: 5,
|
|
61
|
+
ipAddress: '91.108.56.179',
|
|
62
|
+
port: 443,
|
|
63
|
+
},
|
|
64
|
+
media: {
|
|
65
|
+
id: 5,
|
|
66
|
+
ipAddress: '149.154.171.255',
|
|
67
|
+
port: 443,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
exports.DC_MAPPING_TEST = {
|
|
72
|
+
'1': {
|
|
73
|
+
main: {
|
|
74
|
+
id: 1,
|
|
75
|
+
ipAddress: '149.154.175.10',
|
|
76
|
+
port: 80,
|
|
77
|
+
},
|
|
78
|
+
media: {
|
|
79
|
+
id: 1,
|
|
80
|
+
ipAddress: '149.154.175.10',
|
|
81
|
+
port: 80,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
'2': {
|
|
85
|
+
main: {
|
|
86
|
+
id: 2,
|
|
87
|
+
ipAddress: '149.154.167.40',
|
|
88
|
+
port: 443,
|
|
89
|
+
},
|
|
90
|
+
media: {
|
|
91
|
+
id: 2,
|
|
92
|
+
ipAddress: '149.154.167.40',
|
|
93
|
+
port: 443,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
'3': {
|
|
97
|
+
main: {
|
|
98
|
+
id: 3,
|
|
99
|
+
ipAddress: '149.154.175.117',
|
|
100
|
+
port: 443,
|
|
101
|
+
},
|
|
102
|
+
media: {
|
|
103
|
+
id: 3,
|
|
104
|
+
ipAddress: '149.154.175.117',
|
|
105
|
+
port: 443,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
function isTestDc(ip) {
|
|
110
|
+
return Object.values(exports.DC_MAPPING_TEST).some((dc) => dc.main.ipAddress === ip || dc.media.ipAddress === ip);
|
|
111
|
+
}
|
|
112
|
+
exports.isTestDc = isTestDc;
|
|
113
|
+
//# sourceMappingURL=dcs.js.map
|
package/cjs/dcs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dcs.js","sourceRoot":"","sources":["../../src/dcs.ts"],"names":[],"mappings":";;;AAEA,kGAAkG;AAClG,8DAA8D;AAC9D,4FAA4F;AAC5F,oDAAoD;AACpD,yDAAyD;AAE5C,QAAA,eAAe,GAA8B;IACtD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,eAAe;YAC1B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;KACJ;CACJ,CAAA;AAEY,QAAA,eAAe,GAA8B;IACtD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,EAAE;SACX;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,EAAE;SACX;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,gBAAgB;YAC3B,IAAI,EAAE,GAAG;SACZ;KACJ;IACD,GAAG,EAAE;QACD,IAAI,EAAE;YACF,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;QACD,KAAK,EAAE;YACH,EAAE,EAAE,CAAC;YACL,SAAS,EAAE,iBAAiB;YAC5B,IAAI,EAAE,GAAG;SACZ;KACJ;CACJ,CAAA;AAED,SAAgB,QAAQ,CAAC,EAAU;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,uBAAe,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,EAAE,CAAC,CAAA;AAC7G,CAAC;AAFD,4BAEC","sourcesContent":["import { DcOptions } from '@mtcute/core/utils.js'\n\n// some libraries only store the DCs in the source code, so we need to map them to the correct DCs\n// this may not be very accurate, but it's better than nothing\n// we *could* always map those to the primary dc (the client should handle that gracefully),\n// but imo it's better to be as accurate as possible\n// we'll also only map to ipv4 since that's more portable\n\nexport const DC_MAPPING_PROD: Record<number, DcOptions> = {\n '1': {\n main: {\n id: 1,\n ipAddress: '149.154.175.56',\n port: 443,\n },\n media: {\n id: 1,\n ipAddress: '149.154.175.211',\n port: 443,\n },\n },\n '2': {\n main: {\n id: 2,\n ipAddress: '149.154.167.41',\n port: 443,\n },\n media: {\n id: 2,\n ipAddress: '149.154.167.35',\n port: 443,\n },\n },\n '3': {\n main: {\n id: 3,\n ipAddress: '149.154.175.100',\n port: 443,\n },\n media: {\n id: 3,\n ipAddress: '149.154.175.100',\n port: 443,\n },\n },\n '4': {\n main: {\n id: 4,\n ipAddress: '149.154.167.91',\n port: 443,\n },\n media: {\n id: 4,\n ipAddress: '149.154.167.255',\n port: 443,\n },\n },\n '5': {\n main: {\n id: 5,\n ipAddress: '91.108.56.179',\n port: 443,\n },\n media: {\n id: 5,\n ipAddress: '149.154.171.255',\n port: 443,\n },\n },\n}\n\nexport const DC_MAPPING_TEST: Record<number, DcOptions> = {\n '1': {\n main: {\n id: 1,\n ipAddress: '149.154.175.10',\n port: 80,\n },\n media: {\n id: 1,\n ipAddress: '149.154.175.10',\n port: 80,\n },\n },\n '2': {\n main: {\n id: 2,\n ipAddress: '149.154.167.40',\n port: 443,\n },\n media: {\n id: 2,\n ipAddress: '149.154.167.40',\n port: 443,\n },\n },\n '3': {\n main: {\n id: 3,\n ipAddress: '149.154.175.117',\n port: 443,\n },\n media: {\n id: 3,\n ipAddress: '149.154.175.117',\n port: 443,\n },\n },\n}\n\nexport function isTestDc(ip: string): boolean {\n return Object.values(DC_MAPPING_TEST).some((dc) => dc.main.ipAddress === ip || dc.media.ipAddress === ip)\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StringSessionData } from '@mtcute/core/utils.js';
|
|
2
|
+
import { TelethonSession } from '../telethon/types.js';
|
|
3
|
+
export declare function convertFromGramjsSession(session: TelethonSession | string): StringSessionData;
|
|
4
|
+
export declare function convertToGramjsSession(session: StringSessionData | string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToGramjsSession = exports.convertFromGramjsSession = void 0;
|
|
4
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
5
|
+
const reader_js_1 = require("@mtcute/tl/binary/reader.js");
|
|
6
|
+
const convert_js_1 = require("../telethon/convert.js");
|
|
7
|
+
const parse_js_1 = require("./parse.js");
|
|
8
|
+
const serialize_js_1 = require("./serialize.js");
|
|
9
|
+
function convertFromGramjsSession(session) {
|
|
10
|
+
if (typeof session === 'string') {
|
|
11
|
+
session = (0, parse_js_1.parseGramjsSession)(session);
|
|
12
|
+
}
|
|
13
|
+
return (0, convert_js_1.convertFromTelethonSession)(session);
|
|
14
|
+
}
|
|
15
|
+
exports.convertFromGramjsSession = convertFromGramjsSession;
|
|
16
|
+
function convertToGramjsSession(session) {
|
|
17
|
+
if (typeof session === 'string') {
|
|
18
|
+
session = (0, utils_js_1.readStringSession)(reader_js_1.__tlReaderMap, session);
|
|
19
|
+
}
|
|
20
|
+
return (0, serialize_js_1.serializeGramjsSession)({
|
|
21
|
+
dcId: session.primaryDcs.main.id,
|
|
22
|
+
ipAddress: session.primaryDcs.main.ipAddress,
|
|
23
|
+
port: session.primaryDcs.main.port,
|
|
24
|
+
ipv6: session.primaryDcs.main.ipv6 ?? false,
|
|
25
|
+
authKey: session.authKey,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.convertToGramjsSession = convertToGramjsSession;
|
|
29
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/gramjs/convert.ts"],"names":[],"mappings":";;;AAAA,oDAA4E;AAC5E,2DAA2D;AAE3D,uDAAmE;AAEnE,yCAA+C;AAC/C,iDAAuD;AAEvD,SAAgB,wBAAwB,CAAC,OAAiC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,6BAAkB,EAAC,OAAO,CAAC,CAAA;KACxC;IAED,OAAO,IAAA,uCAA0B,EAAC,OAAO,CAAC,CAAA;AAC9C,CAAC;AAND,4DAMC;AAED,SAAgB,sBAAsB,CAAC,OAAmC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,4BAAiB,EAAC,yBAAa,EAAE,OAAO,CAAC,CAAA;KACtD;IAED,OAAO,IAAA,qCAAsB,EAAC;QAC1B,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS;QAC5C,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI;QAClC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAC,CAAA;AACN,CAAC;AAZD,wDAYC","sourcesContent":["import { readStringSession, StringSessionData } from '@mtcute/core/utils.js'\nimport { __tlReaderMap } from '@mtcute/tl/binary/reader.js'\n\nimport { convertFromTelethonSession } from '../telethon/convert.js'\nimport { TelethonSession } from '../telethon/types.js'\nimport { parseGramjsSession } from './parse.js'\nimport { serializeGramjsSession } from './serialize.js'\n\nexport function convertFromGramjsSession(session: TelethonSession | string): StringSessionData {\n if (typeof session === 'string') {\n session = parseGramjsSession(session)\n }\n\n return convertFromTelethonSession(session)\n}\n\nexport function convertToGramjsSession(session: StringSessionData | string): string {\n if (typeof session === 'string') {\n session = readStringSession(__tlReaderMap, session)\n }\n\n return serializeGramjsSession({\n dcId: session.primaryDcs.main.id,\n ipAddress: session.primaryDcs.main.ipAddress,\n port: session.primaryDcs.main.port,\n ipv6: session.primaryDcs.main.ipv6 ?? false,\n authKey: session.authKey,\n })\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./convert.js"), exports);
|
|
18
|
+
__exportStar(require("./parse.js"), exports);
|
|
19
|
+
__exportStar(require("./serialize.js"), exports);
|
|
20
|
+
__exportStar(require("./types.js"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gramjs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,6CAA0B;AAC1B,iDAA8B;AAC9B,6CAA0B","sourcesContent":["export * from './convert.js'\nexport * from './parse.js'\nexport * from './serialize.js'\nexport * from './types.js'\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGramjsSession = void 0;
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
|
+
const platform_js_1 = require("@mtcute/core/platform.js");
|
|
6
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
7
|
+
function parseGramjsSession(session) {
|
|
8
|
+
if (session[0] !== '1') {
|
|
9
|
+
// version
|
|
10
|
+
throw new core_1.MtArgumentError(`Invalid session string (version = ${session[0]})`);
|
|
11
|
+
}
|
|
12
|
+
session = session.slice(1);
|
|
13
|
+
const data = (0, platform_js_1.getPlatform)().base64Decode(session);
|
|
14
|
+
const dv = (0, utils_js_1.dataViewFromBuffer)(data);
|
|
15
|
+
const dcId = dv.getUint8(0);
|
|
16
|
+
const ipSize = dv.getUint16(1);
|
|
17
|
+
let pos = 3 + ipSize;
|
|
18
|
+
const ip = (0, platform_js_1.getPlatform)().utf8Decode(data.subarray(3, pos));
|
|
19
|
+
const port = dv.getUint16(pos);
|
|
20
|
+
pos += 2;
|
|
21
|
+
const authKey = data.subarray(pos, pos + 256);
|
|
22
|
+
return {
|
|
23
|
+
dcId,
|
|
24
|
+
ipAddress: ip,
|
|
25
|
+
ipv6: ip.includes(':'),
|
|
26
|
+
port,
|
|
27
|
+
authKey,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.parseGramjsSession = parseGramjsSession;
|
|
31
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/gramjs/parse.ts"],"names":[],"mappings":";;;AAAA,uCAA8C;AAC9C,0DAAsD;AACtD,oDAA0D;AAI1D,SAAgB,kBAAkB,CAAC,OAAe;IAC9C,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACpB,UAAU;QACV,MAAM,IAAI,sBAAe,CAAC,qCAAqC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;KAChF;IAED,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE1B,MAAM,IAAI,GAAG,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;IAChD,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAA;IAEnC,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAE3B,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAC9B,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,CAAA;IAEpB,MAAM,EAAE,GAAG,IAAA,yBAAW,GAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;IAC1D,MAAM,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IAC9B,GAAG,IAAI,CAAC,CAAA;IACR,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,CAAA;IAE7C,OAAO;QACH,IAAI;QACJ,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtB,IAAI;QACJ,OAAO;KACV,CAAA;AACL,CAAC;AA5BD,gDA4BC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport { TelethonSession } from '../telethon/types.js'\n\nexport function parseGramjsSession(session: string): TelethonSession {\n if (session[0] !== '1') {\n // version\n throw new MtArgumentError(`Invalid session string (version = ${session[0]})`)\n }\n\n session = session.slice(1)\n\n const data = getPlatform().base64Decode(session)\n const dv = dataViewFromBuffer(data)\n\n const dcId = dv.getUint8(0)\n\n const ipSize = dv.getUint16(1)\n let pos = 3 + ipSize\n\n const ip = getPlatform().utf8Decode(data.subarray(3, pos))\n const port = dv.getUint16(pos)\n pos += 2\n const authKey = data.subarray(pos, pos + 256)\n\n return {\n dcId,\n ipAddress: ip,\n ipv6: ip.includes(':'), // dumb check but gramjs does this\n port,\n authKey,\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeGramjsSession = void 0;
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
|
+
const platform_js_1 = require("@mtcute/core/platform.js");
|
|
6
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
7
|
+
function serializeGramjsSession(session) {
|
|
8
|
+
if (session.authKey.length !== 256) {
|
|
9
|
+
throw new core_1.MtArgumentError('authKey must be 256 bytes long');
|
|
10
|
+
}
|
|
11
|
+
const ipEncoded = (0, platform_js_1.getPlatform)().utf8Encode(session.ipAddress);
|
|
12
|
+
const u8 = new Uint8Array(261 + ipEncoded.length);
|
|
13
|
+
const dv = (0, utils_js_1.dataViewFromBuffer)(u8);
|
|
14
|
+
dv.setUint8(0, session.dcId);
|
|
15
|
+
dv.setUint16(1, ipEncoded.length);
|
|
16
|
+
u8.set(ipEncoded, 3);
|
|
17
|
+
let pos = 3 + ipEncoded.length;
|
|
18
|
+
dv.setUint16(pos, session.port);
|
|
19
|
+
pos += 2;
|
|
20
|
+
u8.set(session.authKey, pos);
|
|
21
|
+
return '1' + (0, platform_js_1.getPlatform)().base64Encode(u8);
|
|
22
|
+
}
|
|
23
|
+
exports.serializeGramjsSession = serializeGramjsSession;
|
|
24
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/gramjs/serialize.ts"],"names":[],"mappings":";;;AAAA,uCAA8C;AAC9C,0DAAsD;AACtD,oDAA0D;AAI1D,SAAgB,sBAAsB,CAAC,OAAwB;IAC3D,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE;QAChC,MAAM,IAAI,sBAAe,CAAC,gCAAgC,CAAC,CAAA;KAC9D;IAED,MAAM,SAAS,GAAG,IAAA,yBAAW,GAAE,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IAE7D,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IACjD,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAA;IAEjC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IACjC,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IAEpB,IAAI,GAAG,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAA;IAE9B,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,GAAG,IAAI,CAAC,CAAA;IACR,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE5B,OAAO,GAAG,GAAG,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;AAC/C,CAAC;AArBD,wDAqBC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport { TelethonSession } from '../telethon/types.js'\n\nexport function serializeGramjsSession(session: TelethonSession) {\n if (session.authKey.length !== 256) {\n throw new MtArgumentError('authKey must be 256 bytes long')\n }\n\n const ipEncoded = getPlatform().utf8Encode(session.ipAddress)\n\n const u8 = new Uint8Array(261 + ipEncoded.length)\n const dv = dataViewFromBuffer(u8)\n\n dv.setUint8(0, session.dcId)\n dv.setUint16(1, ipEncoded.length)\n u8.set(ipEncoded, 3)\n\n let pos = 3 + ipEncoded.length\n\n dv.setUint16(pos, session.port)\n pos += 2\n u8.set(session.authKey, pos)\n\n return '1' + getPlatform().base64Encode(u8)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/gramjs/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface GramjsSession {\n dcId: number\n ipAddress: string\n ipv6: boolean\n port: number\n authKey: Uint8Array\n}\n"]}
|
package/cjs/index.d.ts
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dcs.js"), exports);
|
|
18
|
+
__exportStar(require("./gramjs/index.js"), exports);
|
|
19
|
+
__exportStar(require("./mtkruto/index.js"), exports);
|
|
20
|
+
__exportStar(require("./pyrogram/index.js"), exports);
|
|
21
|
+
__exportStar(require("./telethon/index.js"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,oDAAiC;AACjC,qDAAkC;AAClC,sDAAmC;AACnC,sDAAmC","sourcesContent":["export * from './dcs.js'\nexport * from './gramjs/index.js'\nexport * from './mtkruto/index.js'\nexport * from './pyrogram/index.js'\nexport * from './telethon/index.js'\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StringSessionData } from '@mtcute/core/utils.js';
|
|
2
|
+
import { MtkrutoSession } from './types.js';
|
|
3
|
+
export declare function convertFromMtkrutoSession(session: MtkrutoSession | string): StringSessionData;
|
|
4
|
+
export declare function convertToMtkrutoSession(session: StringSessionData | string): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToMtkrutoSession = exports.convertFromMtkrutoSession = void 0;
|
|
4
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
5
|
+
const reader_js_1 = require("@mtcute/tl/binary/reader.js");
|
|
6
|
+
const dcs_js_1 = require("../dcs.js");
|
|
7
|
+
const parse_js_1 = require("./parse.js");
|
|
8
|
+
const serialize_js_1 = require("./serialize.js");
|
|
9
|
+
function convertFromMtkrutoSession(session) {
|
|
10
|
+
if (typeof session === 'string') {
|
|
11
|
+
session = (0, parse_js_1.parseMtkrutoSession)(session);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
version: 3,
|
|
15
|
+
testMode: session.isTest,
|
|
16
|
+
primaryDcs: (session.isTest ? dcs_js_1.DC_MAPPING_TEST : dcs_js_1.DC_MAPPING_PROD)[session.dcId],
|
|
17
|
+
authKey: session.authKey,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.convertFromMtkrutoSession = convertFromMtkrutoSession;
|
|
21
|
+
function convertToMtkrutoSession(session) {
|
|
22
|
+
if (typeof session === 'string') {
|
|
23
|
+
session = (0, utils_js_1.readStringSession)(reader_js_1.__tlReaderMap, session);
|
|
24
|
+
}
|
|
25
|
+
return (0, serialize_js_1.serializeMtkrutoSession)({
|
|
26
|
+
dcId: session.primaryDcs.main.id,
|
|
27
|
+
isTest: session.testMode,
|
|
28
|
+
authKey: session.authKey,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.convertToMtkrutoSession = convertToMtkrutoSession;
|
|
32
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/mtkruto/convert.ts"],"names":[],"mappings":";;;AAAA,oDAA4E;AAC5E,2DAA2D;AAE3D,sCAA4D;AAC5D,yCAAgD;AAChD,iDAAwD;AAGxD,SAAgB,yBAAyB,CAAC,OAAgC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,8BAAmB,EAAC,OAAO,CAAC,CAAA;KACzC;IAED,OAAO;QACH,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,UAAU,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,wBAAe,CAAC,CAAC,CAAC,wBAAe,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAC9E,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAA;AACL,CAAC;AAXD,8DAWC;AAED,SAAgB,uBAAuB,CAAC,OAAmC;IACvE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,4BAAiB,EAAC,yBAAa,EAAE,OAAO,CAAC,CAAA;KACtD;IAED,OAAO,IAAA,sCAAuB,EAAC;QAC3B,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,MAAM,EAAE,OAAO,CAAC,QAAQ;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAC,CAAA;AACN,CAAC;AAVD,0DAUC","sourcesContent":["import { readStringSession, StringSessionData } from '@mtcute/core/utils.js'\nimport { __tlReaderMap } from '@mtcute/tl/binary/reader.js'\n\nimport { DC_MAPPING_PROD, DC_MAPPING_TEST } from '../dcs.js'\nimport { parseMtkrutoSession } from './parse.js'\nimport { serializeMtkrutoSession } from './serialize.js'\nimport { MtkrutoSession } from './types.js'\n\nexport function convertFromMtkrutoSession(session: MtkrutoSession | string): StringSessionData {\n if (typeof session === 'string') {\n session = parseMtkrutoSession(session)\n }\n\n return {\n version: 3,\n testMode: session.isTest,\n primaryDcs: (session.isTest ? DC_MAPPING_TEST : DC_MAPPING_PROD)[session.dcId],\n authKey: session.authKey,\n }\n}\n\nexport function convertToMtkrutoSession(session: StringSessionData | string): string {\n if (typeof session === 'string') {\n session = readStringSession(__tlReaderMap, session)\n }\n\n return serializeMtkrutoSession({\n dcId: session.primaryDcs.main.id,\n isTest: session.testMode,\n authKey: session.authKey,\n })\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./convert.js"), exports);
|
|
18
|
+
__exportStar(require("./parse.js"), exports);
|
|
19
|
+
__exportStar(require("./serialize.js"), exports);
|
|
20
|
+
__exportStar(require("./types.js"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mtkruto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,6CAA0B;AAC1B,iDAA8B;AAC9B,6CAA0B","sourcesContent":["export * from './convert.js'\nexport * from './parse.js'\nexport * from './serialize.js'\nexport * from './types.js'\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMtkrutoSession = void 0;
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
|
+
const platform_js_1 = require("@mtcute/core/platform.js");
|
|
6
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
7
|
+
const rle_js_1 = require("../utils/rle.js");
|
|
8
|
+
function parseMtkrutoSession(session) {
|
|
9
|
+
const data = (0, rle_js_1.telegramRleDecode)((0, platform_js_1.getPlatform)().base64Decode(session, true));
|
|
10
|
+
const reader = utils_js_1.TlBinaryReader.manual(data);
|
|
11
|
+
let dcIdStr = reader.string();
|
|
12
|
+
const authKey = reader.bytes();
|
|
13
|
+
const isTest = dcIdStr.endsWith('-test');
|
|
14
|
+
if (isTest) {
|
|
15
|
+
dcIdStr = dcIdStr.slice(0, -5);
|
|
16
|
+
}
|
|
17
|
+
const dcId = Number(dcIdStr);
|
|
18
|
+
if (isNaN(dcId)) {
|
|
19
|
+
throw new core_1.MtArgumentError(`Invalid DC ID: ${dcIdStr}`);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
dcId,
|
|
23
|
+
isTest,
|
|
24
|
+
authKey,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.parseMtkrutoSession = parseMtkrutoSession;
|
|
28
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/mtkruto/parse.ts"],"names":[],"mappings":";;;AAAA,uCAA8C;AAC9C,0DAAsD;AACtD,oDAAsD;AAEtD,4CAAmD;AAGnD,SAAgB,mBAAmB,CAAC,OAAe;IAC/C,MAAM,IAAI,GAAG,IAAA,0BAAiB,EAAC,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;IACzE,MAAM,MAAM,GAAG,yBAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAE1C,IAAI,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;IAE9B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAExC,IAAI,MAAM,EAAE;QACR,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;KACjC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAE5B,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACb,MAAM,IAAI,sBAAe,CAAC,kBAAkB,OAAO,EAAE,CAAC,CAAA;KACzD;IAED,OAAO;QACH,IAAI;QACJ,MAAM;QACN,OAAO;KACV,CAAA;AACL,CAAC;AAvBD,kDAuBC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { TlBinaryReader } from '@mtcute/core/utils.js'\n\nimport { telegramRleDecode } from '../utils/rle.js'\nimport { MtkrutoSession } from './types.js'\n\nexport function parseMtkrutoSession(session: string): MtkrutoSession {\n const data = telegramRleDecode(getPlatform().base64Decode(session, true))\n const reader = TlBinaryReader.manual(data)\n\n let dcIdStr = reader.string()\n const authKey = reader.bytes()\n\n const isTest = dcIdStr.endsWith('-test')\n\n if (isTest) {\n dcIdStr = dcIdStr.slice(0, -5)\n }\n const dcId = Number(dcIdStr)\n\n if (isNaN(dcId)) {\n throw new MtArgumentError(`Invalid DC ID: ${dcIdStr}`)\n }\n\n return {\n dcId,\n isTest,\n authKey,\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeMtkrutoSession = void 0;
|
|
4
|
+
const platform_js_1 = require("@mtcute/core/platform.js");
|
|
5
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
6
|
+
const rle_js_1 = require("../utils/rle.js");
|
|
7
|
+
function serializeMtkrutoSession(session) {
|
|
8
|
+
const dcIdStr = `${session.dcId}${session.isTest ? '-test' : ''}`;
|
|
9
|
+
const writer = utils_js_1.TlBinaryWriter.manual(session.authKey.length + dcIdStr.length + 8);
|
|
10
|
+
writer.string(dcIdStr);
|
|
11
|
+
writer.bytes(session.authKey);
|
|
12
|
+
return (0, platform_js_1.getPlatform)().base64Encode((0, rle_js_1.telegramRleEncode)(writer.result()), true);
|
|
13
|
+
}
|
|
14
|
+
exports.serializeMtkrutoSession = serializeMtkrutoSession;
|
|
15
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/mtkruto/serialize.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AACtD,oDAAsD;AAEtD,4CAAmD;AAGnD,SAAgB,uBAAuB,CAAC,OAAuB;IAC3D,MAAM,OAAO,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;IAEjE,MAAM,MAAM,GAAG,yBAAc,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEjF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACtB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE7B,OAAO,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,IAAA,0BAAiB,EAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;AAC/E,CAAC;AATD,0DASC","sourcesContent":["import { getPlatform } from '@mtcute/core/platform.js'\nimport { TlBinaryWriter } from '@mtcute/core/utils.js'\n\nimport { telegramRleEncode } from '../utils/rle.js'\nimport { MtkrutoSession } from './types.js'\n\nexport function serializeMtkrutoSession(session: MtkrutoSession): string {\n const dcIdStr = `${session.dcId}${session.isTest ? '-test' : ''}`\n\n const writer = TlBinaryWriter.manual(session.authKey.length + dcIdStr.length + 8)\n\n writer.string(dcIdStr)\n writer.bytes(session.authKey)\n\n return getPlatform().base64Encode(telegramRleEncode(writer.result()), true)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/mtkruto/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface MtkrutoSession {\n dcId: number\n isTest: boolean\n authKey: Uint8Array\n}\n"]}
|
package/cjs/package.json
ADDED
|
@@ -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,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToPyrogramSession = exports.convertFromPyrogramSession = void 0;
|
|
4
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
5
|
+
const reader_js_1 = require("@mtcute/tl/binary/reader.js");
|
|
6
|
+
const dcs_js_1 = require("../dcs.js");
|
|
7
|
+
const parse_js_1 = require("./parse.js");
|
|
8
|
+
const serialize_js_1 = require("./serialize.js");
|
|
9
|
+
function convertFromPyrogramSession(session) {
|
|
10
|
+
if (typeof session === 'string') {
|
|
11
|
+
session = (0, parse_js_1.parsePyrogramSession)(session);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
version: 3,
|
|
15
|
+
testMode: session.isTest,
|
|
16
|
+
primaryDcs: (session.isTest ? dcs_js_1.DC_MAPPING_TEST : dcs_js_1.DC_MAPPING_PROD)[session.dcId],
|
|
17
|
+
authKey: session.authKey,
|
|
18
|
+
self: {
|
|
19
|
+
userId: session.userId,
|
|
20
|
+
isBot: session.isBot,
|
|
21
|
+
isPremium: false,
|
|
22
|
+
usernames: [],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.convertFromPyrogramSession = convertFromPyrogramSession;
|
|
27
|
+
function convertToPyrogramSession(session, params) {
|
|
28
|
+
if (typeof session === 'string') {
|
|
29
|
+
session = (0, utils_js_1.readStringSession)(reader_js_1.__tlReaderMap, session);
|
|
30
|
+
}
|
|
31
|
+
return (0, serialize_js_1.serializePyrogramSession)({
|
|
32
|
+
apiId: params?.apiId,
|
|
33
|
+
isBot: session.self?.isBot ?? false,
|
|
34
|
+
isTest: session.testMode,
|
|
35
|
+
userId: session.self?.userId ?? 0,
|
|
36
|
+
dcId: session.primaryDcs.main.id,
|
|
37
|
+
authKey: session.authKey,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.convertToPyrogramSession = convertToPyrogramSession;
|
|
41
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/pyrogram/convert.ts"],"names":[],"mappings":";;;AAAA,oDAA4E;AAC5E,2DAA2D;AAE3D,sCAA4D;AAC5D,yCAAiD;AACjD,iDAAyD;AAGzD,SAAgB,0BAA0B,CAAC,OAAiC;IACxE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,+BAAoB,EAAC,OAAO,CAAC,CAAA;KAC1C;IAED,OAAO;QACH,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,UAAU,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,wBAAe,CAAC,CAAC,CAAC,wBAAe,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAC9E,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE;YACF,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,SAAS,EAAE,KAAK;YAChB,SAAS,EAAE,EAAE;SAChB;KACJ,CAAA;AACL,CAAC;AAjBD,gEAiBC;AAED,SAAgB,wBAAwB,CACpC,OAAmC,EACnC,MAEC;IAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC7B,OAAO,GAAG,IAAA,4BAAiB,EAAC,yBAAa,EAAE,OAAO,CAAC,CAAA;KACtD;IAED,OAAO,IAAA,uCAAwB,EAAC;QAC5B,KAAK,EAAE,MAAM,EAAE,KAAK;QACpB,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,IAAI,KAAK;QACnC,MAAM,EAAE,OAAO,CAAC,QAAQ;QACxB,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;QACjC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAC,CAAA;AACN,CAAC;AAlBD,4DAkBC","sourcesContent":["import { readStringSession, StringSessionData } from '@mtcute/core/utils.js'\nimport { __tlReaderMap } from '@mtcute/tl/binary/reader.js'\n\nimport { DC_MAPPING_PROD, DC_MAPPING_TEST } from '../dcs.js'\nimport { parsePyrogramSession } from './parse.js'\nimport { serializePyrogramSession } from './serialize.js'\nimport { PyrogramSession } from './types.js'\n\nexport function convertFromPyrogramSession(session: PyrogramSession | string): StringSessionData {\n if (typeof session === 'string') {\n session = parsePyrogramSession(session)\n }\n\n return {\n version: 3,\n testMode: session.isTest,\n primaryDcs: (session.isTest ? DC_MAPPING_TEST : DC_MAPPING_PROD)[session.dcId],\n authKey: session.authKey,\n self: {\n userId: session.userId,\n isBot: session.isBot,\n isPremium: false,\n usernames: [],\n },\n }\n}\n\nexport function convertToPyrogramSession(\n session: StringSessionData | string,\n params?: {\n apiId?: number\n },\n): string {\n if (typeof session === 'string') {\n session = readStringSession(__tlReaderMap, session)\n }\n\n return serializePyrogramSession({\n apiId: params?.apiId,\n isBot: session.self?.isBot ?? false,\n isTest: session.testMode,\n userId: session.self?.userId ?? 0,\n dcId: session.primaryDcs.main.id,\n authKey: session.authKey,\n })\n}\n"]}
|