2023-04-04 21:52:10 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { scrypt } = require ('scrypt-js');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates a scrypt hash
|
|
|
|
*
|
|
|
|
* @param {string} str string input
|
2023-04-07 16:55:52 +02:00
|
|
|
* @param {string} salt salt#
|
|
|
|
* @param {(progress: number) => void} [progress] progress callback
|
2023-04-04 21:52:10 +02:00
|
|
|
* @returns {Promise<string>} hash
|
|
|
|
*/
|
2023-04-07 16:55:52 +02:00
|
|
|
async function pbkdf_scrypt (str, salt, progress) {
|
2023-04-04 21:52:10 +02:00
|
|
|
const bstr = Buffer.from (str.normalize ('NFKC'), 'utf-8');
|
|
|
|
const bsalt = Buffer.from (salt.normalize ('NFKC'), 'utf-8');
|
2023-04-07 16:55:52 +02:00
|
|
|
const hash = await scrypt (bstr, bsalt, 8192, 8, 1, 64, progress);
|
2023-04-04 21:52:10 +02:00
|
|
|
return Buffer.from (hash)
|
|
|
|
.toString ('hex');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { pbkdf_scrypt };
|