@mtcute/convert 0.19.4 → 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.
Files changed (55) hide show
  1. package/gramjs/convert.d.cts +2 -2
  2. package/gramjs/convert.d.ts +2 -2
  3. package/index.cjs +17 -17
  4. package/index.js +17 -17
  5. package/package.json +10 -2
  6. package/{convert/src/utils → utils}/crypto.cjs +3 -2
  7. package/{convert/src/utils → utils}/crypto.js +3 -2
  8. package/node/src/utils/crypto.cjs +0 -75
  9. package/node/src/utils/crypto.js +0 -69
  10. package/node/src/utils.cjs +0 -34
  11. package/node/src/utils.js +0 -7
  12. package/wasm/src/index.cjs +0 -64
  13. package/wasm/src/index.js +0 -59
  14. /package/{convert/src/dcs.cjs → dcs.cjs} +0 -0
  15. /package/{convert/src/dcs.js → dcs.js} +0 -0
  16. /package/{convert/src/gramjs → gramjs}/convert.cjs +0 -0
  17. /package/{convert/src/gramjs → gramjs}/convert.js +0 -0
  18. /package/{convert/src/gramjs → gramjs}/parse.cjs +0 -0
  19. /package/{convert/src/gramjs → gramjs}/parse.js +0 -0
  20. /package/{convert/src/gramjs → gramjs}/serialize.cjs +0 -0
  21. /package/{convert/src/gramjs → gramjs}/serialize.js +0 -0
  22. /package/{convert/src/gramjs → gramjs}/store-session.cjs +0 -0
  23. /package/{convert/src/gramjs → gramjs}/store-session.js +0 -0
  24. /package/{convert/src/mtkruto → mtkruto}/convert.cjs +0 -0
  25. /package/{convert/src/mtkruto → mtkruto}/convert.js +0 -0
  26. /package/{convert/src/mtkruto → mtkruto}/parse.cjs +0 -0
  27. /package/{convert/src/mtkruto → mtkruto}/parse.js +0 -0
  28. /package/{convert/src/mtkruto → mtkruto}/serialize.cjs +0 -0
  29. /package/{convert/src/mtkruto → mtkruto}/serialize.js +0 -0
  30. /package/{convert/src/pyrogram → pyrogram}/convert.cjs +0 -0
  31. /package/{convert/src/pyrogram → pyrogram}/convert.js +0 -0
  32. /package/{convert/src/pyrogram → pyrogram}/parse.cjs +0 -0
  33. /package/{convert/src/pyrogram → pyrogram}/parse.js +0 -0
  34. /package/{convert/src/pyrogram → pyrogram}/serialize.cjs +0 -0
  35. /package/{convert/src/pyrogram → pyrogram}/serialize.js +0 -0
  36. /package/{convert/src/tdesktop → tdesktop}/convert.cjs +0 -0
  37. /package/{convert/src/tdesktop → tdesktop}/convert.js +0 -0
  38. /package/{convert/src/tdesktop → tdesktop}/qt-bundle.cjs +0 -0
  39. /package/{convert/src/tdesktop → tdesktop}/qt-bundle.js +0 -0
  40. /package/{convert/src/tdesktop → tdesktop}/qt-reader.cjs +0 -0
  41. /package/{convert/src/tdesktop → tdesktop}/qt-reader.js +0 -0
  42. /package/{convert/src/tdesktop → tdesktop}/qt-writer.cjs +0 -0
  43. /package/{convert/src/tdesktop → tdesktop}/qt-writer.js +0 -0
  44. /package/{convert/src/tdesktop → tdesktop}/tdata.cjs +0 -0
  45. /package/{convert/src/tdesktop → tdesktop}/tdata.js +0 -0
  46. /package/{convert/src/telethon → telethon}/convert.cjs +0 -0
  47. /package/{convert/src/telethon → telethon}/convert.js +0 -0
  48. /package/{convert/src/telethon → telethon}/parse.cjs +0 -0
  49. /package/{convert/src/telethon → telethon}/parse.js +0 -0
  50. /package/{convert/src/telethon → telethon}/serialize.cjs +0 -0
  51. /package/{convert/src/telethon → telethon}/serialize.js +0 -0
  52. /package/{convert/src/utils → utils}/fs.cjs +0 -0
  53. /package/{convert/src/utils → utils}/fs.js +0 -0
  54. /package/{convert/src/utils → utils}/rle.cjs +0 -0
  55. /package/{convert/src/utils → utils}/rle.js +0 -0
@@ -1,4 +1,4 @@
1
1
  import { StringSessionData } from '@mtcute/core/utils.js';
2
- import { TelethonSession } from '../telethon/types.js';
3
- export declare function convertFromGramjsSession(session: TelethonSession | string): StringSessionData;
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;
@@ -1,4 +1,4 @@
1
1
  import { StringSessionData } from '@mtcute/core/utils.js';
