@amirmarmul/waba-common
Version:

24 lines (23 loc) • 807 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hash = void 0;
const crypto_1 = require("crypto");
class Hash {
static make = (text) => {
const salt = (0, crypto_1.randomBytes)(16).toString('hex');
return Hash.encrypt(text, salt) + salt;
};
static compare = (text, hash) => {
const salt = hash.slice(64);
const originalTextHash = hash.slice(0, 64);
const currentTextHash = Hash.encrypt(text, salt);
return originalTextHash === currentTextHash;
};
static sha256 = (text) => {
return (0, crypto_1.createHash)('sha256').update(text).digest('hex');
};
static encrypt = (text, salt) => {
return (0, crypto_1.scryptSync)(text, salt, 32).toString('hex');
};
}
exports.Hash = Hash;