Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
/**
* Supported Argon2 variants.
* Argon2 currently has three modes:
* - d: Argon2d data-dependent.
* - i: Argon2i data-independent.
* - id: Argon2id a mix of the two.
* See https://crypto.stackexchange.com/a/49969
* @private
* @type {Object}
*/
const variants = Object.freeze({
i: argon2.argon2i,
d: argon2.argon2d,
id: argon2.argon2id
});
/**
* Supported Argon2 versions.
* @private
* @type {number[]}
*/
const versions = [
0x10, // 1.0 (16)
0x13 // 1.3 (19)
];
/**
* Computes the hash string of the given password in the PHC format using argon2
* package.
* @public
module.exports = async () => {
const response = await prompts(questions, { onCancel })
let config = readConfig('webhooks')
config.enabled = response.enabled
config.password = await argon2.hash(response.password, { type: argon2.argon2id })
return writeConfig('webhooks', config)
}
module.exports = async () => {
const response = await prompts(questions, { onCancel })
let config = readConfig('webhooks')
config.enabled = response.enabled
if (config.enabled) {
config.password = await argon2.hash(response.password, { type: argon2.argon2id })
}
return writeConfig('webhooks', config)
}
export function hash(plaintext: string): Promise {
return argon2.hash(plaintext, { type: argon2.argon2id })
}
public async create(user: UserCreateInput) {
const password = await argon2.hash(user.password, {
type: argon2.argon2id,
});
return await this.prisma.mutation.createUser({
data: {
...user,
password,
},
});
}
}
import { Injectable } from '@nestjs/common';
import * as argon2 from 'argon2';
@Injectable()
export class CryptoService {
private readonly type = argon2.argon2id;
constructor() {
}
/**
* Compare hash
* @param {string} plain
* @param {string} hash
* @returns {Promise}
*/
public async compare(plain: string, hash: string): Promise {
return await argon2.verify(hash, plain);
}
/**
* Generate hash