Browse Source

Fix hd string path parsing.

patch-2
Yemel Jardi 10 years ago
parent
commit
3bd361e27a
  1. 9
      lib/hdprivatekey.js
  2. 12
      test/hdprivatekey.js

9
lib/hdprivatekey.js

@ -106,8 +106,13 @@ HDPrivateKey._getDerivationIndexes = function(path) {
}
var indexes = steps.slice(1).map(function(step) {
var index = parseInt(step);
index += step != index.toString() ? HDPrivateKey.Hardened : 0;
var index = step ? +step : NaN;
var isHardened = isNaN(index) && step[step.length-1] == "'";
if (isHardened) {
index = (+(step.slice(0, -1))) + HDPrivateKey.Hardened;
}
return index;
});

12
test/hdprivatekey.js

@ -234,6 +234,9 @@ describe('HDPrivate key interface', function() {
valid = HDPrivateKey.isValidPath('m/');
valid.should.equal(false);
valid = HDPrivateKey.isValidPath('m/12asd');
valid.should.equal(false);
valid = HDPrivateKey.isValidPath(HDPrivateKey.MaxHardened);
valid.should.equal(false);
});
@ -259,6 +262,15 @@ describe('HDPrivate key interface', function() {
indexes = HDPrivateKey._getDerivationIndexes("bad path");
expect(indexes).to.be.null;
indexes = HDPrivateKey._getDerivationIndexes("K");
expect(indexes).to.be.null;
indexes = HDPrivateKey._getDerivationIndexes("m/");
expect(indexes).to.be.null;
indexes = HDPrivateKey._getDerivationIndexes("m/123asd");
expect(indexes).to.be.null;
});
});

Loading…
Cancel
Save