diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index 9cf09789..c5148bde 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -311,23 +311,16 @@ utils.pbkdf2 = function pbkdf2(key, salt, iterations, dkLen) { var DK, U, T, block1, l, r; var i, j, k, destPos, len; + if (typeof key === 'string') + key = new Buffer(key, 'utf8'); + + if (typeof salt === 'string') + salt = new Buffer(salt, 'utf8'); + if (crypto && crypto.pbkdf2Sync) return crypto.pbkdf2Sync(key, salt, iterations, dkLen, 'sha512'); - if (dkLen > (Math.pow(2, 32) - 1) * hLen) - throw Error('Requested key length too long'); - - if (typeof key !== 'string' && typeof key.length !== 'number') - throw new TypeError('key must a string or array'); - - if (typeof salt !== 'string' && typeof salt.length !== 'number') - throw new TypeError('salt must a string or array'); - - if (typeof key === 'string') - key = new Buffer(key); - - if (typeof salt === 'string') - salt = new Buffer(salt); + assert(dkLen <= 0xffffffff * hLen, 'Requested key length too long'); DK = new Buffer(dkLen); U = new Buffer(hLen); diff --git a/test/mnemonic-test.js b/test/mnemonic-test.js index 18e13de7..fc52884e 100644 --- a/test/mnemonic-test.js +++ b/test/mnemonic-test.js @@ -13,9 +13,9 @@ describe('Mnemonic', function() { var xpriv = data[3]; it('should create an english mnemonic (' + i + ')', function() { var mnemonic = new bcoin.hd.mnemonic({ - passphrase: 'TREZOR', lang: 'english', - entropy: entropy + entropy: entropy, + passphrase: 'TREZOR' }); mnemonic.toSeed(); assert.equal(mnemonic.phrase, phrase); @@ -24,7 +24,6 @@ describe('Mnemonic', function() { assert.equal(key.xprivkey, xpriv); }); }); - return; mnemonic2.forEach(function(data, i) { var entropy = new Buffer(data.entropy, 'hex'); var phrase = data.mnemonic;