fix unicode mnemonics.
This commit is contained in:
parent
bc59106f45
commit
27d5f2370b
@ -311,23 +311,16 @@ utils.pbkdf2 = function pbkdf2(key, salt, iterations, dkLen) {
|
|||||||
var DK, U, T, block1, l, r;
|
var DK, U, T, block1, l, r;
|
||||||
var i, j, k, destPos, len;
|
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)
|
if (crypto && crypto.pbkdf2Sync)
|
||||||
return crypto.pbkdf2Sync(key, salt, iterations, dkLen, 'sha512');
|
return crypto.pbkdf2Sync(key, salt, iterations, dkLen, 'sha512');
|
||||||
|
|
||||||
if (dkLen > (Math.pow(2, 32) - 1) * hLen)
|
assert(dkLen <= 0xffffffff * hLen, 'Requested key length too long');
|
||||||
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);
|
|
||||||
|
|
||||||
DK = new Buffer(dkLen);
|
DK = new Buffer(dkLen);
|
||||||
U = new Buffer(hLen);
|
U = new Buffer(hLen);
|
||||||
|
|||||||
@ -13,9 +13,9 @@ describe('Mnemonic', function() {
|
|||||||
var xpriv = data[3];
|
var xpriv = data[3];
|
||||||
it('should create an english mnemonic (' + i + ')', function() {
|
it('should create an english mnemonic (' + i + ')', function() {
|
||||||
var mnemonic = new bcoin.hd.mnemonic({
|
var mnemonic = new bcoin.hd.mnemonic({
|
||||||
passphrase: 'TREZOR',
|
|
||||||
lang: 'english',
|
lang: 'english',
|
||||||
entropy: entropy
|
entropy: entropy,
|
||||||
|
passphrase: 'TREZOR'
|
||||||
});
|
});
|
||||||
mnemonic.toSeed();
|
mnemonic.toSeed();
|
||||||
assert.equal(mnemonic.phrase, phrase);
|
assert.equal(mnemonic.phrase, phrase);
|
||||||
@ -24,7 +24,6 @@ describe('Mnemonic', function() {
|
|||||||
assert.equal(key.xprivkey, xpriv);
|
assert.equal(key.xprivkey, xpriv);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
mnemonic2.forEach(function(data, i) {
|
mnemonic2.forEach(function(data, i) {
|
||||||
var entropy = new Buffer(data.entropy, 'hex');
|
var entropy = new Buffer(data.entropy, 'hex');
|
||||||
var phrase = data.mnemonic;
|
var phrase = data.mnemonic;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user