46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.HashGeneratorHelp = void 0;
|
|
const crypto_1 = require("crypto");
|
|
const help_1 = require("./help");
|
|
class HashGeneratorHelp {
|
|
static generateOddOrEvenHash(isEven = false) {
|
|
const hash = this.generateHash().substring(0, 63);
|
|
const isLetter = help_1.Help.getRandomInt(1, 2) == 1;
|
|
if (isLetter) {
|
|
let num = help_1.Help.getRandomInt(1, 25);
|
|
if (isEven) {
|
|
num = num % 2 === 0 ? num : num + 1;
|
|
}
|
|
else {
|
|
num = num % 2 !== 0 ? num : num + 1;
|
|
}
|
|
return `${hash}${String.fromCharCode(96 + num)}`;
|
|
}
|
|
else {
|
|
let num = help_1.Help.getRandomInt(0, 8);
|
|
if (isEven) {
|
|
num = num % 2 === 0 ? num : num + 1;
|
|
}
|
|
else {
|
|
num = num % 2 !== 0 ? num : num + 1;
|
|
}
|
|
return `${hash}${num}`;
|
|
}
|
|
}
|
|
static generateHash() {
|
|
const seed = (0, crypto_1.randomBytes)(32).toString('hex');
|
|
const hash = (0, crypto_1.createHash)('sha256').update(seed).digest('hex');
|
|
return '0x' + hash;
|
|
}
|
|
static generateInviteCode(length = 6) {
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
let result = '';
|
|
for (let i = 0; i < length; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
exports.HashGeneratorHelp = HashGeneratorHelp;
|
|
//# sourceMappingURL=hash_generator_help.js.map
|