UNPKG

@bunq-community/bunq-js-client

Version:

[![NPM Version](https://img.shields.io/npm/v/@bunq-community/bunq-js-client.svg) ](https://www.npmjs.com/package/@bunq-community/bunq-js-client) [![NPM Downloads](https://img.shields.io/npm/dt/@bunq-community/bunq-js-client.svg) ](https://www.npmjs.com/p

34 lines (33 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const forge = require("./CustomForge"); exports.derivePasswordKey = async (password, salt = false, iterations = 10000) => { if (salt === false) { // no salt given, create a new random one salt = forge.random.getBytesSync(128); } else { // get bytes from the hex salt salt = forge.util.hexToBytes(salt); } // asynchronously derive a key from the password const derivedKey = await new Promise((resolve, reject) => { // derive a 32-byte key from the password forge.pkcs5.pbkdf2(password, salt, iterations, 16, (errorMessage, derivedKey) => { /* istanbul ignore if - can't manually trigger an error with this lib */ if (errorMessage) { reject(errorMessage); } else { resolve(derivedKey); } }); }); // encode the bytes as hex const hexKey = forge.util.bytesToHex(derivedKey); const hexSalt = forge.util.bytesToHex(salt); return { key: hexKey, salt: hexSalt }; };