@mtkruto/node 0.1.0 → 0.1.100

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 (29) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +1 -1
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.2}/mod.d.ts +2 -6
  6. package/esm/deps/deno.land/x/tgcrypto@0.3.2/mod.js +158 -0
  7. package/esm/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +308 -0
  8. package/esm/transport/0_obfuscation.js +1 -1
  9. package/esm/transport/0_transport.js +2 -2
  10. package/esm/utilities/0_crypto.d.ts +1 -2
  11. package/esm/utilities/0_crypto.js +3 -12
  12. package/package.json +1 -1
  13. package/script/0_deps.d.ts +1 -1
  14. package/script/0_deps.js +3 -4
  15. package/script/4_constants.d.ts +1 -1
  16. package/script/4_constants.js +1 -1
  17. package/script/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.2}/mod.d.ts +2 -6
  18. package/script/deps/deno.land/x/tgcrypto@0.3.2/mod.js +171 -0
  19. package/script/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +310 -0
  20. package/script/transport/0_obfuscation.js +1 -1
  21. package/script/transport/0_transport.js +2 -2
  22. package/script/utilities/0_crypto.d.ts +1 -2
  23. package/script/utilities/0_crypto.js +2 -11
  24. package/esm/deps/deno.land/x/tgcrypto@0.2.1/mod.js +0 -81
  25. package/esm/deps/deno.land/x/tgcrypto@0.2.1/tgcrypto.js +0 -991
  26. package/script/deps/deno.land/x/tgcrypto@0.2.1/mod.js +0 -95
  27. package/script/deps/deno.land/x/tgcrypto@0.2.1/tgcrypto.js +0 -993
  28. /package/esm/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.2}/tgcrypto.d.ts +0 -0
  29. /package/script/deps/deno.land/x/{tgcrypto@0.2.1 → tgcrypto@0.3.2}/tgcrypto.d.ts +0 -0
