All files / node-user-accounts-boilerplate-nahid/crypt SCRYPT.js

100% Statements 8/8
100% Branches 3/3
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46    1x 1x                               2x 2x               1x     1x               2x         1x  
"use strict";
 
const Crypt = require('./Crypt');
const scrypt = require("scrypt");
 
/**
 * Use scrypt.
 * 
 * Requires scrypt (npm install scrypt).
 */
class SCRYPT extends Crypt
{
 
  /**
   * @param {Object} [options={}]
   * @param {Number} [options.maxtime=0.1] see https://www.npmjs.com/package/scrypt#params
   */
  constructor(options = {})
  {
    super();
    this.params = scrypt.paramsSync(options.maxtime || 0.1);
  }
 
  /**
   * @override
   */
  async hashImplementation(password)
  {
    const result = await scrypt.kdf(password, this.params);
 
 
    return result.toString('hex');
  }
 
  /**
   * @override
   */
  async verifyImplementation(password, hash)
  {
    return await scrypt.verifyKdf(new Buffer(hash, "hex"), password)
  }
 
}
 
module.exports = SCRYPT;