fix unicode mnemonics.

This commit is contained in:
Christopher Jeffrey 2016-04-30 00:51:53 -07:00
parent bc59106f45
commit 27d5f2370b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 9 additions and 17 deletions

View File

@ -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);

View File

@ -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;