@@ -22,7 +22,7 @@ export async function getObfuscationParameters(protocol, connection) {
22
22
  const encryptKey = init.slice(8, 8 + 32);
23
23
  const encryptIv = init.slice(40, 40 + 16);
24
24
  const encryptionCTR = new CTR(encryptKey, encryptIv);
25
- const encryptedInit = encryptionCTR.encrypt(init);
25
+ const encryptedInit = encryptionCTR.call(init);
26
26
  const initRev = new Uint8Array(init).reverse();
27
27
  const decryptKey = initRev.slice(8, 8 + 32);
28
28
  const decryptIv = initRev.slice(40, 40 + 16);
@@ -15,7 +15,7 @@ export class Transport {
15
15
  }
16
16
  encrypt(buffer) {
17
17
  if (this.obfuscationParameters) {
18
- return this.obfuscationParameters.encryptionCTR.encrypt(buffer);
18
+ return this.obfuscationParameters.encryptionCTR.call(buffer);
19
19
  }
20
20
  else {
21
21
  return buffer;
@@ -23,7 +23,7 @@ export class Transport {
23
23
  }
24
24
  decrypt(buffer) {
25
25
  if (this.obfuscationParameters) {
26
- return this.obfuscationParameters.decryptionCTR.decrypt(buffer);
26
+ return this.obfuscationParameters.decryptionCTR.call(buffer);
27
27
  }
28
28
  else {
29
29
  return buffer;
@@ -3,6 +3,5 @@ export declare class CTR {
3
3
  iv: Uint8Array;
4
4
  state: Uint8Array;
5
5
  constructor(key: Uint8Array, iv: Uint8Array);
6
- encrypt(data: Uint8Array): Uint8Array;
7
- decrypt(data: Uint8Array): Uint8Array;
6
+ call(data: Uint8Array): Uint8Array;
8
7
  }
@@ -1,4 +1,4 @@
1
- import { ctr256Decrypt, ctr256Encrypt } from "../0_deps.js";
1
+ import { ctr256 } from "../0_deps.js";
2
2
  export class CTR {
3
3
  constructor(key, iv) {
4
4
  Object.defineProperty(this, "key", {
@@ -20,18 +20,9 @@ export class CTR {
20
20
  value: new Uint8Array(1)
21
21
  });
22
22
  }
23
- encrypt(data) {
23
+ call(data) {
24
24
  const v = new Uint8Array(data); // TODO: don't copy
25
- const [iv, state] = ctr256Encrypt(v, this.key, this.iv, this.state);
26
- this.iv = iv;
27
- this.state = state;
28
- return v;
29
- }
30
- decrypt(data) {
31
- const v = new Uint8Array(data); // TODO: don't copy
32
- const [iv, state] = ctr256Decrypt(v, this.key, this.iv, this.state);
33
- this.iv = iv;
34
- this.state = state;
25
+ ctr256(v, this.key, this.iv, this.state);
35
26
  return v;
36
27
  }
37
28
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.1.0",
5
+ "version": "0.1.100",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1,5 +1,5 @@
1
1
  export * from "./deps/deno.land/std@0.201.0/assert/mod.js";
2
- export { ctr256Decrypt, ctr256Encrypt, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.2.1/mod.js";
2
+ export { ctr256, factorize, ige256Decrypt, ige256Encrypt, init as initTgCrypto } from "./deps/deno.land/x/tgcrypto@0.3.2/mod.js";
3
3
  export { gunzip, gzip } from "./deps/raw.githubusercontent.com/MTKruto/compress/main/gzip/gzip.js";
4
4
  export { Mutex, type MutexInterface } from "async-mutex";
5
5
  export { Parser } from "./deps/deno.land/x/html_parser@v0.1.3/src/mod.js";
package/script/0_deps.js CHANGED
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.base64Encode = exports.base64Decode = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256Encrypt = exports.ctr256Decrypt = void 0;
17
+ exports.base64Encode = exports.base64Decode = exports.debug = exports.Parser = exports.Mutex = exports.gzip = exports.gunzip = exports.initTgCrypto = exports.ige256Encrypt = exports.ige256Decrypt = exports.factorize = exports.ctr256 = void 0;
18
18
  __exportStar(require("./deps/deno.land/std@0.201.0/assert/mod.js"), exports);
19
- var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.2.1/mod.js");
20
- Object.defineProperty(exports, "ctr256Decrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Decrypt; } });
21
- Object.defineProperty(exports, "ctr256Encrypt", { enumerable: true, get: function () { return mod_js_1.ctr256Encrypt; } });
19
+ var mod_js_1 = require("./deps/deno.land/x/tgcrypto@0.3.2/mod.js");
20
+ Object.defineProperty(exports, "ctr256", { enumerable: true, get: function () { return mod_js_1.ctr256; } });
22
21
  Object.defineProperty(exports, "factorize", { enumerable: true, get: function () { return mod_js_1.factorize; } });
23
22
  Object.defineProperty(exports, "ige256Decrypt", { enumerable: true, get: function () { return mod_js_1.ige256Decrypt; } });
24
23
  Object.defineProperty(exports, "ige256Encrypt", { enumerable: true, get: function () { return mod_js_1.ige256Encrypt; } });
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.1.0";
8
+ export declare const APP_VERSION = "MTKruto 0.1.100";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.1.0";
83
+ exports.APP_VERSION = "MTKruto 0.1.100";
84
84
  // @ts-ignore: lib
85
85
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -16,18 +16,14 @@ export declare function ige256Encrypt(data: Uint8Array, key: Uint8Array, iv: Uin
16
16
  */
17
17
  export declare function ige256Decrypt(data: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
18
18
  /**
19
- * Performs CTR-256 encryption.
19
+ * Performs CTR-256 encryption/decryption.
20
20
  *
21
21
  * @param data The data, larger than a byte
22
22
  * @param key 32-byte encryption key
23
23
  * @param iv 16-byte initialization vector
24
24
  * @param state 1-byte state
25
25
  */
26
- export declare function ctr256Encrypt(data: Uint8Array, key: Uint8Array, iv: Uint8Array, state: Uint8Array): [Uint8Array, Uint8Array];
27
- /**
28
- * Alias of `ctr256Encrypt`
29
- */
30
- export declare function ctr256Decrypt(data: Uint8Array, key: Uint8Array, iv: Uint8Array, state: Uint8Array): [Uint8Array, Uint8Array];
26
+ export declare function ctr256(data: Uint8Array, key: Uint8Array, iv: Uint8Array, state: Uint8Array): void;
31
27
  /**
32
28
  * Performs CBC-256 encryption.
33
29
  *
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.factorize = exports.cbc256Decrypt = exports.cbc256Encrypt = exports.ctr256 = exports.ige256Decrypt = exports.ige256Encrypt = exports.init = void 0;
7
+ const tgcrypto_js_1 = __importDefault(require("./tgcrypto.js"));
8
+ // deno-lint-ignore no-explicit-any
9
+ let module_;
10
+ const promise = (0, tgcrypto_js_1.default)().then((v) => module_ = v);
11
+ async function init() {
12
+ await promise;
13
+ }
14
+ exports.init = init;
15
+ function checkIgeParams(data, key, iv) {
16
+ if (data.length == 0) {
17
+ throw new TypeError("data must not be empty");
18
+ }
19
+ else if (data.length % 16 != 0) {
20
+ throw new TypeError("data must consist of a number of bytes that is divisible by 16");
21
+ }
22
+ else if (key.length != 32) {
23
+ throw new TypeError("key must be 32 bytes");
24
+ }
25
+ else if (iv.length != 32) {
26
+ throw new TypeError("iv must be 32 bytes");
27
+ }
28
+ }
29
+ /**
30
+ * Performs IGE-256 encryption.
31
+ *
32
+ * @param data The unencrypted data, larger than a byte, divisible by 16
33
+ * @param key 32-byte encryption key
34
+ * @param iv 32-byte initialization vector
35
+ */
36
+ function ige256Encrypt(data, key, iv) {
37
+ checkIgeParams(data, key, iv);
38
+ const out = module_._malloc(1024);
39
+ module_.ccall("ige256_encrypt", "void", ["array", "pointer", "number", "array", "array"], [data, out, data.length, key, iv]);
40
+ try {
41
+ return module_.HEAPU8.slice(out, out + data.length);
42
+ }
43
+ finally {
44
+ module_._free(out);
45
+ }
46
+ }
47
+ exports.ige256Encrypt = ige256Encrypt;
48
+ /**
49
+ * Performs IGE-256 decryption.
50
+ *
51
+ * @param data The encrypted data, larger than a byte, divisible by 16
52
+ * @param key 32-byte encryption key
53
+ * @param iv 32-byte initialization vector
54
+ */
55
+ function ige256Decrypt(data, key, iv) {
56
+ checkIgeParams(data, key, iv);
57
+ const out = module_._malloc(1024);
58
+ module_.ccall("ige256_decrypt", "void", ["array", "pointer", "number", "array", "array"], [data, out, data.length, key, iv]);
59
+ try {
60
+ return module_.HEAPU8.slice(out, out + data.length);
61
+ }
62
+ finally {
63
+ module_._free(out);
64
+ }
65
+ }
66
+ exports.ige256Decrypt = ige256Decrypt;
67
+ function checkCtrParams(data, key, iv, state) {
68
+ if (data.length == 0) {
69
+ throw new TypeError("data must not be empty");
70
+ }
71
+ else if (key.length != 32) {
72
+ throw new TypeError("key must be 32 bytes");
73
+ }
74
+ else if (iv.length != 16) {
75
+ throw new TypeError("iv must be 16 bytes");
76
+ }
77
+ else if (state.length != 1) {
78
+ throw new TypeError("state must be 1 byte");
79
+ }
80
+ }
81
+ /**
82
+ * Performs CTR-256 encryption/decryption.
83
+ *
84
+ * @param data The data, larger than a byte
85
+ * @param key 32-byte encryption key
86
+ * @param iv 16-byte initialization vector
87
+ * @param state 1-byte state
88
+ */
89
+ function ctr256(data, key, iv, state) {
90
+ checkCtrParams(data, key, iv, state);
91
+ const datap = module_._malloc(data.length);
92
+ module_.HEAPU8.set(data, datap);
93
+ const ivp = module_._malloc(iv.length);
94
+ module_.HEAPU8.set(iv, ivp);
95
+ const statep = module_._malloc(state.length);
96
+ module_.HEAPU8.set(state, statep);
97
+ module_.ccall("ctr256", "void", ["pointer", "number", "array", "pointer", "pointer"], [datap, data.length, key, ivp, statep]);
98
+ data.set(module_.HEAPU8.slice(datap, datap + data.length));
99
+ iv.set(module_.HEAPU8.slice(ivp, ivp + iv.length));
100
+ state.set(module_.HEAPU8.slice(statep, statep + state.length));
101
+ module_._free(datap);
102
+ module_._free(ivp);
103
+ module_._free(statep);
104
+ }
105
+ exports.ctr256 = ctr256;
106
+ function checkCbcParams(data, key, iv) {
107
+ if (data.length == 0) {
108
+ throw new TypeError("data must not be empty");
109
+ }
110
+ else if (data.length % 16 != 0) {
111
+ throw new TypeError("data must consist of a number of bytes that is divisible by 16");
112
+ }
113
+ else if (key.length != 32) {
114
+ throw new TypeError("key must be 32 bytes");
115
+ }
116
+ else if (iv.length != 16) {
117
+ throw new TypeError("iv must be 16 bytes");
118
+ }
119
+ }
120
+ /**
121
+ * Performs CBC-256 encryption.
122
+ *
123
+ * @param data The unencrypted data, larger than a byte, divisible by 16
124
+ * @param key 32-byte encryption key
125
+ * @param iv 16-byte initialization vector
126
+ */
127
+ function cbc256Encrypt(data, key, iv) {
128
+ checkCbcParams(data, key, iv);
129
+ const datap = module_._malloc(data.length);
130
+ module_.HEAPU8.set(data, datap);
131
+ module_.ccall("cbc256_encrypt", "void", ["pointer", "number", "array", "array"], [datap, data.length, key, iv]);
132
+ try {
133
+ return module_.HEAPU8.slice(datap, datap + data.length);
134
+ }
135
+ finally {
136
+ module_._free(datap);
137
+ }
138
+ }
139
+ exports.cbc256Encrypt = cbc256Encrypt;
140
+ /**
141
+ * Performs CBC-256 decryption.
142
+ *
143
+ * @param data The encrypted data, larger than a byte, divisible by 16
144
+ * @param key 32-byte encryption key
145
+ * @param iv 16-byte initialization vector
146
+ */
147
+ function cbc256Decrypt(data, key, iv) {
148
+ checkCbcParams(data, key, iv);
149
+ const datap = module_._malloc(data.length);
150
+ module_.HEAPU8.set(data, datap);
151
+ module_.ccall("cbc256_decrypt", "void", ["pointer", "number", "array", "array"], [datap, data.length, key, iv]);
152
+ try {
153
+ return module_.HEAPU8.slice(datap, datap + data.length);
154
+ }
155
+ finally {
156
+ module_._free(datap);
157
+ }
158
+ }
159
+ exports.cbc256Decrypt = cbc256Decrypt;
160
+ function factorize(pq) {
161
+ const pqp = module_._malloc(16);
162
+ module_.ccall("factorize", "void", ["number", "pointer"], [pq, pqp]);
163
+ try {
164
+ const pqp_ = module_.HEAP64.slice(pqp / 8, pqp / 8 + 2);
165
+ return [pqp_[0], pqp_[1]];
166
+ }
167
+ finally {
168
+ module_._free(pqp);
169
+ }
170
+ }
171
+ exports.factorize = factorize;