2
- import { TelethonSession } from '../telethon/types.js';
3
- export declare function convertFromGramjsSession(session: TelethonSession | string): StringSessionData;
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/index.cjs CHANGED
@@ -5,23 +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("./convert/src/dcs.cjs");
9
- const convert = require("./convert/src/gramjs/convert.cjs");
10
- const parse = require("./convert/src/gramjs/parse.cjs");
11
- const serialize = require("./convert/src/gramjs/serialize.cjs");
12
- const storeSession = require("./convert/src/gramjs/store-session.cjs");
13
- const convert$1 = require("./convert/src/mtkruto/convert.cjs");
14
- const parse$1 = require("./convert/src/mtkruto/parse.cjs");
15
- const serialize$1 = require("./convert/src/mtkruto/serialize.cjs");
16
- const convert$2 = require("./convert/src/pyrogram/convert.cjs");
17
- const parse$2 = require("./convert/src/pyrogram/parse.cjs");
18
- const serialize$2 = require("./convert/src/pyrogram/serialize.cjs");
19
- const convert$3 = require("./convert/src/tdesktop/convert.cjs");
20
- const tdata = require("./convert/src/tdesktop/tdata.cjs");
21
- const qtBundle = require("./convert/src/tdesktop/qt-bundle.cjs");
22
- const convert$4 = require("./convert/src/telethon/convert.cjs");
23
- const parse$3 = require("./convert/src/telethon/parse.cjs");
24
- const serialize$3 = require("./convert/src/telethon/serialize.cjs");
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");
25
25
  exports.DC_MAPPING_PROD = dcs.DC_MAPPING_PROD;
26
26
  exports.DC_MAPPING_TEST = dcs.DC_MAPPING_TEST;
27
27
  exports.isTestDc = dcs.isTestDc;
package/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { DC_MAPPING_PROD, DC_MAPPING_TEST, isTestDc } from "./convert/src/dcs.js";
2
- import { convertFromGramjsSession, convertToGramjsSession } from "./convert/src/gramjs/convert.js";
3
- import { parseGramjsSession } from "./convert/src/gramjs/parse.js";
4
- import { serializeGramjsSession } from "./convert/src/gramjs/serialize.js";
5
- import { readGramjsStoreSession, writeGramjsStoreSession } from "./convert/src/gramjs/store-session.js";
6
- import { convertFromMtkrutoSession, convertToMtkrutoSession } from "./convert/src/mtkruto/convert.js";
7
- import { parseMtkrutoSession } from "./convert/src/mtkruto/parse.js";
8
- import { serializeMtkrutoSession } from "./convert/src/mtkruto/serialize.js";
9
- import { convertFromPyrogramSession, convertToPyrogramSession } from "./convert/src/pyrogram/convert.js";
10
- import { parsePyrogramSession } from "./convert/src/pyrogram/parse.js";
11
- import { serializePyrogramSession } from "./convert/src/pyrogram/serialize.js";
12
- import { convertFromTdata, convertToTdata } from "./convert/src/tdesktop/convert.js";
13
- import { Tdata } from "./convert/src/tdesktop/tdata.js";
14
- import * as qtBundle from "./convert/src/tdesktop/qt-bundle.js";
15
- import { convertFromTelethonSession, convertToTelethonSession } from "./convert/src/telethon/convert.js";
16
- import { parseTelethonSession } from "./convert/src/telethon/parse.js";
17
- import { serializeTelethonSession } from "./convert/src/telethon/serialize.js";
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";
18
18
  export {
19
19
  DC_MAPPING_PROD,
20
20
  DC_MAPPING_TEST,
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@mtcute/convert",
3
3
  "type": "module",
4
- "version": "0.19.4",
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.3",
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 { NodeCryptoProvider } = (
35
+ const nodeModule = "@mtcute/node/utils.js";
36
+ const { NodeCryptoProvider } = await import(
36
37
  /* @vite-ignore */
37
- await Promise.resolve().then(() => require("../../../node/src/utils.cjs"))
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 { NodeCryptoProvider } = (
6
+ const nodeModule = "@mtcute/node/utils.js";
7
+ const { NodeCryptoProvider } = await import(
7
8
  /* @vite-ignore */
8
- await import("../../../node/src/utils.js")
9
+ nodeModule
9
10
  );
10
11
  return new class extends NodeCryptoProvider {
11
12
  createHash(algorithm) {
@@ -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;
@@ -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
- };
@@ -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
@@ -1,7 +0,0 @@
1
- import { BaseNodeCryptoProvider, NodeCryptoProvider } from "./utils/crypto.js";
2
- import * as utils_js from "@mtcute/core/utils.js";
3
- export * from "@mtcute/core/utils.js";
4
- export {
5
- BaseNodeCryptoProvider,
6
- NodeCryptoProvider
7
- };
@@ -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