All files / src/adapters scrypt.ts

90% Statements 9/10
80% Branches 4/5
100% Functions 4/4
100% Lines 9/9

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 331x 1x               1x 1x 1x                       8x 8x 8x   8x          
import { BaseHashingAdapter } from "../adapter";
import { scrypt } from "crypto";
/**
 *
 *
 * @export
 * @class SCryptHashingAdapter
 * @extends {BaseHashingAdapter}
 */
export class SCryptHashingAdapter extends BaseHashingAdapter {
  readonly name = "scrypt";
  readonly keyLength: number = 64;
 
  /**
   *
   *
   * @protected
   * @param {Buffer} password
   * @param {(Buffer | undefined)} salt
   * @return {Promise<Buffer>}  {Promise<Buffer>}
   * @memberof SCryptHashingAdapter
   */
  protected _hash(password: Buffer, salt: Buffer | undefined): Promise<Buffer> {
    return new Promise((resolve, reject) => {
      scrypt(password, salt ?? Buffer.alloc(0), this.keyLength, (error, key) => {
        Iif (error) return reject(error);
 
        resolve(key);
      });
    });
  }
}