ayiin 2.0.51 → 2.0.53
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/dist/methods/crypt.d.ts +20 -6
- package/dist/methods/crypt.js +33 -79
- package/dist/methods/index.d.ts +2 -1
- package/dist/methods/index.js +2 -0
- package/dist/methods/response.d.ts +18 -0
- package/dist/methods/response.js +16 -0
- package/dist/methods/token.d.ts +10 -0
- package/dist/methods/token.js +91 -0
- package/package.json +1 -1
package/dist/methods/crypt.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
declare class Crypt {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Performs Base encryption and decryption.
|
|
4
|
+
* @param {string | Buffer} input - The input data to be encrypted or decrypted.
|
|
5
|
+
* @param {string} key - The encryption/decryption key.
|
|
6
|
+
* @returns {Buffer} - The encrypted or decrypted data as a Buffer.
|
|
7
|
+
*/
|
|
6
8
|
private baseCrypt;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Encrypts a plaintext message using the given key.
|
|
11
|
+
* @param {string} text - The plaintext message to be encrypted.
|
|
12
|
+
* @param {string} key - The encryption key.
|
|
13
|
+
* @returns {string} - The encrypted data in Hex format.
|
|
14
|
+
*/
|
|
15
|
+
encrypt: (text: string, key: string, bufferEncoding?: BufferEncoding) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypts an encrypted message using the given key.
|
|
18
|
+
* @param {string} encrypted - The encrypted data in Hex format.
|
|
19
|
+
* @param {string} key - The decryption key.
|
|
20
|
+
* @returns {string} - The decrypted plaintext message.
|
|
21
|
+
*/
|
|
22
|
+
decrypt: (encrypted: string, key: string, bufferEncoding?: BufferEncoding) => string;
|
|
9
23
|
/**
|
|
10
24
|
* Converts a Hex string to its corresponding ASCII representation.
|
|
11
25
|
* @param {string} hexString - The Hex string to be converted.
|
package/dist/methods/crypt.js
CHANGED
|
@@ -5,87 +5,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
7
|
class Crypt {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
digits.push(carry % 62);
|
|
21
|
-
carry = Math.floor(carry / 62);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return (digits
|
|
25
|
-
.reverse()
|
|
26
|
-
.map((d) => this.chars[d])
|
|
27
|
-
.join("") || "0");
|
|
28
|
-
}
|
|
29
|
-
// Base62 decode: string → buffer
|
|
30
|
-
base62Decode(str) {
|
|
31
|
-
let digits = [0];
|
|
32
|
-
for (const c of str) {
|
|
33
|
-
let carry = this.chars.indexOf(c);
|
|
34
|
-
for (let j = 0; j < digits.length; j++) {
|
|
35
|
-
const val = digits[j] * 62 + carry;
|
|
36
|
-
digits[j] = val & 0xff;
|
|
37
|
-
carry = val >> 8;
|
|
38
|
-
}
|
|
39
|
-
while (carry > 0) {
|
|
40
|
-
digits.push(carry & 0xff);
|
|
41
|
-
carry >>= 8;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return Buffer.from(digits.reverse());
|
|
45
|
-
}
|
|
46
|
-
generateKeystream(key, length) {
|
|
47
|
-
const result = Buffer.alloc(length);
|
|
48
|
-
let pos = 0;
|
|
49
|
-
let counter = 0;
|
|
50
|
-
while (pos < length) {
|
|
51
|
-
const hash = crypto_1.default.createHash("sha256");
|
|
52
|
-
hash.update(key);
|
|
53
|
-
hash.update(Buffer.from(counter.toString()));
|
|
54
|
-
const digest = hash.digest();
|
|
55
|
-
const copy = Math.min(length - pos, digest.length);
|
|
56
|
-
digest.copy(result, pos, 0, copy);
|
|
57
|
-
pos += copy;
|
|
58
|
-
counter++;
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
baseCrypt(input, key) {
|
|
63
|
-
const keystream = this.generateKeystream(key, input.length);
|
|
64
|
-
const output = Buffer.alloc(input.length);
|
|
65
|
-
for (let i = 0; i < input.length; i++) {
|
|
66
|
-
output[i] = input[i] ^ keystream[i];
|
|
8
|
+
/**
|
|
9
|
+
* Performs Base encryption and decryption.
|
|
10
|
+
* @param {string | Buffer} input - The input data to be encrypted or decrypted.
|
|
11
|
+
* @param {string} key - The encryption/decryption key.
|
|
12
|
+
* @returns {Buffer} - The encrypted or decrypted data as a Buffer.
|
|
13
|
+
*/
|
|
14
|
+
baseCrypt = (input, key) => {
|
|
15
|
+
const inputBuffer = Buffer.from(input, "ascii");
|
|
16
|
+
const keyBuffer = Buffer.from(key, "ascii");
|
|
17
|
+
const resultBuffer = Buffer.alloc(inputBuffer.length);
|
|
18
|
+
for (let i = 0; i < inputBuffer.length; i++) {
|
|
19
|
+
resultBuffer[i] = inputBuffer[i] ^ keyBuffer[i % keyBuffer.length];
|
|
67
20
|
}
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
encrypt = (text, key) => {
|
|
71
|
-
const input = Buffer.from(text, "utf8");
|
|
72
|
-
const encrypted = this.baseCrypt(input, key);
|
|
73
|
-
const cipher = this.base62Encode(encrypted);
|
|
74
|
-
const hmac = crypto_1.default.createHmac("sha256", key).update(cipher).digest();
|
|
75
|
-
const signature = this.base62Encode(hmac);
|
|
76
|
-
return `${cipher}.${signature}`;
|
|
21
|
+
return resultBuffer;
|
|
77
22
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Encrypts a plaintext message using the given key.
|
|
25
|
+
* @param {string} text - The plaintext message to be encrypted.
|
|
26
|
+
* @param {string} key - The encryption key.
|
|
27
|
+
* @returns {string} - The encrypted data in Hex format.
|
|
28
|
+
*/
|
|
29
|
+
encrypt = (text, key, bufferEncoding = "base64") => {
|
|
30
|
+
const encryptedBuffer = this.baseCrypt(text, key);
|
|
31
|
+
return encryptedBuffer.toString(bufferEncoding);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Decrypts an encrypted message using the given key.
|
|
35
|
+
* @param {string} encrypted - The encrypted data in Hex format.
|
|
36
|
+
* @param {string} key - The decryption key.
|
|
37
|
+
* @returns {string} - The decrypted plaintext message.
|
|
38
|
+
*/
|
|
39
|
+
decrypt = (encrypted, key, bufferEncoding = "base64") => {
|
|
40
|
+
const encryptedBuffer = Buffer.from(encrypted, bufferEncoding);
|
|
41
|
+
const decryptedBuffer = this.baseCrypt(encryptedBuffer, key);
|
|
42
|
+
return decryptedBuffer.toString("ascii");
|
|
89
43
|
};
|
|
90
44
|
/**
|
|
91
45
|
* Converts a Hex string to its corresponding ASCII representation.
|
package/dist/methods/index.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ import Objects from "./objects";
|
|
|
8
8
|
import Random from "./random";
|
|
9
9
|
import ResponseApi from "./response";
|
|
10
10
|
import Strings from "./strings";
|
|
11
|
+
import Token from "./token";
|
|
11
12
|
import Validation from "./validation";
|
|
12
13
|
declare class Methods {
|
|
13
14
|
}
|
|
14
|
-
interface Methods extends Async, Crypt, Currency, Dates, Files, Limiter, Objects, Random, ResponseApi, Strings, Validation {
|
|
15
|
+
interface Methods extends Async, Crypt, Currency, Dates, Files, Limiter, Objects, Random, ResponseApi, Strings, Token, Validation {
|
|
15
16
|
}
|
|
16
17
|
export default Methods;
|
package/dist/methods/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const objects_1 = __importDefault(require("./objects"));
|
|
|
13
13
|
const random_1 = __importDefault(require("./random"));
|
|
14
14
|
const response_1 = __importDefault(require("./response"));
|
|
15
15
|
const strings_1 = __importDefault(require("./strings"));
|
|
16
|
+
const token_1 = __importDefault(require("./token"));
|
|
16
17
|
const validation_1 = __importDefault(require("./validation"));
|
|
17
18
|
class Methods {
|
|
18
19
|
}
|
|
@@ -27,5 +28,6 @@ Object.assign(Methods.prototype, new objects_1.default());
|
|
|
27
28
|
Object.assign(Methods.prototype, new random_1.default());
|
|
28
29
|
Object.assign(Methods.prototype, new response_1.default());
|
|
29
30
|
Object.assign(Methods.prototype, new strings_1.default());
|
|
31
|
+
Object.assign(Methods.prototype, new token_1.default());
|
|
30
32
|
Object.assign(Methods.prototype, new validation_1.default());
|
|
31
33
|
exports.default = Methods;
|
|
@@ -46,6 +46,24 @@ declare class ResponseApi {
|
|
|
46
46
|
responseMessage: string;
|
|
47
47
|
responseData: any;
|
|
48
48
|
};
|
|
49
|
+
forbidden: ({ caption, data }: {
|
|
50
|
+
caption: string;
|
|
51
|
+
data?: any;
|
|
52
|
+
}) => {
|
|
53
|
+
responseCode: number;
|
|
54
|
+
responseSuccess: boolean;
|
|
55
|
+
responseMessage: string;
|
|
56
|
+
responseData: any;
|
|
57
|
+
};
|
|
58
|
+
floodWait: ({ caption, data }: {
|
|
59
|
+
caption: string;
|
|
60
|
+
data?: any;
|
|
61
|
+
}) => {
|
|
62
|
+
responseCode: number;
|
|
63
|
+
responseSuccess: boolean;
|
|
64
|
+
responseMessage: string;
|
|
65
|
+
responseData: any;
|
|
66
|
+
};
|
|
49
67
|
internalServer: ({ caption, data }: {
|
|
50
68
|
caption: string;
|
|
51
69
|
data?: any;
|
package/dist/methods/response.js
CHANGED
|
@@ -42,6 +42,22 @@ class ResponseApi {
|
|
|
42
42
|
responseData: data,
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
|
+
forbidden = ({ caption, data }) => {
|
|
46
|
+
return {
|
|
47
|
+
responseCode: 4037400,
|
|
48
|
+
responseSuccess: false,
|
|
49
|
+
responseMessage: `[Forbidden] - ${caption}`,
|
|
50
|
+
responseData: data,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
floodWait = ({ caption, data }) => {
|
|
54
|
+
return {
|
|
55
|
+
responseCode: 4297400,
|
|
56
|
+
responseSuccess: false,
|
|
57
|
+
responseMessage: `[Flood Wait] - ${caption}`,
|
|
58
|
+
responseData: data,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
45
61
|
internalServer = ({ caption, data }) => {
|
|
46
62
|
return {
|
|
47
63
|
responseCode: 5007400,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare class Token {
|
|
2
|
+
private chars;
|
|
3
|
+
private base62Encode;
|
|
4
|
+
private base62Decode;
|
|
5
|
+
private generateKeystream;
|
|
6
|
+
private baseCryptToken;
|
|
7
|
+
generateToken: (text: string, key: string) => string;
|
|
8
|
+
verifyToken: (token: string, key: string) => string | null;
|
|
9
|
+
}
|
|
10
|
+
export default Token;
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
class Token {
|
|
8
|
+
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
9
|
+
// Base62 encode: buffer → base62 string
|
|
10
|
+
base62Encode(buffer) {
|
|
11
|
+
let digits = [0];
|
|
12
|
+
for (const byte of buffer) {
|
|
13
|
+
let carry = byte;
|
|
14
|
+
for (let j = 0; j < digits.length; j++) {
|
|
15
|
+
const val = digits[j] * 256 + carry;
|
|
16
|
+
digits[j] = val % 62;
|
|
17
|
+
carry = Math.floor(val / 62);
|
|
18
|
+
}
|
|
19
|
+
while (carry > 0) {
|
|
20
|
+
digits.push(carry % 62);
|
|
21
|
+
carry = Math.floor(carry / 62);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return (digits
|
|
25
|
+
.reverse()
|
|
26
|
+
.map((d) => this.chars[d])
|
|
27
|
+
.join("") || "0");
|
|
28
|
+
}
|
|
29
|
+
// Base62 decode: string → buffer
|
|
30
|
+
base62Decode(str) {
|
|
31
|
+
let digits = [0];
|
|
32
|
+
for (const c of str) {
|
|
33
|
+
let carry = this.chars.indexOf(c);
|
|
34
|
+
for (let j = 0; j < digits.length; j++) {
|
|
35
|
+
const val = digits[j] * 62 + carry;
|
|
36
|
+
digits[j] = val & 0xff;
|
|
37
|
+
carry = val >> 8;
|
|
38
|
+
}
|
|
39
|
+
while (carry > 0) {
|
|
40
|
+
digits.push(carry & 0xff);
|
|
41
|
+
carry >>= 8;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Buffer.from(digits.reverse());
|
|
45
|
+
}
|
|
46
|
+
generateKeystream(key, length) {
|
|
47
|
+
const result = Buffer.alloc(length);
|
|
48
|
+
let pos = 0;
|
|
49
|
+
let counter = 0;
|
|
50
|
+
while (pos < length) {
|
|
51
|
+
const hash = crypto_1.default.createHash("sha256");
|
|
52
|
+
hash.update(key);
|
|
53
|
+
hash.update(Buffer.from(counter.toString()));
|
|
54
|
+
const digest = hash.digest();
|
|
55
|
+
const copy = Math.min(length - pos, digest.length);
|
|
56
|
+
digest.copy(result, pos, 0, copy);
|
|
57
|
+
pos += copy;
|
|
58
|
+
counter++;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
baseCryptToken(input, key) {
|
|
63
|
+
const keystream = this.generateKeystream(key, input.length);
|
|
64
|
+
const output = Buffer.alloc(input.length);
|
|
65
|
+
for (let i = 0; i < input.length; i++) {
|
|
66
|
+
output[i] = input[i] ^ keystream[i];
|
|
67
|
+
}
|
|
68
|
+
return output;
|
|
69
|
+
}
|
|
70
|
+
generateToken = (text, key) => {
|
|
71
|
+
const input = Buffer.from(text, "utf8");
|
|
72
|
+
const encrypted = this.baseCryptToken(input, key);
|
|
73
|
+
const cipher = this.base62Encode(encrypted);
|
|
74
|
+
const hmac = crypto_1.default.createHmac("sha256", key).update(cipher).digest();
|
|
75
|
+
const signature = this.base62Encode(hmac);
|
|
76
|
+
return `${cipher}.${signature}`;
|
|
77
|
+
};
|
|
78
|
+
verifyToken = (token, key) => {
|
|
79
|
+
const [cipher, signature] = token.split(".");
|
|
80
|
+
if (!cipher || !signature)
|
|
81
|
+
return null;
|
|
82
|
+
const hmac = crypto_1.default.createHmac("sha256", key).update(cipher).digest();
|
|
83
|
+
const expected = this.base62Encode(hmac);
|
|
84
|
+
if (expected !== signature)
|
|
85
|
+
return null;
|
|
86
|
+
const input = this.base62Decode(cipher);
|
|
87
|
+
const decrypted = this.baseCryptToken(input, key);
|
|
88
|
+
return decrypted.toString("utf8");
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.default = Token;
|