Accounts and login.

This commit is contained in:
Mike Cao 2020-07-23 19:56:55 -07:00
parent f3f0ad15f2
commit 49a55b40b4
22 changed files with 347 additions and 172 deletions

View file

@ -6,23 +6,19 @@ import { JWT, JWE, JWK } from 'jose';
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/;
const KEY = JWK.asKey(Buffer.from(secret()));
export function sha256(...args) {
return crypto.createHash('sha256').update(args.join('')).digest('hex');
export function hash(...args) {
return crypto.createHash('sha512').update(args.join('')).digest('hex');
}
export function secret() {
return sha256(process.env.HASH_SALT);
return hash(process.env.HASH_SALT);
}
export function uuid(...args) {
return v5(args.join(''), v5(process.env.HASH_SALT, v5.DNS));
}
export function random(n = 64) {
return crypto.randomBytes(n).toString('hex');
}
export function isValidHash(s) {
export function isValidId(s) {
return UUID_REGEX.test(s);
}