Fix hd string path parsing.
This commit is contained in:
parent
970bf12df8
commit
3bd361e27a
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue