Skip to content

Commit

Permalink
Merge pull request #99 from ConsenSys/generateNewAddress-bug
Browse files Browse the repository at this point in the history
fixed bug in generating new addresses with a wrong pwDerivedKey
  • Loading branch information
coder5876 committed May 26, 2016
2 parents 4f0017c + f82922c commit 3880d18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,16 @@ KeyStore.prototype._generatePrivKeys = function(pwDerivedKey, n, hdPathString) {
}

var hdRoot = KeyStore._decryptString(this.ksData[hdPathString].encHdPathPriv, pwDerivedKey);

if (hdRoot.length === 0) {
throw new Error('Provided password derived key is wrong');
}

var keys = [];
for (var i = 0; i < n; i++){
var hdprivkey = new bitcore.HDPrivateKey(hdRoot).derive(this.ksData[hdPathString].hdIndex++);
var privkeyBuf = hdprivkey.privateKey.toBuffer();

var privkeyHex = privkeyBuf.toString('hex');
if (privkeyBuf.length < 16) {
// Way too small key, something must have gone wrong
Expand Down Expand Up @@ -307,7 +312,7 @@ KeyStore.prototype.isDerivedKeyCorrect = function(pwDerivedKey) {
}

return false;

};

// Takes keystore serialized as string and returns an instance of KeyStore
Expand Down

0 comments on commit 3880d18

Please sign in to comment.