@mtcute/convert 0.16.7 → 0.16.9
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/{cjs/dcs.d.ts → dcs.d.ts} +1 -1
- package/gramjs/__fixtures__/session.d.ts +1 -0
- package/{esm/gramjs → gramjs}/convert.d.ts +2 -2
- package/{cjs/gramjs → gramjs}/parse.d.ts +1 -1
- package/{cjs/gramjs → gramjs}/serialize.d.ts +1 -1
- package/gramjs/serialize.test.d.ts +1 -0
- package/index.cjs +493 -0
- package/index.d.ts +5 -1
- package/index.js +488 -1
- package/mtkruto/__fixtures__/session.d.ts +1 -0
- package/{cjs/mtkruto → mtkruto}/convert.d.ts +2 -2
- package/mtkruto/convert.test.d.ts +1 -0
- package/{esm/mtkruto → mtkruto}/parse.d.ts +1 -1
- package/mtkruto/parse.test.d.ts +1 -0
- package/{cjs/mtkruto → mtkruto}/serialize.d.ts +1 -1
- package/mtkruto/serialize.test.d.ts +1 -0
- package/package.json +27 -23
- package/pyrogram/__fixtures__/session.d.ts +1 -0
- package/pyrogram/__fixtures__/session_old.d.ts +1 -0
- package/{esm/pyrogram → pyrogram}/convert.d.ts +2 -2
- package/pyrogram/convert.test.d.ts +1 -0
- package/{esm/pyrogram → pyrogram}/parse.d.ts +1 -1
- package/pyrogram/parse.test.d.ts +1 -0
- package/{esm/pyrogram → pyrogram}/serialize.d.ts +1 -1
- package/pyrogram/serialize.test.d.ts +1 -0
- package/telethon/__fixtures__/session.d.ts +1 -0
- package/telethon/__fixtures__/session_v6.d.ts +1 -0
- package/{esm/telethon → telethon}/convert.d.ts +2 -2
- package/telethon/convert.test.d.ts +1 -0
- package/{esm/telethon → telethon}/parse.d.ts +1 -1
- package/telethon/parse.test.d.ts +1 -0
- package/{esm/telethon → telethon}/serialize.d.ts +1 -1
- package/telethon/serialize.test.d.ts +1 -0
- package/types.d.ts +0 -0
- package/cjs/dcs.js +0 -113
- package/cjs/dcs.js.map +0 -1
- package/cjs/gramjs/convert.d.ts +0 -4
- package/cjs/gramjs/convert.js +0 -27
- package/cjs/gramjs/convert.js.map +0 -1
- package/cjs/gramjs/index.js +0 -21
- package/cjs/gramjs/index.js.map +0 -1
- package/cjs/gramjs/parse.js +0 -30
- package/cjs/gramjs/parse.js.map +0 -1
- package/cjs/gramjs/serialize.js +0 -23
- package/cjs/gramjs/serialize.js.map +0 -1
- package/cjs/gramjs/types.js +0 -3
- package/cjs/gramjs/types.js.map +0 -1
- package/cjs/index.js +0 -28
- package/cjs/index.js.map +0 -1
- package/cjs/mtkruto/convert.js +0 -30
- package/cjs/mtkruto/convert.js.map +0 -1
- package/cjs/mtkruto/index.js +0 -21
- package/cjs/mtkruto/index.js.map +0 -1
- package/cjs/mtkruto/parse.d.ts +0 -2
- package/cjs/mtkruto/parse.js +0 -27
- package/cjs/mtkruto/parse.js.map +0 -1
- package/cjs/mtkruto/serialize.js +0 -14
- package/cjs/mtkruto/serialize.js.map +0 -1
- package/cjs/mtkruto/types.js +0 -3
- package/cjs/mtkruto/types.js.map +0 -1
- package/cjs/package.json +0 -3
- package/cjs/pyrogram/convert.d.ts +0 -6
- package/cjs/pyrogram/convert.js +0 -39
- package/cjs/pyrogram/convert.js.map +0 -1
- package/cjs/pyrogram/index.js +0 -21
- package/cjs/pyrogram/index.js.map +0 -1
- package/cjs/pyrogram/parse.d.ts +0 -2
- package/cjs/pyrogram/parse.js +0 -55
- package/cjs/pyrogram/parse.js.map +0 -1
- package/cjs/pyrogram/serialize.d.ts +0 -2
- package/cjs/pyrogram/serialize.js +0 -39
- package/cjs/pyrogram/serialize.js.map +0 -1
- package/cjs/pyrogram/types.js +0 -3
- package/cjs/pyrogram/types.js.map +0 -1
- package/cjs/telethon/convert.d.ts +0 -4
- package/cjs/telethon/convert.js +0 -43
- package/cjs/telethon/convert.js.map +0 -1
- package/cjs/telethon/index.js +0 -21
- package/cjs/telethon/index.js.map +0 -1
- package/cjs/telethon/parse.d.ts +0 -2
- package/cjs/telethon/parse.js +0 -32
- package/cjs/telethon/parse.js.map +0 -1
- package/cjs/telethon/serialize.d.ts +0 -2
- package/cjs/telethon/serialize.js +0 -33
- package/cjs/telethon/serialize.js.map +0 -1
- package/cjs/telethon/types.js +0 -3
- package/cjs/telethon/types.js.map +0 -1
- package/cjs/types.js +0 -3
- package/cjs/types.js.map +0 -1
- package/cjs/utils/ip.js +0 -44
- package/cjs/utils/ip.js.map +0 -1
- package/cjs/utils/rle.js +0 -54
- package/cjs/utils/rle.js.map +0 -1
- package/esm/dcs.d.ts +0 -4
- package/esm/dcs.js +0 -109
- package/esm/dcs.js.map +0 -1
- package/esm/gramjs/convert.js +0 -23
- package/esm/gramjs/convert.js.map +0 -1
- package/esm/gramjs/index.d.ts +0 -4
- package/esm/gramjs/index.js +0 -5
- package/esm/gramjs/index.js.map +0 -1
- package/esm/gramjs/parse.d.ts +0 -2
- package/esm/gramjs/parse.js +0 -27
- package/esm/gramjs/parse.js.map +0 -1
- package/esm/gramjs/serialize.d.ts +0 -2
- package/esm/gramjs/serialize.js +0 -20
- package/esm/gramjs/serialize.js.map +0 -1
- package/esm/gramjs/types.d.ts +0 -7
- package/esm/gramjs/types.js +0 -2
- package/esm/gramjs/types.js.map +0 -1
- package/esm/index.d.ts +0 -5
- package/esm/index.js +0 -6
- package/esm/index.js.map +0 -1
- package/esm/mtkruto/convert.d.ts +0 -4
- package/esm/mtkruto/convert.js +0 -26
- package/esm/mtkruto/convert.js.map +0 -1
- package/esm/mtkruto/index.d.ts +0 -4
- package/esm/mtkruto/index.js +0 -5
- package/esm/mtkruto/index.js.map +0 -1
- package/esm/mtkruto/parse.js +0 -24
- package/esm/mtkruto/parse.js.map +0 -1
- package/esm/mtkruto/serialize.d.ts +0 -2
- package/esm/mtkruto/serialize.js +0 -11
- package/esm/mtkruto/serialize.js.map +0 -1
- package/esm/mtkruto/types.d.ts +0 -5
- package/esm/mtkruto/types.js +0 -2
- package/esm/mtkruto/types.js.map +0 -1
- package/esm/pyrogram/convert.js +0 -35
- package/esm/pyrogram/convert.js.map +0 -1
- package/esm/pyrogram/index.d.ts +0 -4
- package/esm/pyrogram/index.js +0 -5
- package/esm/pyrogram/index.js.map +0 -1
- package/esm/pyrogram/parse.js +0 -52
- package/esm/pyrogram/parse.js.map +0 -1
- package/esm/pyrogram/serialize.js +0 -36
- package/esm/pyrogram/serialize.js.map +0 -1
- package/esm/pyrogram/types.d.ts +0 -8
- package/esm/pyrogram/types.js +0 -2
- package/esm/pyrogram/types.js.map +0 -1
- package/esm/telethon/convert.js +0 -39
- package/esm/telethon/convert.js.map +0 -1
- package/esm/telethon/index.d.ts +0 -4
- package/esm/telethon/index.js +0 -5
- package/esm/telethon/index.js.map +0 -1
- package/esm/telethon/parse.js +0 -29
- package/esm/telethon/parse.js.map +0 -1
- package/esm/telethon/serialize.js +0 -30
- package/esm/telethon/serialize.js.map +0 -1
- package/esm/telethon/types.d.ts +0 -7
- package/esm/telethon/types.js +0 -2
- package/esm/telethon/types.js.map +0 -1
- package/esm/types.js +0 -2
- package/esm/types.js.map +0 -1
- package/esm/utils/ip.d.ts +0 -3
- package/esm/utils/ip.js +0 -39
- package/esm/utils/ip.js.map +0 -1
- package/esm/utils/rle.d.ts +0 -3
- package/esm/utils/rle.js +0 -49
- package/esm/utils/rle.js.map +0 -1
- /package/{cjs/types.d.ts → gramjs/convert.test.d.ts} +0 -0
- /package/{cjs/gramjs → gramjs}/index.d.ts +0 -0
- /package/{esm/types.d.ts → gramjs/parse.test.d.ts} +0 -0
- /package/{cjs/gramjs → gramjs}/types.d.ts +0 -0
- /package/{cjs/index.d.ts → index.d.cts} +0 -0
- /package/{cjs/mtkruto → mtkruto}/index.d.ts +0 -0
- /package/{cjs/mtkruto → mtkruto}/types.d.ts +0 -0
- /package/{cjs/pyrogram → pyrogram}/index.d.ts +0 -0
- /package/{cjs/pyrogram → pyrogram}/types.d.ts +0 -0
- /package/{cjs/telethon → telethon}/index.d.ts +0 -0
- /package/{cjs/telethon → telethon}/types.d.ts +0 -0
- /package/{cjs/utils → utils}/ip.d.ts +0 -0
- /package/{cjs/utils → utils}/rle.d.ts +0 -0
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializePyrogramSession = serializePyrogramSession;
|
|
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 SESSION_STRING_SIZE_OLD = 267;
|
|
8
|
-
const SESSION_STRING_SIZE = 271;
|
|
9
|
-
function serializePyrogramSession(session) {
|
|
10
|
-
if (session.authKey.length !== 256) {
|
|
11
|
-
throw new core_1.MtArgumentError('authKey must be 256 bytes long');
|
|
12
|
-
}
|
|
13
|
-
const userIdLong = core_1.Long.fromNumber(session.userId, true);
|
|
14
|
-
let u8;
|
|
15
|
-
if (session.apiId === undefined) {
|
|
16
|
-
// old format
|
|
17
|
-
u8 = new Uint8Array(SESSION_STRING_SIZE_OLD);
|
|
18
|
-
const dv = (0, utils_js_1.dataViewFromBuffer)(u8);
|
|
19
|
-
dv.setUint8(0, session.dcId);
|
|
20
|
-
dv.setUint8(1, session.isTest ? 1 : 0);
|
|
21
|
-
u8.set(session.authKey, 2);
|
|
22
|
-
dv.setUint32(258, userIdLong.high);
|
|
23
|
-
dv.setUint32(262, userIdLong.low);
|
|
24
|
-
dv.setUint8(266, session.isBot ? 1 : 0);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
u8 = new Uint8Array(SESSION_STRING_SIZE);
|
|
28
|
-
const dv = (0, utils_js_1.dataViewFromBuffer)(u8);
|
|
29
|
-
dv.setUint8(0, session.dcId);
|
|
30
|
-
dv.setUint32(1, session.apiId);
|
|
31
|
-
dv.setUint8(5, session.isTest ? 1 : 0);
|
|
32
|
-
u8.set(session.authKey, 6);
|
|
33
|
-
dv.setUint32(262, userIdLong.high);
|
|
34
|
-
dv.setUint32(266, userIdLong.low);
|
|
35
|
-
dv.setUint8(270, session.isBot ? 1 : 0);
|
|
36
|
-
}
|
|
37
|
-
return (0, platform_js_1.getPlatform)().base64Encode(u8, true);
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=serialize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/pyrogram/serialize.ts"],"names":[],"mappings":";;AASA,4DAmCC;AA5CD,uCAAoD;AACpD,0DAAsD;AACtD,oDAA0D;AAI1D,MAAM,uBAAuB,GAAG,GAAG,CAAA;AACnC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAE/B,SAAgB,wBAAwB,CAAC,OAAwB;IAC7D,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjC,MAAM,IAAI,sBAAe,CAAC,gCAAgC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,UAAU,GAAG,WAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAExD,IAAI,EAAc,CAAA;IAElB,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,aAAa;QACb,EAAE,GAAG,IAAI,UAAU,CAAC,uBAAuB,CAAC,CAAA;QAC5C,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAA;QAEjC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAC5B,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QAC1B,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;QAClC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;QACjC,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACJ,EAAE,GAAG,IAAI,UAAU,CAAC,mBAAmB,CAAC,CAAA;QACxC,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAA;QAEjC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAC5B,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QAC9B,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QAE1B,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;QAClC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;QACjC,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED,OAAO,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["import { Long, MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport type { PyrogramSession } from './types.js'\n\nconst SESSION_STRING_SIZE_OLD = 267\nconst SESSION_STRING_SIZE = 271\n\nexport function serializePyrogramSession(session: PyrogramSession): string {\n if (session.authKey.length !== 256) {\n throw new MtArgumentError('authKey must be 256 bytes long')\n }\n\n const userIdLong = Long.fromNumber(session.userId, true)\n\n let u8: Uint8Array\n\n if (session.apiId === undefined) {\n // old format\n u8 = new Uint8Array(SESSION_STRING_SIZE_OLD)\n const dv = dataViewFromBuffer(u8)\n\n dv.setUint8(0, session.dcId)\n dv.setUint8(1, session.isTest ? 1 : 0)\n u8.set(session.authKey, 2)\n dv.setUint32(258, userIdLong.high)\n dv.setUint32(262, userIdLong.low)\n dv.setUint8(266, session.isBot ? 1 : 0)\n } else {\n u8 = new Uint8Array(SESSION_STRING_SIZE)\n const dv = dataViewFromBuffer(u8)\n\n dv.setUint8(0, session.dcId)\n dv.setUint32(1, session.apiId)\n dv.setUint8(5, session.isTest ? 1 : 0)\n u8.set(session.authKey, 6)\n\n dv.setUint32(262, userIdLong.high)\n dv.setUint32(266, userIdLong.low)\n dv.setUint8(270, session.isBot ? 1 : 0)\n }\n\n return getPlatform().base64Encode(u8, true)\n}\n"]}
|
package/cjs/pyrogram/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/pyrogram/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface PyrogramSession {\n apiId?: number\n dcId: number\n isTest: boolean\n authKey: Uint8Array\n userId: number\n isBot: boolean\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { StringSessionData } from '@mtcute/core/utils.js';
|
|
2
|
-
import type { TelethonSession } from './types.js';
|
|
3
|
-
export declare function convertFromTelethonSession(session: TelethonSession | string): StringSessionData;
|
|
4
|
-
export declare function convertToTelethonSession(session: StringSessionData | string): string;
|
package/cjs/telethon/convert.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFromTelethonSession = convertFromTelethonSession;
|
|
4
|
-
exports.convertToTelethonSession = convertToTelethonSession;
|
|
5
|
-
const utils_js_1 = require("@mtcute/core/utils.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 convertFromTelethonSession(session) {
|
|
10
|
-
if (typeof session === 'string') {
|
|
11
|
-
session = (0, parse_js_1.parseTelethonSession)(session);
|
|
12
|
-
}
|
|
13
|
-
const dc = {
|
|
14
|
-
id: session.dcId,
|
|
15
|
-
ipAddress: session.ipAddress,
|
|
16
|
-
port: session.port,
|
|
17
|
-
ipv6: session.ipv6,
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
version: 3,
|
|
21
|
-
// we don't exactly have that information. try to deduce it from DC_MAPPING_TEST
|
|
22
|
-
// todo: we should maybe check this at connect?
|
|
23
|
-
testMode: (0, dcs_js_1.isTestDc)(session.ipAddress),
|
|
24
|
-
primaryDcs: {
|
|
25
|
-
main: dc,
|
|
26
|
-
media: dc,
|
|
27
|
-
},
|
|
28
|
-
authKey: session.authKey,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function convertToTelethonSession(session) {
|
|
32
|
-
if (typeof session === 'string') {
|
|
33
|
-
session = (0, utils_js_1.readStringSession)(session);
|
|
34
|
-
}
|
|
35
|
-
return (0, serialize_js_1.serializeTelethonSession)({
|
|
36
|
-
dcId: session.primaryDcs.main.id,
|
|
37
|
-
ipAddress: session.primaryDcs.main.ipAddress,
|
|
38
|
-
port: session.primaryDcs.main.port,
|
|
39
|
-
ipv6: session.primaryDcs.main.ipv6 ?? false,
|
|
40
|
-
authKey: session.authKey,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=convert.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/telethon/convert.ts"],"names":[],"mappings":";;AASA,gEAuBC;AAED,4DAYC;AA7CD,oDAAyD;AAEzD,sCAAoC;AAEpC,yCAAiD;AACjD,iDAAyD;AAGzD,SAAgB,0BAA0B,CAAC,OAAiC;IACxE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,GAAG,IAAA,+BAAoB,EAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,MAAM,EAAE,GAAkB;QACtB,EAAE,EAAE,OAAO,CAAC,IAAI;QAChB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;KACrB,CAAA;IAED,OAAO;QACH,OAAO,EAAE,CAAC;QACV,gFAAgF;QAChF,+CAA+C;QAC/C,QAAQ,EAAE,IAAA,iBAAQ,EAAC,OAAO,CAAC,SAAS,CAAC;QACrC,UAAU,EAAE;YACR,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,EAAE;SACZ;QACD,OAAO,EAAE,OAAO,CAAC,OAAO;KAC3B,CAAA;AACL,CAAC;AAED,SAAgB,wBAAwB,CAAC,OAAmC;IACxE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,GAAG,IAAA,4BAAiB,EAAC,OAAO,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,IAAA,uCAAwB,EAAC;QAC5B,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","sourcesContent":["import type { BasicDcOption, StringSessionData } from '@mtcute/core/utils.js'\nimport { readStringSession } from '@mtcute/core/utils.js'\n\nimport { isTestDc } from '../dcs.js'\n\nimport { parseTelethonSession } from './parse.js'\nimport { serializeTelethonSession } from './serialize.js'\nimport type { TelethonSession } from './types.js'\n\nexport function convertFromTelethonSession(session: TelethonSession | string): StringSessionData {\n if (typeof session === 'string') {\n session = parseTelethonSession(session)\n }\n\n const dc: BasicDcOption = {\n id: session.dcId,\n ipAddress: session.ipAddress,\n port: session.port,\n ipv6: session.ipv6,\n }\n\n return {\n version: 3,\n // we don't exactly have that information. try to deduce it from DC_MAPPING_TEST\n // todo: we should maybe check this at connect?\n testMode: isTestDc(session.ipAddress),\n primaryDcs: {\n main: dc,\n media: dc,\n },\n authKey: session.authKey,\n }\n}\n\nexport function convertToTelethonSession(session: StringSessionData | string): string {\n if (typeof session === 'string') {\n session = readStringSession(session)\n }\n\n return serializeTelethonSession({\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"]}
|
package/cjs/telethon/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/telethon/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"]}
|
package/cjs/telethon/parse.d.ts
DELETED
package/cjs/telethon/parse.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTelethonSession = parseTelethonSession;
|
|
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 ip_js_1 = require("../utils/ip.js");
|
|
8
|
-
function parseTelethonSession(session) {
|
|
9
|
-
if (session[0] !== '1') {
|
|
10
|
-
// version
|
|
11
|
-
throw new core_1.MtArgumentError(`Invalid session string (version = ${session[0]})`);
|
|
12
|
-
}
|
|
13
|
-
session = session.slice(1);
|
|
14
|
-
const data = (0, platform_js_1.getPlatform)().base64Decode(session, true);
|
|
15
|
-
const dv = (0, utils_js_1.dataViewFromBuffer)(data);
|
|
16
|
-
const dcId = dv.getUint8(0);
|
|
17
|
-
const ipSize = session.length === 352 ? 4 : 16;
|
|
18
|
-
let pos = 1 + ipSize;
|
|
19
|
-
const ipBytes = data.subarray(1, pos);
|
|
20
|
-
const port = dv.getUint16(pos);
|
|
21
|
-
pos += 2;
|
|
22
|
-
const authKey = data.subarray(pos, pos + 256);
|
|
23
|
-
const ip = (0, ip_js_1.parseIpFromBytes)(ipBytes);
|
|
24
|
-
return {
|
|
25
|
-
dcId,
|
|
26
|
-
ipAddress: ip,
|
|
27
|
-
ipv6: ipSize === 16,
|
|
28
|
-
port,
|
|
29
|
-
authKey,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=parse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/telethon/parse.ts"],"names":[],"mappings":";;AAQA,oDA8BC;AAtCD,uCAA8C;AAC9C,0DAAsD;AACtD,oDAA0D;AAE1D,0CAAiD;AAIjD,SAAgB,oBAAoB,CAAC,OAAe;IAChD,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACrB,UAAU;QACV,MAAM,IAAI,sBAAe,CAAC,qCAAqC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACjF,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE1B,MAAM,IAAI,GAAG,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACtD,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAA;IAEnC,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAE3B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9C,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,CAAA;IAEpB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACrC,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,MAAM,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAA;IAEpC,OAAO;QACH,IAAI;QACJ,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,MAAM,KAAK,EAAE;QACnB,IAAI;QACJ,OAAO;KACV,CAAA;AACL,CAAC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport { parseIpFromBytes } from '../utils/ip.js'\n\nimport type { TelethonSession } from './types.js'\n\nexport function parseTelethonSession(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, true)\n const dv = dataViewFromBuffer(data)\n\n const dcId = dv.getUint8(0)\n\n const ipSize = session.length === 352 ? 4 : 16\n let pos = 1 + ipSize\n\n const ipBytes = data.subarray(1, pos)\n const port = dv.getUint16(pos)\n pos += 2\n const authKey = data.subarray(pos, pos + 256)\n\n const ip = parseIpFromBytes(ipBytes)\n\n return {\n dcId,\n ipAddress: ip,\n ipv6: ipSize === 16,\n port,\n authKey,\n }\n}\n"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeTelethonSession = serializeTelethonSession;
|
|
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 ip_js_1 = require("../utils/ip.js");
|
|
8
|
-
function serializeTelethonSession(session) {
|
|
9
|
-
if (session.authKey.length !== 256) {
|
|
10
|
-
throw new core_1.MtArgumentError('authKey must be 256 bytes long');
|
|
11
|
-
}
|
|
12
|
-
const ipSize = session.ipv6 ? 16 : 4;
|
|
13
|
-
const u8 = new Uint8Array(259 + ipSize);
|
|
14
|
-
const dv = (0, utils_js_1.dataViewFromBuffer)(u8);
|
|
15
|
-
dv.setUint8(0, session.dcId);
|
|
16
|
-
let pos;
|
|
17
|
-
if (session.ipv6) {
|
|
18
|
-
(0, ip_js_1.serializeIpv6ToBytes)(session.ipAddress, u8.subarray(1, 17));
|
|
19
|
-
pos = 17;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
(0, ip_js_1.serializeIpv4ToBytes)(session.ipAddress, u8.subarray(1, 5));
|
|
23
|
-
pos = 5;
|
|
24
|
-
}
|
|
25
|
-
dv.setUint16(pos, session.port);
|
|
26
|
-
pos += 2;
|
|
27
|
-
u8.set(session.authKey, pos);
|
|
28
|
-
let b64 = (0, platform_js_1.getPlatform)().base64Encode(u8, true);
|
|
29
|
-
while (b64.length % 4 !== 0)
|
|
30
|
-
b64 += '='; // for some reason telethon uses padding
|
|
31
|
-
return `1${b64}`;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=serialize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/telethon/serialize.ts"],"names":[],"mappings":";;AAQA,4DA6BC;AArCD,uCAA8C;AAC9C,0DAAsD;AACtD,oDAA0D;AAE1D,0CAA2E;AAI3E,SAAgB,wBAAwB,CAAC,OAAwB;IAC7D,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjC,MAAM,IAAI,sBAAe,CAAC,gCAAgC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACpC,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,GAAG,GAAG,MAAM,CAAC,CAAA;IACvC,MAAM,EAAE,GAAG,IAAA,6BAAkB,EAAC,EAAE,CAAC,CAAA;IAEjC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAE5B,IAAI,GAAG,CAAA;IAEP,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,IAAA,4BAAoB,EAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;QAC3D,GAAG,GAAG,EAAE,CAAA;IACZ,CAAC;SAAM,CAAC;QACJ,IAAA,4BAAoB,EAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC1D,GAAG,GAAG,CAAC,CAAA;IACX,CAAC;IAED,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,IAAI,GAAG,GAAG,IAAA,yBAAW,GAAE,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9C,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC;QAAE,GAAG,IAAI,GAAG,CAAA,CAAC,wCAAwC;IAEhF,OAAO,IAAI,GAAG,EAAE,CAAA;AACpB,CAAC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport { serializeIpv4ToBytes, serializeIpv6ToBytes } from '../utils/ip.js'\n\nimport type { TelethonSession } from './types.js'\n\nexport function serializeTelethonSession(session: TelethonSession) {\n if (session.authKey.length !== 256) {\n throw new MtArgumentError('authKey must be 256 bytes long')\n }\n\n const ipSize = session.ipv6 ? 16 : 4\n const u8 = new Uint8Array(259 + ipSize)\n const dv = dataViewFromBuffer(u8)\n\n dv.setUint8(0, session.dcId)\n\n let pos\n\n if (session.ipv6) {\n serializeIpv6ToBytes(session.ipAddress, u8.subarray(1, 17))\n pos = 17\n } else {\n serializeIpv4ToBytes(session.ipAddress, u8.subarray(1, 5))\n pos = 5\n }\n\n dv.setUint16(pos, session.port)\n pos += 2\n u8.set(session.authKey, pos)\n\n let b64 = getPlatform().base64Encode(u8, true)\n while (b64.length % 4 !== 0) b64 += '=' // for some reason telethon uses padding\n\n return `1${b64}`\n}\n"]}
|
package/cjs/telethon/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/telethon/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface TelethonSession {\n dcId: number\n ipAddress: string\n ipv6: boolean\n port: number\n authKey: Uint8Array\n}\n"]}
|
package/cjs/types.js
DELETED
package/cjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
package/cjs/utils/ip.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseIpFromBytes = parseIpFromBytes;
|
|
4
|
-
exports.serializeIpv4ToBytes = serializeIpv4ToBytes;
|
|
5
|
-
exports.serializeIpv6ToBytes = serializeIpv6ToBytes;
|
|
6
|
-
const core_1 = require("@mtcute/core");
|
|
7
|
-
function parseIpFromBytes(data) {
|
|
8
|
-
if (data.length === 4) {
|
|
9
|
-
return `${data[0]}.${data[1]}.${data[2]}.${data[3]}`;
|
|
10
|
-
}
|
|
11
|
-
if (data.length === 16) {
|
|
12
|
-
let res = '';
|
|
13
|
-
for (let i = 0; i < 16; i += 2) {
|
|
14
|
-
res += data[i].toString(16).padStart(2, '0');
|
|
15
|
-
res += data[i + 1].toString(16).padStart(2, '0');
|
|
16
|
-
if (i < 14)
|
|
17
|
-
res += ':';
|
|
18
|
-
}
|
|
19
|
-
return res;
|
|
20
|
-
}
|
|
21
|
-
throw new core_1.MtArgumentError('Invalid IP address length');
|
|
22
|
-
}
|
|
23
|
-
function serializeIpv4ToBytes(ip, buf) {
|
|
24
|
-
const parts = ip.split('.');
|
|
25
|
-
if (parts.length !== 4) {
|
|
26
|
-
throw new core_1.MtArgumentError('Invalid IPv4 address');
|
|
27
|
-
}
|
|
28
|
-
buf[0] = Number(parts[0]);
|
|
29
|
-
buf[1] = Number(parts[1]);
|
|
30
|
-
buf[2] = Number(parts[2]);
|
|
31
|
-
buf[3] = Number(parts[3]);
|
|
32
|
-
}
|
|
33
|
-
function serializeIpv6ToBytes(ip, buf) {
|
|
34
|
-
const parts = ip.split(':');
|
|
35
|
-
if (parts.length !== 8) {
|
|
36
|
-
throw new core_1.MtArgumentError('Invalid IPv6 address');
|
|
37
|
-
}
|
|
38
|
-
for (let i = 0; i < 8; i++) {
|
|
39
|
-
const val = Number.parseInt(parts[i], 16);
|
|
40
|
-
buf[i * 2] = val >> 8;
|
|
41
|
-
buf[i * 2 + 1] = val & 0xFF;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=ip.js.map
|
package/cjs/utils/ip.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ip.js","sourceRoot":"","sources":["../../../src/utils/ip.ts"],"names":[],"mappings":";;AAEA,4CAkBC;AAED,oDAWC;AAED,oDAYC;AA/CD,uCAA8C;AAE9C,SAAgB,gBAAgB,CAAC,IAAgB;IAC7C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACxD,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACrB,IAAI,GAAG,GAAG,EAAE,CAAA;QAEZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YAC5C,GAAG,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YAChD,IAAI,CAAC,GAAG,EAAE;gBAAE,GAAG,IAAI,GAAG,CAAA;QAC1B,CAAC;QAED,OAAO,GAAG,CAAA;IACd,CAAC;IAED,MAAM,IAAI,sBAAe,CAAC,2BAA2B,CAAC,CAAA;AAC1D,CAAC;AAED,SAAgB,oBAAoB,CAAC,EAAU,EAAE,GAAe;IAC5D,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE3B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,sBAAe,CAAC,sBAAsB,CAAC,CAAA;IACrD,CAAC;IAED,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACzB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACzB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACzB,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAED,SAAgB,oBAAoB,CAAC,EAAU,EAAE,GAAe;IAC5D,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE3B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,sBAAe,CAAC,sBAAsB,CAAC,CAAA;IACrD,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QACzC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAA;QACrB,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAA;IAC/B,CAAC;AACL,CAAC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\n\nexport function parseIpFromBytes(data: Uint8Array): string {\n if (data.length === 4) {\n return `${data[0]}.${data[1]}.${data[2]}.${data[3]}`\n }\n\n if (data.length === 16) {\n let res = ''\n\n for (let i = 0; i < 16; i += 2) {\n res += data[i].toString(16).padStart(2, '0')\n res += data[i + 1].toString(16).padStart(2, '0')\n if (i < 14) res += ':'\n }\n\n return res\n }\n\n throw new MtArgumentError('Invalid IP address length')\n}\n\nexport function serializeIpv4ToBytes(ip: string, buf: Uint8Array): void {\n const parts = ip.split('.')\n\n if (parts.length !== 4) {\n throw new MtArgumentError('Invalid IPv4 address')\n }\n\n buf[0] = Number(parts[0])\n buf[1] = Number(parts[1])\n buf[2] = Number(parts[2])\n buf[3] = Number(parts[3])\n}\n\nexport function serializeIpv6ToBytes(ip: string, buf: Uint8Array): void {\n const parts = ip.split(':')\n\n if (parts.length !== 8) {\n throw new MtArgumentError('Invalid IPv6 address')\n }\n\n for (let i = 0; i < 8; i++) {\n const val = Number.parseInt(parts[i], 16)\n buf[i * 2] = val >> 8\n buf[i * 2 + 1] = val & 0xFF\n }\n}\n"]}
|
package/cjs/utils/rle.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// tdlib's RLE only encodes consecutive \x00
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.telegramRleEncode = telegramRleEncode;
|
|
5
|
-
exports.telegramRleDecode = telegramRleDecode;
|
|
6
|
-
exports.assertNever = assertNever;
|
|
7
|
-
function telegramRleEncode(buf) {
|
|
8
|
-
const len = buf.length;
|
|
9
|
-
const ret = [];
|
|
10
|
-
let count = 0;
|
|
11
|
-
for (let i = 0; i < len; i++) {
|
|
12
|
-
const cur = buf[i];
|
|
13
|
-
if (cur === 0) {
|
|
14
|
-
count += 1;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
if (count > 0) {
|
|
18
|
-
ret.push(0, count);
|
|
19
|
-
count = 0;
|
|
20
|
-
}
|
|
21
|
-
ret.push(cur);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (count > 0) {
|
|
25
|
-
ret.push(0, count);
|
|
26
|
-
}
|
|
27
|
-
return new Uint8Array(ret);
|
|
28
|
-
}
|
|
29
|
-
function telegramRleDecode(buf) {
|
|
30
|
-
const len = buf.length;
|
|
31
|
-
const ret = [];
|
|
32
|
-
let prev = -1;
|
|
33
|
-
for (let i = 0; i < len; i++) {
|
|
34
|
-
const cur = buf[i];
|
|
35
|
-
if (prev === 0) {
|
|
36
|
-
for (let j = 0; j < cur; j++) {
|
|
37
|
-
ret.push(prev);
|
|
38
|
-
}
|
|
39
|
-
prev = -1;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
if (prev !== -1)
|
|
43
|
-
ret.push(prev);
|
|
44
|
-
prev = cur;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (prev !== -1)
|
|
48
|
-
ret.push(prev);
|
|
49
|
-
return new Uint8Array(ret);
|
|
50
|
-
}
|
|
51
|
-
function assertNever(_) {
|
|
52
|
-
throw new Error('unreachable');
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=rle.js.map
|
package/cjs/utils/rle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rle.js","sourceRoot":"","sources":["../../../src/utils/rle.ts"],"names":[],"mappings":";AAAA,4CAA4C;;AAE5C,8CAyBC;AAED,8CAsBC;AAED,kCAEC;AArDD,SAAgB,iBAAiB,CAAC,GAAe;IAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;IACtB,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAElB,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACZ,KAAK,IAAI,CAAC,CAAA;QACd,CAAC;aAAM,CAAC;YACJ,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;gBACZ,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;gBAClB,KAAK,GAAG,CAAC,CAAA;YACb,CAAC;YAED,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC;IACL,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACZ,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACtB,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,SAAgB,iBAAiB,CAAC,GAAe;IAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;IACtB,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,IAAI,IAAI,GAAG,CAAC,CAAC,CAAA;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QAElB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC;YACD,IAAI,GAAG,CAAC,CAAC,CAAA;QACb,CAAC;aAAM,CAAC;YACJ,IAAI,IAAI,KAAK,CAAC,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC/B,IAAI,GAAG,GAAG,CAAA;QACd,CAAC;IACL,CAAC;IAED,IAAI,IAAI,KAAK,CAAC,CAAC;QAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAE/B,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,SAAgB,WAAW,CAAC,CAAQ;IAChC,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;AAClC,CAAC","sourcesContent":["// tdlib's RLE only encodes consecutive \\x00\n\nexport function telegramRleEncode(buf: Uint8Array): Uint8Array {\n const len = buf.length\n const ret: number[] = []\n let count = 0\n\n for (let i = 0; i < len; i++) {\n const cur = buf[i]\n\n if (cur === 0) {\n count += 1\n } else {\n if (count > 0) {\n ret.push(0, count)\n count = 0\n }\n\n ret.push(cur)\n }\n }\n\n if (count > 0) {\n ret.push(0, count)\n }\n\n return new Uint8Array(ret)\n}\n\nexport function telegramRleDecode(buf: Uint8Array): Uint8Array {\n const len = buf.length\n const ret: number[] = []\n let prev = -1\n\n for (let i = 0; i < len; i++) {\n const cur = buf[i]\n\n if (prev === 0) {\n for (let j = 0; j < cur; j++) {\n ret.push(prev)\n }\n prev = -1\n } else {\n if (prev !== -1) ret.push(prev)\n prev = cur\n }\n }\n\n if (prev !== -1) ret.push(prev)\n\n return new Uint8Array(ret)\n}\n\nexport function assertNever(_: never): never {\n throw new Error('unreachable')\n}\n"]}
|
package/esm/dcs.d.ts
DELETED
package/esm/dcs.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// some libraries only store the DCs in the source code, so we need to map them to the correct DCs
|
|
2
|
-
// this may not be very accurate, but it's better than nothing
|
|
3
|
-
// we *could* always map those to the primary dc (the client should handle that gracefully),
|
|
4
|
-
// but imo it's better to be as accurate as possible
|
|
5
|
-
// we'll also only map to ipv4 since that's more portable
|
|
6
|
-
export const DC_MAPPING_PROD = {
|
|
7
|
-
1: {
|
|
8
|
-
main: {
|
|
9
|
-
id: 1,
|
|
10
|
-
ipAddress: '149.154.175.56',
|
|
11
|
-
port: 443,
|
|
12
|
-
},
|
|
13
|
-
media: {
|
|
14
|
-
id: 1,
|
|
15
|
-
ipAddress: '149.154.175.211',
|
|
16
|
-
port: 443,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
2: {
|
|
20
|
-
main: {
|
|
21
|
-
id: 2,
|
|
22
|
-
ipAddress: '149.154.167.41',
|
|
23
|
-
port: 443,
|
|
24
|
-
},
|
|
25
|
-
media: {
|
|
26
|
-
id: 2,
|
|
27
|
-
ipAddress: '149.154.167.35',
|
|
28
|
-
port: 443,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
3: {
|
|
32
|
-
main: {
|
|
33
|
-
id: 3,
|
|
34
|
-
ipAddress: '149.154.175.100',
|
|
35
|
-
port: 443,
|
|
36
|
-
},
|
|
37
|
-
media: {
|
|
38
|
-
id: 3,
|
|
39
|
-
ipAddress: '149.154.175.100',
|
|
40
|
-
port: 443,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
4: {
|
|
44
|
-
main: {
|
|
45
|
-
id: 4,
|
|
46
|
-
ipAddress: '149.154.167.91',
|
|
47
|
-
port: 443,
|
|
48
|
-
},
|
|
49
|
-
media: {
|
|
50
|
-
id: 4,
|
|
51
|
-
ipAddress: '149.154.167.255',
|
|
52
|
-
port: 443,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
5: {
|
|
56
|
-
main: {
|
|
57
|
-
id: 5,
|
|
58
|
-
ipAddress: '91.108.56.179',
|
|
59
|
-
port: 443,
|
|
60
|
-
},
|
|
61
|
-
media: {
|
|
62
|
-
id: 5,
|
|
63
|
-
ipAddress: '149.154.171.255',
|
|
64
|
-
port: 443,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
export const DC_MAPPING_TEST = {
|
|
69
|
-
1: {
|
|
70
|
-
main: {
|
|
71
|
-
id: 1,
|
|
72
|
-
ipAddress: '149.154.175.10',
|
|
73
|
-
port: 80,
|
|
74
|
-
},
|
|
75
|
-
media: {
|
|
76
|
-
id: 1,
|
|
77
|
-
ipAddress: '149.154.175.10',
|
|
78
|
-
port: 80,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
2: {
|
|
82
|
-
main: {
|
|
83
|
-
id: 2,
|
|
84
|
-
ipAddress: '149.154.167.40',
|
|
85
|
-
port: 443,
|
|
86
|
-
},
|
|
87
|
-
media: {
|
|
88
|
-
id: 2,
|
|
89
|
-
ipAddress: '149.154.167.40',
|
|
90
|
-
port: 443,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
3: {
|
|
94
|
-
main: {
|
|
95
|
-
id: 3,
|
|
96
|
-
ipAddress: '149.154.175.117',
|
|
97
|
-
port: 443,
|
|
98
|
-
},
|
|
99
|
-
media: {
|
|
100
|
-
id: 3,
|
|
101
|
-
ipAddress: '149.154.175.117',
|
|
102
|
-
port: 443,
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
export function isTestDc(ip) {
|
|
107
|
-
return Object.values(DC_MAPPING_TEST).some(dc => dc.main.ipAddress === ip || dc.media.ipAddress === ip);
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=dcs.js.map
|
package/esm/dcs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dcs.js","sourceRoot":"","sources":["../../src/dcs.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,8DAA8D;AAC9D,4FAA4F;AAC5F,oDAAoD;AACpD,yDAAyD;AAEzD,MAAM,CAAC,MAAM,eAAe,GAA8B;IACtD,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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;AAED,MAAM,CAAC,MAAM,eAAe,GAA8B;IACtD,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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,CAAC,EAAE;QACC,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,MAAM,UAAU,QAAQ,CAAC,EAAU;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,EAAE,CAAC,CAAA;AAC3G,CAAC","sourcesContent":["import type { 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"]}
|
package/esm/gramjs/convert.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
export function convertFromGramjsSession(session) {
|
|
6
|
-
if (typeof session === 'string') {
|
|
7
|
-
session = parseGramjsSession(session);
|
|
8
|
-
}
|
|
9
|
-
return convertFromTelethonSession(session);
|
|
10
|
-
}
|
|
11
|
-
export 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
|
-
ipv6: session.primaryDcs.main.ipv6 ?? false,
|
|
20
|
-
authKey: session.authKey,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=convert.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/gramjs/convert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,MAAM,UAAU,wBAAwB,CAAC,OAAiC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;IAED,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAmC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,sBAAsB,CAAC;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","sourcesContent":["import type { StringSessionData } from '@mtcute/core/utils.js'\nimport { readStringSession } from '@mtcute/core/utils.js'\n\nimport { convertFromTelethonSession } from '../telethon/convert.js'\nimport type { TelethonSession } from '../telethon/types.js'\n\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(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"]}
|
package/esm/gramjs/index.d.ts
DELETED
package/esm/gramjs/index.js
DELETED
package/esm/gramjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gramjs/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA","sourcesContent":["export * from './convert.js'\nexport * from './parse.js'\nexport * from './serialize.js'\nexport * from './types.js'\n"]}
|
package/esm/gramjs/parse.d.ts
DELETED
package/esm/gramjs/parse.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MtArgumentError } from '@mtcute/core';
|
|
2
|
-
import { getPlatform } from '@mtcute/core/platform.js';
|
|
3
|
-
import { dataViewFromBuffer } from '@mtcute/core/utils.js';
|
|
4
|
-
export function parseGramjsSession(session) {
|
|
5
|
-
if (session[0] !== '1') {
|
|
6
|
-
// version
|
|
7
|
-
throw new MtArgumentError(`Invalid session string (version = ${session[0]})`);
|
|
8
|
-
}
|
|
9
|
-
session = session.slice(1);
|
|
10
|
-
const data = getPlatform().base64Decode(session);
|
|
11
|
-
const dv = dataViewFromBuffer(data);
|
|
12
|
-
const dcId = dv.getUint8(0);
|
|
13
|
-
const ipSize = dv.getUint16(1);
|
|
14
|
-
let pos = 3 + ipSize;
|
|
15
|
-
const ip = getPlatform().utf8Decode(data.subarray(3, pos));
|
|
16
|
-
const port = dv.getUint16(pos);
|
|
17
|
-
pos += 2;
|
|
18
|
-
const authKey = data.subarray(pos, pos + 256);
|
|
19
|
-
return {
|
|
20
|
-
dcId,
|
|
21
|
-
ipAddress: ip,
|
|
22
|
-
ipv6: ip.includes(':'), // dumb check but gramjs does this
|
|
23
|
-
port,
|
|
24
|
-
authKey,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=parse.js.map
|
package/esm/gramjs/parse.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/gramjs/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAI1D,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAC9C,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACrB,UAAU;QACV,MAAM,IAAI,eAAe,CAAC,qCAAqC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACjF,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE1B,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;IAChD,MAAM,EAAE,GAAG,kBAAkB,CAAC,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,WAAW,EAAE,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,EAAE,kCAAkC;QAC1D,IAAI;QACJ,OAAO;KACV,CAAA;AACL,CAAC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport type { 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"]}
|
package/esm/gramjs/serialize.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MtArgumentError } from '@mtcute/core';
|
|
2
|
-
import { getPlatform } from '@mtcute/core/platform.js';
|
|
3
|
-
import { dataViewFromBuffer } from '@mtcute/core/utils.js';
|
|
4
|
-
export function serializeGramjsSession(session) {
|
|
5
|
-
if (session.authKey.length !== 256) {
|
|
6
|
-
throw new MtArgumentError('authKey must be 256 bytes long');
|
|
7
|
-
}
|
|
8
|
-
const ipEncoded = getPlatform().utf8Encode(session.ipAddress);
|
|
9
|
-
const u8 = new Uint8Array(261 + ipEncoded.length);
|
|
10
|
-
const dv = dataViewFromBuffer(u8);
|
|
11
|
-
dv.setUint8(0, session.dcId);
|
|
12
|
-
dv.setUint16(1, ipEncoded.length);
|
|
13
|
-
u8.set(ipEncoded, 3);
|
|
14
|
-
let pos = 3 + ipEncoded.length;
|
|
15
|
-
dv.setUint16(pos, session.port);
|
|
16
|
-
pos += 2;
|
|
17
|
-
u8.set(session.authKey, pos);
|
|
18
|
-
return `1${getPlatform().base64Encode(u8)}`;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=serialize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/gramjs/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAI1D,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC3D,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjC,MAAM,IAAI,eAAe,CAAC,gCAAgC,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,SAAS,GAAG,WAAW,EAAE,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,kBAAkB,CAAC,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,IAAI,WAAW,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAA;AAC/C,CAAC","sourcesContent":["import { MtArgumentError } from '@mtcute/core'\nimport { getPlatform } from '@mtcute/core/platform.js'\nimport { dataViewFromBuffer } from '@mtcute/core/utils.js'\n\nimport type { 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"]}
|
package/esm/gramjs/types.d.ts
DELETED
package/esm/gramjs/types.js
DELETED
package/esm/gramjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"]}
|