@mtcute/convert 0.19.3 → 0.19.8
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/gramjs/convert.d.cts +2 -2
- package/gramjs/convert.d.ts +2 -2
- package/gramjs/index.d.cts +1 -0
- package/gramjs/index.d.ts +1 -0
- package/gramjs/store-session.cjs +88 -0
- package/gramjs/store-session.js +61 -0
- package/index.cjs +19 -16
- package/index.js +20 -17
- package/package.json +10 -2
- package/{convert/src/utils → utils}/crypto.cjs +3 -2
- package/{convert/src/utils → utils}/crypto.js +3 -2
- package/{convert/src/utils → utils}/fs.cjs +4 -0
- package/{convert/src/utils → utils}/fs.js +4 -0
- package/node/src/utils/crypto.cjs +0 -75
- package/node/src/utils/crypto.js +0 -69
- package/node/src/utils.cjs +0 -34
- package/node/src/utils.js +0 -7
- package/wasm/src/index.cjs +0 -64
- package/wasm/src/index.js +0 -59
- /package/{convert/src/dcs.cjs → dcs.cjs} +0 -0
- /package/{convert/src/dcs.js → dcs.js} +0 -0
- /package/{convert/src/gramjs → gramjs}/convert.cjs +0 -0
- /package/{convert/src/gramjs → gramjs}/convert.js +0 -0
- /package/{convert/src/gramjs → gramjs}/parse.cjs +0 -0
- /package/{convert/src/gramjs → gramjs}/parse.js +0 -0
- /package/{convert/src/gramjs → gramjs}/serialize.cjs +0 -0
- /package/{convert/src/gramjs → gramjs}/serialize.js +0 -0
- /package/{convert/src/mtkruto → mtkruto}/convert.cjs +0 -0
- /package/{convert/src/mtkruto → mtkruto}/convert.js +0 -0
- /package/{convert/src/mtkruto → mtkruto}/parse.cjs +0 -0
- /package/{convert/src/mtkruto → mtkruto}/parse.js +0 -0
- /package/{convert/src/mtkruto → mtkruto}/serialize.cjs +0 -0
- /package/{convert/src/mtkruto → mtkruto}/serialize.js +0 -0
- /package/{convert/src/pyrogram → pyrogram}/convert.cjs +0 -0
- /package/{convert/src/pyrogram → pyrogram}/convert.js +0 -0
- /package/{convert/src/pyrogram → pyrogram}/parse.cjs +0 -0
- /package/{convert/src/pyrogram → pyrogram}/parse.js +0 -0
- /package/{convert/src/pyrogram → pyrogram}/serialize.cjs +0 -0
- /package/{convert/src/pyrogram → pyrogram}/serialize.js +0 -0
- /package/{convert/src/tdesktop → tdesktop}/convert.cjs +0 -0
- /package/{convert/src/tdesktop → tdesktop}/convert.js +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-bundle.cjs +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-bundle.js +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-reader.cjs +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-reader.js +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-writer.cjs +0 -0
- /package/{convert/src/tdesktop → tdesktop}/qt-writer.js +0 -0
- /package/{convert/src/tdesktop → tdesktop}/tdata.cjs +0 -0
- /package/{convert/src/tdesktop → tdesktop}/tdata.js +0 -0
- /package/{convert/src/telethon → telethon}/convert.cjs +0 -0
- /package/{convert/src/telethon → telethon}/convert.js +0 -0
- /package/{convert/src/telethon → telethon}/parse.cjs +0 -0
- /package/{convert/src/telethon → telethon}/parse.js +0 -0
- /package/{convert/src/telethon → telethon}/serialize.cjs +0 -0
- /package/{convert/src/telethon → telethon}/serialize.js +0 -0
- /package/{convert/src/utils → utils}/rle.cjs +0 -0
- /package/{convert/src/utils → utils}/rle.js +0 -0
package/gramjs/convert.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { StringSessionData } from '@mtcute/core/utils.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare function convertFromGramjsSession(session:
|
|
2
|
+
import { GramjsSession } from './types.js';
|
|
3
|
+
export declare function convertFromGramjsSession(session: GramjsSession | string): StringSessionData;
|
|
4
4
|
export declare function convertToGramjsSession(session: StringSessionData | string): string;
|
package/gramjs/convert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { StringSessionData } from '@mtcute/core/utils.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare function convertFromGramjsSession(session:
|
|
2
|
+
import { GramjsSession } from './types.js';
|
|
3
|
+
export declare function convertFromGramjsSession(session: GramjsSession | string): StringSessionData;
|
|
4
4
|
export declare function convertToGramjsSession(session: StringSessionData | string): string;
|
package/gramjs/index.d.cts
CHANGED
package/gramjs/index.d.ts
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
24
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
25
|
+
console.warn("[@mtcute/convert] CommonJS support is deprecated and will be removed in 0.25.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
26
|
+
console.warn("[@mtcute/convert] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
27
|
+
}
|
|
28
|
+
"use strict";
|
|
29
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
30
|
+
const utils = require("@fuman/utils");
|
|
31
|
+
const fs = require("../utils/fs.cjs");
|
|
32
|
+
async function readGramjsStoreSession(path, params) {
|
|
33
|
+
const fs$1 = params?.fs ?? await import("node:fs/promises");
|
|
34
|
+
const sessionName = fs.basename(path);
|
|
35
|
+
const [fAuthKey, fDcId, fIpAddress, fPort] = await Promise.all([
|
|
36
|
+
fs$1.readFile(fs.joinPaths(path, `${sessionName}%3AauthKey`)),
|
|
37
|
+
fs$1.readFile(fs.joinPaths(path, `${sessionName}%3AdcId`)),
|
|
38
|
+
fs$1.readFile(fs.joinPaths(path, `${sessionName}%3AserverAddress`)),
|
|
39
|
+
fs$1.readFile(fs.joinPaths(path, `${sessionName}%3Aport`))
|
|
40
|
+
]);
|
|
41
|
+
const authKeyParsed = JSON.parse(utils.utf8.decoder.decode(fAuthKey));
|
|
42
|
+
if (typeof authKeyParsed !== "object" || authKeyParsed === null || !("type" in authKeyParsed) || authKeyParsed.type !== "Buffer" || !("data" in authKeyParsed) || !Array.isArray(authKeyParsed.data)) {
|
|
43
|
+
throw new Error("Invalid auth key file");
|
|
44
|
+
}
|
|
45
|
+
const authKey = new Uint8Array(authKeyParsed.data);
|
|
46
|
+
if (authKey.length !== 256) {
|
|
47
|
+
throw new Error("Invalid auth key length");
|
|
48
|
+
}
|
|
49
|
+
const dcId = Number.parseInt(utils.utf8.decoder.decode(fDcId));
|
|
50
|
+
if (Number.isNaN(dcId)) {
|
|
51
|
+
throw new TypeError("Invalid dc id");
|
|
52
|
+
}
|
|
53
|
+
const port = Number.parseInt(utils.utf8.decoder.decode(fPort));
|
|
54
|
+
if (Number.isNaN(port)) {
|
|
55
|
+
throw new TypeError("Invalid port");
|
|
56
|
+
}
|
|
57
|
+
const ip = JSON.parse(utils.utf8.decoder.decode(fIpAddress));
|
|
58
|
+
if (typeof ip !== "string") {
|
|
59
|
+
throw new TypeError("Invalid server address");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
dcId,
|
|
63
|
+
ipAddress: ip,
|
|
64
|
+
ipv6: ip.includes(":"),
|
|
65
|
+
// dumb check but gramjs does this
|
|
66
|
+
port,
|
|
67
|
+
authKey
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function writeGramjsStoreSession(path, session, params) {
|
|
71
|
+
const fs$1 = params?.fs ?? await import("node:fs/promises");
|
|
72
|
+
const sessionName = fs.basename(path);
|
|
73
|
+
await fs$1.mkdir(sessionName, { recursive: true });
|
|
74
|
+
await Promise.all([
|
|
75
|
+
fs$1.writeFile(
|
|
76
|
+
fs.joinPaths(path, `${sessionName}%3AauthKey`),
|
|
77
|
+
utils.utf8.encoder.encode(JSON.stringify({
|
|
78
|
+
type: "Buffer",
|
|
79
|
+
data: Array.from(session.authKey)
|
|
80
|
+
}))
|
|
81
|
+
),
|
|
82
|
+
fs$1.writeFile(fs.joinPaths(path, `${sessionName}%3AdcId`), utils.utf8.encoder.encode(session.dcId.toString())),
|
|
83
|
+
fs$1.writeFile(fs.joinPaths(path, `${sessionName}%3AserverAddress`), utils.utf8.encoder.encode(JSON.stringify(session.ipAddress))),
|
|
84
|
+
fs$1.writeFile(fs.joinPaths(path, `${sessionName}%3Aport`), utils.utf8.encoder.encode(session.port.toString()))
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
exports.readGramjsStoreSession = readGramjsStoreSession;
|
|
88
|
+
exports.writeGramjsStoreSession = writeGramjsStoreSession;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { utf8 } from "@fuman/utils";
|
|
2
|
+
import { basename, joinPaths } from "../utils/fs.js";
|
|
3
|
+
async function readGramjsStoreSession(path, params) {
|
|
4
|
+
const fs = params?.fs ?? await import("node:fs/promises");
|
|
5
|
+
const sessionName = basename(path);
|
|
6
|
+
const [fAuthKey, fDcId, fIpAddress, fPort] = await Promise.all([
|
|
7
|
+
fs.readFile(joinPaths(path, `${sessionName}%3AauthKey`)),
|
|
8
|
+
fs.readFile(joinPaths(path, `${sessionName}%3AdcId`)),
|
|
9
|
+
fs.readFile(joinPaths(path, `${sessionName}%3AserverAddress`)),
|
|
10
|
+
fs.readFile(joinPaths(path, `${sessionName}%3Aport`))
|
|
11
|
+
]);
|
|
12
|
+
const authKeyParsed = JSON.parse(utf8.decoder.decode(fAuthKey));
|
|
13
|
+
if (typeof authKeyParsed !== "object" || authKeyParsed === null || !("type" in authKeyParsed) || authKeyParsed.type !== "Buffer" || !("data" in authKeyParsed) || !Array.isArray(authKeyParsed.data)) {
|
|
14
|
+
throw new Error("Invalid auth key file");
|
|
15
|
+
}
|
|
16
|
+
const authKey = new Uint8Array(authKeyParsed.data);
|
|
17
|
+
if (authKey.length !== 256) {
|
|
18
|
+
throw new Error("Invalid auth key length");
|
|
19
|
+
}
|
|
20
|
+
const dcId = Number.parseInt(utf8.decoder.decode(fDcId));
|
|
21
|
+
if (Number.isNaN(dcId)) {
|
|
22
|
+
throw new TypeError("Invalid dc id");
|
|
23
|
+
}
|
|
24
|
+
const port = Number.parseInt(utf8.decoder.decode(fPort));
|
|
25
|
+
if (Number.isNaN(port)) {
|
|
26
|
+
throw new TypeError("Invalid port");
|
|
27
|
+
}
|
|
28
|
+
const ip = JSON.parse(utf8.decoder.decode(fIpAddress));
|
|
29
|
+
if (typeof ip !== "string") {
|
|
30
|
+
throw new TypeError("Invalid server address");
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
dcId,
|
|
34
|
+
ipAddress: ip,
|
|
35
|
+
ipv6: ip.includes(":"),
|
|
36
|
+
// dumb check but gramjs does this
|
|
37
|
+
port,
|
|
38
|
+
authKey
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function writeGramjsStoreSession(path, session, params) {
|
|
42
|
+
const fs = params?.fs ?? await import("node:fs/promises");
|
|
43
|
+
const sessionName = basename(path);
|
|
44
|
+
await fs.mkdir(sessionName, { recursive: true });
|
|
45
|
+
await Promise.all([
|
|
46
|
+
fs.writeFile(
|
|
47
|
+
joinPaths(path, `${sessionName}%3AauthKey`),
|
|
48
|
+
utf8.encoder.encode(JSON.stringify({
|
|
49
|
+
type: "Buffer",
|
|
50
|
+
data: Array.from(session.authKey)
|
|
51
|
+
}))
|
|
52
|
+
),
|
|
53
|
+
fs.writeFile(joinPaths(path, `${sessionName}%3AdcId`), utf8.encoder.encode(session.dcId.toString())),
|
|
54
|
+
fs.writeFile(joinPaths(path, `${sessionName}%3AserverAddress`), utf8.encoder.encode(JSON.stringify(session.ipAddress))),
|
|
55
|
+
fs.writeFile(joinPaths(path, `${sessionName}%3Aport`), utf8.encoder.encode(session.port.toString()))
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
readGramjsStoreSession,
|
|
60
|
+
writeGramjsStoreSession
|
|
61
|
+
};
|
package/index.cjs
CHANGED
|
@@ -5,22 +5,23 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
5
5
|
}
|
|
6
6
|
"use strict";
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
const dcs = require("./
|
|
9
|
-
const convert = require("./
|
|
10
|
-
const parse = require("./
|
|
11
|
-
const serialize = require("./
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
8
|
+
const dcs = require("./dcs.cjs");
|
|
9
|
+
const convert = require("./gramjs/convert.cjs");
|
|
10
|
+
const parse = require("./gramjs/parse.cjs");
|
|
11
|
+
const serialize = require("./gramjs/serialize.cjs");
|
|
12
|
+
const storeSession = require("./gramjs/store-session.cjs");
|
|
13
|
+
const convert$1 = require("./mtkruto/convert.cjs");
|
|
14
|
+
const parse$1 = require("./mtkruto/parse.cjs");
|
|
15
|
+
const serialize$1 = require("./mtkruto/serialize.cjs");
|
|
16
|
+
const convert$2 = require("./pyrogram/convert.cjs");
|
|
17
|
+
const parse$2 = require("./pyrogram/parse.cjs");
|
|
18
|
+
const serialize$2 = require("./pyrogram/serialize.cjs");
|
|
19
|
+
const convert$3 = require("./tdesktop/convert.cjs");
|
|
20
|
+
const tdata = require("./tdesktop/tdata.cjs");
|
|
21
|
+
const qtBundle = require("./tdesktop/qt-bundle.cjs");
|
|
22
|
+
const convert$4 = require("./telethon/convert.cjs");
|
|
23
|
+
const parse$3 = require("./telethon/parse.cjs");
|
|
24
|
+
const serialize$3 = require("./telethon/serialize.cjs");
|
|
24
25
|
exports.DC_MAPPING_PROD = dcs.DC_MAPPING_PROD;
|
|
25
26
|
exports.DC_MAPPING_TEST = dcs.DC_MAPPING_TEST;
|
|
26
27
|
exports.isTestDc = dcs.isTestDc;
|
|
@@ -28,6 +29,8 @@ exports.convertFromGramjsSession = convert.convertFromGramjsSession;
|
|
|
28
29
|
exports.convertToGramjsSession = convert.convertToGramjsSession;
|
|
29
30
|
exports.parseGramjsSession = parse.parseGramjsSession;
|
|
30
31
|
exports.serializeGramjsSession = serialize.serializeGramjsSession;
|
|
32
|
+
exports.readGramjsStoreSession = storeSession.readGramjsStoreSession;
|
|
33
|
+
exports.writeGramjsStoreSession = storeSession.writeGramjsStoreSession;
|
|
31
34
|
exports.convertFromMtkrutoSession = convert$1.convertFromMtkrutoSession;
|
|
32
35
|
exports.convertToMtkrutoSession = convert$1.convertToMtkrutoSession;
|
|
33
36
|
exports.parseMtkrutoSession = parse$1.parseMtkrutoSession;
|
package/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { DC_MAPPING_PROD, DC_MAPPING_TEST, isTestDc } from "./
|
|
2
|
-
import { convertFromGramjsSession, convertToGramjsSession } from "./
|
|
3
|
-
import { parseGramjsSession } from "./
|
|
4
|
-
import { serializeGramjsSession } from "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
1
|
+
import { DC_MAPPING_PROD, DC_MAPPING_TEST, isTestDc } from "./dcs.js";
|
|
2
|
+
import { convertFromGramjsSession, convertToGramjsSession } from "./gramjs/convert.js";
|
|
3
|
+
import { parseGramjsSession } from "./gramjs/parse.js";
|
|
4
|
+
import { serializeGramjsSession } from "./gramjs/serialize.js";
|
|
5
|
+
import { readGramjsStoreSession, writeGramjsStoreSession } from "./gramjs/store-session.js";
|
|
6
|
+
import { convertFromMtkrutoSession, convertToMtkrutoSession } from "./mtkruto/convert.js";
|
|
7
|
+
import { parseMtkrutoSession } from "./mtkruto/parse.js";
|
|
8
|
+
import { serializeMtkrutoSession } from "./mtkruto/serialize.js";
|
|
9
|
+
import { convertFromPyrogramSession, convertToPyrogramSession } from "./pyrogram/convert.js";
|
|
10
|
+
import { parsePyrogramSession } from "./pyrogram/parse.js";
|
|
11
|
+
import { serializePyrogramSession } from "./pyrogram/serialize.js";
|
|
12
|
+
import { convertFromTdata, convertToTdata } from "./tdesktop/convert.js";
|
|
13
|
+
import { Tdata } from "./tdesktop/tdata.js";
|
|
14
|
+
import * as qtBundle from "./tdesktop/qt-bundle.js";
|
|
15
|
+
import { convertFromTelethonSession, convertToTelethonSession } from "./telethon/convert.js";
|
|
16
|
+
import { parseTelethonSession } from "./telethon/parse.js";
|
|
17
|
+
import { serializeTelethonSession } from "./telethon/serialize.js";
|
|
17
18
|
export {
|
|
18
19
|
DC_MAPPING_PROD,
|
|
19
20
|
DC_MAPPING_TEST,
|
|
@@ -34,8 +35,10 @@ export {
|
|
|
34
35
|
parsePyrogramSession,
|
|
35
36
|
parseTelethonSession,
|
|
36
37
|
qtBundle as qt,
|
|
38
|
+
readGramjsStoreSession,
|
|
37
39
|
serializeGramjsSession,
|
|
38
40
|
serializeMtkrutoSession,
|
|
39
41
|
serializePyrogramSession,
|
|
40
|
-
serializeTelethonSession
|
|
42
|
+
serializeTelethonSession,
|
|
43
|
+
writeGramjsStoreSession
|
|
41
44
|
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/convert",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.8",
|
|
5
5
|
"description": "Cross-library session conversion utilities",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mtcute/core": "^0.19.
|
|
8
|
+
"@mtcute/core": "^0.19.7",
|
|
9
9
|
"@fuman/utils": "0.0.4",
|
|
10
10
|
"@fuman/net": "0.0.9",
|
|
11
11
|
"@fuman/io": "0.0.8"
|
|
12
12
|
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@mtcute/node": "^0.19.3"
|
|
15
|
+
},
|
|
13
16
|
"exports": {
|
|
14
17
|
".": {
|
|
15
18
|
"import": {
|
|
@@ -24,6 +27,11 @@
|
|
|
24
27
|
},
|
|
25
28
|
"author": "alina sireneva <alina@tei.su>",
|
|
26
29
|
"sideEffects": false,
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"@mtcute/node": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
27
35
|
"homepage": "https://mtcute.dev",
|
|
28
36
|
"repository": {
|
|
29
37
|
"type": "git",
|
|
@@ -32,9 +32,10 @@ async function getDefaultCryptoProvider() {
|
|
|
32
32
|
/* @vite-ignore */
|
|
33
33
|
await import("node:crypto")
|
|
34
34
|
);
|
|
35
|
-
const
|
|
35
|
+
const nodeModule = "@mtcute/node/utils.js";
|
|
36
|
+
const { NodeCryptoProvider } = await import(
|
|
36
37
|
/* @vite-ignore */
|
|
37
|
-
|
|
38
|
+
nodeModule
|
|
38
39
|
);
|
|
39
40
|
return new class extends NodeCryptoProvider {
|
|
40
41
|
createHash(algorithm) {
|
|
@@ -3,9 +3,10 @@ async function getDefaultCryptoProvider() {
|
|
|
3
3
|
/* @vite-ignore */
|
|
4
4
|
await import("node:crypto")
|
|
5
5
|
);
|
|
6
|
-
const
|
|
6
|
+
const nodeModule = "@mtcute/node/utils.js";
|
|
7
|
+
const { NodeCryptoProvider } = await import(
|
|
7
8
|
/* @vite-ignore */
|
|
8
|
-
|
|
9
|
+
nodeModule
|
|
9
10
|
);
|
|
10
11
|
return new class extends NodeCryptoProvider {
|
|
11
12
|
createHash(algorithm) {
|
|
@@ -8,6 +8,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
function dirname(path) {
|
|
9
9
|
return path.replace(/[/\\][^/\\]*$/, "");
|
|
10
10
|
}
|
|
11
|
+
function basename(path) {
|
|
12
|
+
return path.replace(/^.*[/\\]/, "");
|
|
13
|
+
}
|
|
11
14
|
function joinPaths(...paths) {
|
|
12
15
|
const parts = [];
|
|
13
16
|
let guessedSep;
|
|
@@ -29,5 +32,6 @@ function joinPaths(...paths) {
|
|
|
29
32
|
}
|
|
30
33
|
return parts.join(guessedSep ?? "/");
|
|
31
34
|
}
|
|
35
|
+
exports.basename = basename;
|
|
32
36
|
exports.dirname = dirname;
|
|
33
37
|
exports.joinPaths = joinPaths;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
function dirname(path) {
|
|
2
2
|
return path.replace(/[/\\][^/\\]*$/, "");
|
|
3
3
|
}
|
|
4
|
+
function basename(path) {
|
|
5
|
+
return path.replace(/^.*[/\\]/, "");
|
|
6
|
+
}
|
|
4
7
|
function joinPaths(...paths) {
|
|
5
8
|
const parts = [];
|
|
6
9
|
let guessedSep;
|
|
@@ -23,6 +26,7 @@ function joinPaths(...paths) {
|
|
|
23
26
|
return parts.join(guessedSep ?? "/");
|
|
24
27
|
}
|
|
25
28
|
export {
|
|
29
|
+
basename,
|
|
26
30
|
dirname,
|
|
27
31
|
joinPaths
|
|
28
32
|
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
-
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
-
console.warn("[@mtcute/convert] CommonJS support is deprecated and will be removed in 0.25.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
-
console.warn("[@mtcute/convert] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
-
}
|
|
6
|
-
"use strict";
|
|
7
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
const node_crypto = require("node:crypto");
|
|
9
|
-
const promises = require("node:fs/promises");
|
|
10
|
-
const node_module = require("node:module");
|
|
11
|
-
const node_zlib = require("node:zlib");
|
|
12
|
-
const utils_js = require("@mtcute/core/utils.js");
|
|
13
|
-
const index = require("../../../wasm/src/index.cjs");
|
|
14
|
-
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
15
|
-
class BaseNodeCryptoProvider extends utils_js.BaseCryptoProvider {
|
|
16
|
-
createAesCtr(key, iv) {
|
|
17
|
-
const cipher = node_crypto.createCipheriv(`aes-${key.length * 8}-ctr`, key, iv);
|
|
18
|
-
const update = (data) => cipher.update(data);
|
|
19
|
-
return {
|
|
20
|
-
process: update
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
pbkdf2(password, salt, iterations, keylen = 64, algo = "sha512") {
|
|
24
|
-
return new Promise(
|
|
25
|
-
(resolve, reject) => node_crypto.pbkdf2(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve(buf))
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
sha1(data) {
|
|
29
|
-
return node_crypto.createHash("sha1").update(data).digest();
|
|
30
|
-
}
|
|
31
|
-
sha256(data) {
|
|
32
|
-
return node_crypto.createHash("sha256").update(data).digest();
|
|
33
|
-
}
|
|
34
|
-
hmacSha256(data, key) {
|
|
35
|
-
return node_crypto.createHmac("sha256", key).update(data).digest();
|
|
36
|
-
}
|
|
37
|
-
gzip(data, maxSize) {
|
|
38
|
-
try {
|
|
39
|
-
return node_zlib.deflateSync(data, {
|
|
40
|
-
maxOutputLength: maxSize
|
|
41
|
-
});
|
|
42
|
-
} catch (e) {
|
|
43
|
-
if (e.code === "ERR_BUFFER_TOO_LARGE") {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
gunzip(data) {
|
|
50
|
-
return node_zlib.gunzipSync(data);
|
|
51
|
-
}
|
|
52
|
-
randomFill(buf) {
|
|
53
|
-
node_crypto.randomFillSync(buf);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
class NodeCryptoProvider extends BaseNodeCryptoProvider {
|
|
57
|
-
async initialize() {
|
|
58
|
-
const require$1 = node_module.createRequire(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("node/src/utils/crypto.cjs", document.baseURI).href);
|
|
59
|
-
const wasmFile = require$1.resolve("@mtcute/wasm/mtcute.wasm");
|
|
60
|
-
const wasm = await promises.readFile(wasmFile);
|
|
61
|
-
index.initSync(wasm);
|
|
62
|
-
}
|
|
63
|
-
createAesIge(key, iv) {
|
|
64
|
-
return {
|
|
65
|
-
encrypt(data) {
|
|
66
|
-
return index.ige256Encrypt(data, key, iv);
|
|
67
|
-
},
|
|
68
|
-
decrypt(data) {
|
|
69
|
-
return index.ige256Decrypt(data, key, iv);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.BaseNodeCryptoProvider = BaseNodeCryptoProvider;
|
|
75
|
-
exports.NodeCryptoProvider = NodeCryptoProvider;
|
package/node/src/utils/crypto.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createCipheriv, pbkdf2, createHash, createHmac, randomFillSync } from "node:crypto";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import { deflateSync, gunzipSync } from "node:zlib";
|
|
5
|
-
import { BaseCryptoProvider } from "@mtcute/core/utils.js";
|
|
6
|
-
import { initSync, ige256Decrypt, ige256Encrypt } from "../../../wasm/src/index.js";
|
|
7
|
-
class BaseNodeCryptoProvider extends BaseCryptoProvider {
|
|
8
|
-
createAesCtr(key, iv) {
|
|
9
|
-
const cipher = createCipheriv(`aes-${key.length * 8}-ctr`, key, iv);
|
|
10
|
-
const update = (data) => cipher.update(data);
|
|
11
|
-
return {
|
|
12
|
-
process: update
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
pbkdf2(password, salt, iterations, keylen = 64, algo = "sha512") {
|
|
16
|
-
return new Promise(
|
|
17
|
-
(resolve, reject) => pbkdf2(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve(buf))
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
sha1(data) {
|
|
21
|
-
return createHash("sha1").update(data).digest();
|
|
22
|
-
}
|
|
23
|
-
sha256(data) {
|
|
24
|
-
return createHash("sha256").update(data).digest();
|
|
25
|
-
}
|
|
26
|
-
hmacSha256(data, key) {
|
|
27
|
-
return createHmac("sha256", key).update(data).digest();
|
|
28
|
-
}
|
|
29
|
-
gzip(data, maxSize) {
|
|
30
|
-
try {
|
|
31
|
-
return deflateSync(data, {
|
|
32
|
-
maxOutputLength: maxSize
|
|
33
|
-
});
|
|
34
|
-
} catch (e) {
|
|
35
|
-
if (e.code === "ERR_BUFFER_TOO_LARGE") {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
gunzip(data) {
|
|
42
|
-
return gunzipSync(data);
|
|
43
|
-
}
|
|
44
|
-
randomFill(buf) {
|
|
45
|
-
randomFillSync(buf);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class NodeCryptoProvider extends BaseNodeCryptoProvider {
|
|
49
|
-
async initialize() {
|
|
50
|
-
const require2 = createRequire(import.meta.url);
|
|
51
|
-
const wasmFile = require2.resolve("@mtcute/wasm/mtcute.wasm");
|
|
52
|
-
const wasm = await readFile(wasmFile);
|
|
53
|
-
initSync(wasm);
|
|
54
|
-
}
|
|
55
|
-
createAesIge(key, iv) {
|
|
56
|
-
return {
|
|
57
|
-
encrypt(data) {
|
|
58
|
-
return ige256Encrypt(data, key, iv);
|
|
59
|
-
},
|
|
60
|
-
decrypt(data) {
|
|
61
|
-
return ige256Decrypt(data, key, iv);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
BaseNodeCryptoProvider,
|
|
68
|
-
NodeCryptoProvider
|
|
69
|
-
};
|
package/node/src/utils.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
-
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
-
console.warn("[@mtcute/convert] CommonJS support is deprecated and will be removed in 0.25.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
-
console.warn("[@mtcute/convert] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
-
}
|
|
6
|
-
"use strict";
|
|
7
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
const crypto = require("./utils/crypto.cjs");
|
|
9
|
-
const utils_js = require("@mtcute/core/utils.js");
|
|
10
|
-
function _interopNamespaceDefault(e) {
|
|
11
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
|
-
if (e) {
|
|
13
|
-
for (const k in e) {
|
|
14
|
-
if (k !== "default") {
|
|
15
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: () => e[k]
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n.default = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
const utils_js__namespace = /* @__PURE__ */ _interopNamespaceDefault(utils_js);
|
|
27
|
-
exports.BaseNodeCryptoProvider = crypto.BaseNodeCryptoProvider;
|
|
28
|
-
exports.NodeCryptoProvider = crypto.NodeCryptoProvider;
|
|
29
|
-
Object.keys(utils_js).forEach((k) => {
|
|
30
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: () => utils_js[k]
|
|
33
|
-
});
|
|
34
|
-
});
|
package/node/src/utils.js
DELETED
package/wasm/src/index.cjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
-
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
-
console.warn("[@mtcute/convert] CommonJS support is deprecated and will be removed in 0.25.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
-
console.warn("[@mtcute/convert] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
-
}
|
|
6
|
-
"use strict";
|
|
7
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
let wasm;
|
|
9
|
-
let sharedKeyPtr;
|
|
10
|
-
let sharedIvPtr;
|
|
11
|
-
let cachedUint8Memory = null;
|
|
12
|
-
function initCommon() {
|
|
13
|
-
wasm.libdeflate_alloc_compressor(6);
|
|
14
|
-
wasm.libdeflate_alloc_decompressor();
|
|
15
|
-
wasm.__get_shared_out();
|
|
16
|
-
sharedKeyPtr = wasm.__get_shared_key_buffer();
|
|
17
|
-
sharedIvPtr = wasm.__get_shared_iv_buffer();
|
|
18
|
-
}
|
|
19
|
-
function getUint8Memory() {
|
|
20
|
-
if (cachedUint8Memory === null || cachedUint8Memory.byteLength === 0) {
|
|
21
|
-
cachedUint8Memory = new Uint8Array(wasm.memory.buffer);
|
|
22
|
-
}
|
|
23
|
-
return cachedUint8Memory;
|
|
24
|
-
}
|
|
25
|
-
function initSync(module2) {
|
|
26
|
-
if (wasm !== void 0) return;
|
|
27
|
-
if (!(module2 instanceof WebAssembly.Instance)) {
|
|
28
|
-
if (!(module2 instanceof WebAssembly.Module)) {
|
|
29
|
-
module2 = new WebAssembly.Module(module2);
|
|
30
|
-
}
|
|
31
|
-
module2 = new WebAssembly.Instance(module2);
|
|
32
|
-
}
|
|
33
|
-
wasm = module2.exports;
|
|
34
|
-
initCommon();
|
|
35
|
-
}
|
|
36
|
-
function ige256Encrypt(data, key, iv) {
|
|
37
|
-
const ptr = wasm.__malloc(data.length + data.length);
|
|
38
|
-
const inputPtr = ptr;
|
|
39
|
-
const outputPtr = inputPtr + data.length;
|
|
40
|
-
const mem = getUint8Memory();
|
|
41
|
-
mem.set(data, inputPtr);
|
|
42
|
-
mem.set(key, sharedKeyPtr);
|
|
43
|
-
mem.set(iv, sharedIvPtr);
|
|
44
|
-
wasm.ige256_encrypt(inputPtr, data.length, outputPtr);
|
|
45
|
-
const result = mem.slice(outputPtr, outputPtr + data.length);
|
|
46
|
-
wasm.__free(ptr);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
function ige256Decrypt(data, key, iv) {
|
|
50
|
-
const ptr = wasm.__malloc(data.length + data.length);
|
|
51
|
-
const inputPtr = ptr;
|
|
52
|
-
const outputPtr = inputPtr + data.length;
|
|
53
|
-
const mem = getUint8Memory();
|
|
54
|
-
mem.set(data, inputPtr);
|
|
55
|
-
mem.set(key, sharedKeyPtr);
|
|
56
|
-
mem.set(iv, sharedIvPtr);
|
|
57
|
-
wasm.ige256_decrypt(inputPtr, data.length, outputPtr);
|
|
58
|
-
const result = mem.slice(outputPtr, outputPtr + data.length);
|
|
59
|
-
wasm.__free(ptr);
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
exports.ige256Decrypt = ige256Decrypt;
|
|
63
|
-
exports.ige256Encrypt = ige256Encrypt;
|
|
64
|
-
exports.initSync = initSync;
|
package/wasm/src/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
let wasm;
|
|
2
|
-
let sharedKeyPtr;
|
|
3
|
-
let sharedIvPtr;
|
|
4
|
-
let cachedUint8Memory = null;
|
|
5
|
-
function initCommon() {
|
|
6
|
-
wasm.libdeflate_alloc_compressor(6);
|
|
7
|
-
wasm.libdeflate_alloc_decompressor();
|
|
8
|
-
wasm.__get_shared_out();
|
|
9
|
-
sharedKeyPtr = wasm.__get_shared_key_buffer();
|
|
10
|
-
sharedIvPtr = wasm.__get_shared_iv_buffer();
|
|
11
|
-
}
|
|
12
|
-
function getUint8Memory() {
|
|
13
|
-
if (cachedUint8Memory === null || cachedUint8Memory.byteLength === 0) {
|
|
14
|
-
cachedUint8Memory = new Uint8Array(wasm.memory.buffer);
|
|
15
|
-
}
|
|
16
|
-
return cachedUint8Memory;
|
|
17
|
-
}
|
|
18
|
-
function initSync(module) {
|
|
19
|
-
if (wasm !== void 0) return;
|
|
20
|
-
if (!(module instanceof WebAssembly.Instance)) {
|
|
21
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
22
|
-
module = new WebAssembly.Module(module);
|
|
23
|
-
}
|
|
24
|
-
module = new WebAssembly.Instance(module);
|
|
25
|
-
}
|
|
26
|
-
wasm = module.exports;
|
|
27
|
-
initCommon();
|
|
28
|
-
}
|
|
29
|
-
function ige256Encrypt(data, key, iv) {
|
|
30
|
-
const ptr = wasm.__malloc(data.length + data.length);
|
|
31
|
-
const inputPtr = ptr;
|
|
32
|
-
const outputPtr = inputPtr + data.length;
|
|
33
|
-
const mem = getUint8Memory();
|
|
34
|
-
mem.set(data, inputPtr);
|
|
35
|
-
mem.set(key, sharedKeyPtr);
|
|
36
|
-
mem.set(iv, sharedIvPtr);
|
|
37
|
-
wasm.ige256_encrypt(inputPtr, data.length, outputPtr);
|
|
38
|
-
const result = mem.slice(outputPtr, outputPtr + data.length);
|
|
39
|
-
wasm.__free(ptr);
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
function ige256Decrypt(data, key, iv) {
|
|
43
|
-
const ptr = wasm.__malloc(data.length + data.length);
|
|
44
|
-
const inputPtr = ptr;
|
|
45
|
-
const outputPtr = inputPtr + data.length;
|
|
46
|
-
const mem = getUint8Memory();
|
|
47
|
-
mem.set(data, inputPtr);
|
|
48
|
-
mem.set(key, sharedKeyPtr);
|
|
49
|
-
mem.set(iv, sharedIvPtr);
|
|
50
|
-
wasm.ige256_decrypt(inputPtr, data.length, outputPtr);
|
|
51
|
-
const result = mem.slice(outputPtr, outputPtr + data.length);
|
|
52
|
-
wasm.__free(ptr);
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
export {
|
|
56
|
-
ige256Decrypt,
|
|
57
|
-
ige256Encrypt,
|
|
58
|
-
initSync
|
|
59
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|