@mtkruto/node 0.0.999 → 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.
- package/esm/0_deps.d.ts +1 -1
- package/esm/0_deps.js +1 -1
- package/esm/3_errors.d.ts +1531 -0
- package/esm/3_errors.js +1531 -0
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/4_errors.d.ts +25 -0
- package/esm/4_errors.js +64 -0
- package/esm/client/2_client_plain.js +1 -1
- package/esm/client/4_client.d.ts +2 -1
- package/esm/client/4_client.js +24 -41
- package/esm/deps/deno.land/x/{tgcrypto@0.1.3 → tgcrypto@0.3.2}/mod.d.ts +2 -6
- package/esm/deps/deno.land/x/tgcrypto@0.3.2/mod.js +158 -0
- package/esm/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.d.ts +2 -0
- package/esm/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +308 -0
- package/esm/mod.d.ts +3 -2
- package/esm/mod.js +3 -2
- package/esm/tl/2_types.d.ts +1 -1
- package/esm/tl/2_types.js +1 -2
- package/esm/tl/3_functions.d.ts +1 -1
- package/esm/tl/3_functions.js +1 -2
- package/esm/transport/0_obfuscation.js +1 -1
- package/esm/transport/0_transport.js +2 -2
- package/esm/types/0__file_id.js +0 -1
- package/esm/types/1_bot_command_scope.d.ts +1 -1
- package/esm/types/1_bot_command_scope.js +1 -1
- package/esm/types/1_chat.d.ts +1 -1
- package/esm/types/1_chat.js +1 -1
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.js +1 -1
- package/esm/types/1_user.d.ts +1 -1
- package/esm/types/1_user.js +1 -1
- package/esm/types/2_inline_keyboard_button.d.ts +1 -1
- package/esm/types/3_message.d.ts +12 -12
- package/esm/types/3_message.js +12 -12
- package/esm/types/5_inline_query_result.d.ts +1 -1
- package/esm/types/5_inline_query_result.js +1 -1
- package/esm/utilities/0_crypto.d.ts +1 -2
- package/esm/utilities/0_crypto.js +5 -12
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -1
- package/script/0_deps.js +3 -4
- package/script/3_errors.d.ts +1531 -0
- package/script/3_errors.js +2053 -0
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/4_errors.d.ts +25 -0
- package/script/4_errors.js +88 -0
- package/script/client/2_client_plain.js +1 -1
- package/script/client/4_client.d.ts +2 -1
- package/script/client/4_client.js +24 -41
- package/script/deps/deno.land/x/{tgcrypto@0.1.3 → tgcrypto@0.3.2}/mod.d.ts +2 -6
- package/script/deps/deno.land/x/tgcrypto@0.3.2/mod.js +171 -0
- package/script/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.d.ts +2 -0
- package/script/deps/deno.land/x/tgcrypto@0.3.2/tgcrypto.js +310 -0
- package/script/mod.d.ts +3 -2
- package/script/mod.js +16 -3
- package/script/tl/2_types.d.ts +1 -1
- package/script/tl/2_types.js +0 -1
- package/script/tl/3_functions.d.ts +1 -1
- package/script/tl/3_functions.js +0 -1
- package/script/transport/0_obfuscation.js +1 -1
- package/script/transport/0_transport.js +2 -2
- package/script/types/0__file_id.js +0 -1
- package/script/types/1_bot_command_scope.d.ts +1 -1
- package/script/types/1_bot_command_scope.js +1 -1
- package/script/types/1_chat.d.ts +1 -1
- package/script/types/1_chat.js +1 -1
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.js +1 -1
- package/script/types/1_user.d.ts +1 -1
- package/script/types/1_user.js +1 -1
- package/script/types/2_inline_keyboard_button.d.ts +1 -1
- package/script/types/3_message.d.ts +12 -12
- package/script/types/3_message.js +12 -12
- package/script/types/5_inline_query_result.d.ts +1 -1
- package/script/types/5_inline_query_result.js +1 -1
- package/script/utilities/0_crypto.d.ts +1 -2
- package/script/utilities/0_crypto.js +4 -11
- package/esm/deps/deno.land/x/tgcrypto@0.1.3/mod.js +0 -68
- package/esm/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.d.ts +0 -2
- package/esm/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.js +0 -1078
- package/script/deps/deno.land/x/tgcrypto@0.1.3/mod.js +0 -82
- package/script/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.d.ts +0 -2
- package/script/deps/deno.land/x/tgcrypto@0.1.3/tgcrypto.js +0 -1080
package/script/4_constants.d.ts
CHANGED
|
@@ -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.
|
|
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 = "";
|
package/script/4_constants.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { types } from "./2_tl.js";
|
|
2
|
+
export * from "./3_errors.js";
|
|
3
|
+
export declare class FloodWait extends types.RPCError {
|
|
4
|
+
seconds: number;
|
|
5
|
+
constructor(params: {
|
|
6
|
+
errorCode: number;
|
|
7
|
+
errorMessage: string;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export declare class Migrate extends types.RPCError {
|
|
11
|
+
dc: number;
|
|
12
|
+
constructor(params: {
|
|
13
|
+
errorCode: number;
|
|
14
|
+
errorMessage: string;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export declare class UserMigrate extends Migrate {
|
|
18
|
+
}
|
|
19
|
+
export declare class PhoneMigrate extends Migrate {
|
|
20
|
+
}
|
|
21
|
+
export declare class FileMigrate extends Migrate {
|
|
22
|
+
}
|
|
23
|
+
export declare class StatsMigrate extends Migrate {
|
|
24
|
+
}
|
|
25
|
+
export declare function upgradeInstance(error: types.RPCError): types.RPCError;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
exports.upgradeInstance = exports.StatsMigrate = exports.FileMigrate = exports.PhoneMigrate = exports.UserMigrate = exports.Migrate = exports.FloodWait = void 0;
|
|
18
|
+
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
19
|
+
const _3_errors_js_1 = require("./3_errors.js");
|
|
20
|
+
const _2_tl_js_1 = require("./2_tl.js");
|
|
21
|
+
__exportStar(require("./3_errors.js"), exports);
|
|
22
|
+
class FloodWait extends _2_tl_js_1.types.RPCError {
|
|
23
|
+
constructor(params) {
|
|
24
|
+
super(params);
|
|
25
|
+
Object.defineProperty(this, "seconds", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
const p = params.errorMessage.split("_");
|
|
32
|
+
this.seconds = Number(p[p.length - 1]);
|
|
33
|
+
if (isNaN(this.seconds)) {
|
|
34
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.FloodWait = FloodWait;
|
|
39
|
+
class Migrate extends _2_tl_js_1.types.RPCError {
|
|
40
|
+
constructor(params) {
|
|
41
|
+
super(params);
|
|
42
|
+
Object.defineProperty(this, "dc", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
48
|
+
const p = params.errorMessage.split("_");
|
|
49
|
+
this.dc = Number(p[p.length - 1]);
|
|
50
|
+
if (isNaN(this.dc)) {
|
|
51
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.Migrate = Migrate;
|
|
56
|
+
class UserMigrate extends Migrate {
|
|
57
|
+
}
|
|
58
|
+
exports.UserMigrate = UserMigrate;
|
|
59
|
+
class PhoneMigrate extends Migrate {
|
|
60
|
+
}
|
|
61
|
+
exports.PhoneMigrate = PhoneMigrate;
|
|
62
|
+
class FileMigrate extends Migrate {
|
|
63
|
+
}
|
|
64
|
+
exports.FileMigrate = FileMigrate;
|
|
65
|
+
class StatsMigrate extends Migrate {
|
|
66
|
+
}
|
|
67
|
+
exports.StatsMigrate = StatsMigrate;
|
|
68
|
+
const prefixMap = {
|
|
69
|
+
"FILE_MIGRATE_": FileMigrate,
|
|
70
|
+
"PHONE_MIGRATE_": PhoneMigrate,
|
|
71
|
+
"USER_MIGRATE_": UserMigrate,
|
|
72
|
+
"STATS_MIGRATE_": StatsMigrate,
|
|
73
|
+
"FLOOD_WAIT_": FloodWait,
|
|
74
|
+
};
|
|
75
|
+
function upgradeInstance(error) {
|
|
76
|
+
for (const [k, v] of Object.entries(prefixMap)) {
|
|
77
|
+
if (error.errorMessage.startsWith(k)) {
|
|
78
|
+
return new v(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (const [k, v] of Object.entries(_3_errors_js_1.map)) {
|
|
82
|
+
if (error.errorMessage == k) {
|
|
83
|
+
return new v(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return error;
|
|
87
|
+
}
|
|
88
|
+
exports.upgradeInstance = upgradeInstance;
|
|
@@ -5,8 +5,8 @@ const _0_deps_js_1 = require("../0_deps.js");
|
|
|
5
5
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
6
6
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
7
7
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
8
|
-
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
9
8
|
const _0_message_js_1 = require("./0_message.js");
|
|
9
|
+
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
10
10
|
const d = (0, _0_deps_js_1.debug)("ClientPlain/createAuthKey");
|
|
11
11
|
class ClientPlain extends _1_client_abstract_js_1.ClientAbstract {
|
|
12
12
|
constructor(params) {
|
|
@@ -3,6 +3,7 @@ import { functions, ReadObject, types } from "../2_tl.js";
|
|
|
3
3
|
import { Storage } from "../3_storage.js";
|
|
4
4
|
import { DC } from "../3_transport.js";
|
|
5
5
|
import { BotCommand, BotCommandScope, ChatAction, ChatID, InlineQueryResult, InlineQueryResultButton, Message } from "../3_types.js";
|
|
6
|
+
import { Migrate } from "../4_errors.js";
|
|
6
7
|
import { With } from "./0_utilities.js";
|
|
7
8
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
8
9
|
import { AnswerCallbackQueryParams, AuthorizeUserParams, ClientParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, Handler, ParseMode, SendMessagesParams, SendPollParams, Update } from "./3_types.js";
|
|
@@ -60,7 +61,7 @@ export declare class Client extends ClientAbstract {
|
|
|
60
61
|
private assertUser;
|
|
61
62
|
private assertBot;
|
|
62
63
|
private fetchState;
|
|
63
|
-
[handleMigrationError](err:
|
|
64
|
+
[handleMigrationError](err: Migrate): Promise<void>;
|
|
64
65
|
private connectionInited;
|
|
65
66
|
disconnect(): Promise<void>;
|
|
66
67
|
private initConnection;
|
|
@@ -7,12 +7,13 @@ const _2_tl_js_1 = require("../2_tl.js");
|
|
|
7
7
|
const _3_storage_js_1 = require("../3_storage.js");
|
|
8
8
|
const _3_types_js_1 = require("../3_types.js");
|
|
9
9
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
10
|
-
const
|
|
10
|
+
const _4_errors_js_1 = require("../4_errors.js");
|
|
11
|
+
const _0_html_js_1 = require("./0_html.js");
|
|
11
12
|
const _0_message_js_1 = require("./0_message.js");
|
|
12
13
|
const _0_password_js_1 = require("./0_password.js");
|
|
13
|
-
const
|
|
14
|
-
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
14
|
+
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
15
15
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
16
|
+
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
16
17
|
const _3_types_js_2 = require("./3_types.js");
|
|
17
18
|
const d = (0, _0_deps_js_1.debug)("Client");
|
|
18
19
|
const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
|
|
@@ -330,18 +331,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
330
331
|
d("state fetched [%s]", source);
|
|
331
332
|
}
|
|
332
333
|
async [exports.handleMigrationError](err) {
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
if (Math.abs(this.dcId) >= 10000) {
|
|
337
|
-
newDc += "-test";
|
|
338
|
-
}
|
|
339
|
-
await this.reconnect(newDc);
|
|
340
|
-
d("migrated to DC%s", newDc);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
334
|
+
let newDc = String(err.dc);
|
|
335
|
+
if (Math.abs(this.dcId) >= 10000) {
|
|
336
|
+
newDc += "-test";
|
|
344
337
|
}
|
|
338
|
+
await this.reconnect(newDc);
|
|
339
|
+
d("migrated to DC%s", newDc);
|
|
345
340
|
}
|
|
346
341
|
disconnect() {
|
|
347
342
|
this.connectionInited = false;
|
|
@@ -414,7 +409,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
414
409
|
return;
|
|
415
410
|
}
|
|
416
411
|
catch (err) {
|
|
417
|
-
if (!(err instanceof
|
|
412
|
+
if (!(err instanceof _4_errors_js_1.AuthKeyUnregistered)) {
|
|
418
413
|
throw err;
|
|
419
414
|
}
|
|
420
415
|
}
|
|
@@ -426,16 +421,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
426
421
|
break;
|
|
427
422
|
}
|
|
428
423
|
catch (err) {
|
|
429
|
-
if (err instanceof
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
await this.initConnection();
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
throw err;
|
|
438
|
-
}
|
|
424
|
+
if (err instanceof _4_errors_js_1.Migrate) {
|
|
425
|
+
await this[exports.handleMigrationError](err);
|
|
426
|
+
await this.initConnection();
|
|
427
|
+
continue;
|
|
439
428
|
}
|
|
440
429
|
else {
|
|
441
430
|
throw err;
|
|
@@ -467,16 +456,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
467
456
|
sentCode = await sendCode();
|
|
468
457
|
}
|
|
469
458
|
catch (err) {
|
|
470
|
-
if (err instanceof
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
await this.initConnection();
|
|
475
|
-
sentCode = await sendCode();
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
throw err;
|
|
479
|
-
}
|
|
459
|
+
if (err instanceof _4_errors_js_1.Migrate) {
|
|
460
|
+
await this[exports.handleMigrationError](err);
|
|
461
|
+
await this.initConnection();
|
|
462
|
+
sentCode = await sendCode();
|
|
480
463
|
}
|
|
481
464
|
else {
|
|
482
465
|
throw err;
|
|
@@ -485,7 +468,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
485
468
|
break;
|
|
486
469
|
}
|
|
487
470
|
catch (err) {
|
|
488
|
-
if (err instanceof
|
|
471
|
+
if (err instanceof _4_errors_js_1.PhoneNumberInvalid) {
|
|
489
472
|
continue;
|
|
490
473
|
}
|
|
491
474
|
else {
|
|
@@ -519,7 +502,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
519
502
|
}
|
|
520
503
|
}
|
|
521
504
|
}
|
|
522
|
-
if (!(err instanceof
|
|
505
|
+
if (!(err instanceof _4_errors_js_1.SessionPasswordNeeded)) {
|
|
523
506
|
throw err;
|
|
524
507
|
}
|
|
525
508
|
while (true) {
|
|
@@ -538,7 +521,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
538
521
|
break;
|
|
539
522
|
}
|
|
540
523
|
catch (err) {
|
|
541
|
-
if (err instanceof
|
|
524
|
+
if (err instanceof _4_errors_js_1.PasswordHashInvalid) {
|
|
542
525
|
continue;
|
|
543
526
|
}
|
|
544
527
|
else {
|
|
@@ -560,7 +543,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
560
543
|
return;
|
|
561
544
|
}
|
|
562
545
|
catch (err) {
|
|
563
|
-
if (!(err instanceof
|
|
546
|
+
if (!(err instanceof _4_errors_js_1.AuthKeyUnregistered)) {
|
|
564
547
|
throw err;
|
|
565
548
|
}
|
|
566
549
|
}
|
|
@@ -612,7 +595,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
612
595
|
const promise = this.promises.get(messageId);
|
|
613
596
|
if (promise) {
|
|
614
597
|
if (result instanceof _2_tl_js_1.types.RPCError) {
|
|
615
|
-
promise.reject(result);
|
|
598
|
+
promise.reject((0, _4_errors_js_1.upgradeInstance)(result));
|
|
616
599
|
}
|
|
617
600
|
else {
|
|
618
601
|
promise.resolve(result);
|
|
@@ -706,7 +689,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
706
689
|
});
|
|
707
690
|
}
|
|
708
691
|
catch (err) {
|
|
709
|
-
if (err instanceof
|
|
692
|
+
if (err instanceof _4_errors_js_1.AuthKeyUnregistered) {
|
|
710
693
|
await this.propagateAuthorizationState(false);
|
|
711
694
|
}
|
|
712
695
|
throw err;
|
|
@@ -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
|
|
27
|
-
/**
|
|
28
|
-
* Alias of `ctr256Encrypt`
|
|
29
|
-
*/
|
|
30
|
-
export declare function ctr256Decrypt(data: Uint8Array, key: Uint8Array, iv: Uint8Array, state: Uint8Array): [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;
|