throw error if deriving an invalid path string

...the path consists "m", numbers, /, and ' characters
This commit is contained in:
Ryan X. Charles 2014-08-09 23:52:19 -07:00
parent 134952d1f8
commit efbebb3528
1 changed files with 4 additions and 1 deletions

View File

@ -215,10 +215,13 @@ BIP32.prototype.derive = function(path) {
var c = e[i];
if (i == 0) {
if (c != 'm') throw new Error('invalid path');
if (c != 'm') throw new Error('bip32: invalid path');
continue;
}
if (parseInt(c.replace("'", "")).toString() !== c.replace("'", ""))
throw new Error('bip32: invalid path');
var usePrivate = (c.length > 1) && (c[c.length - 1] == '\'');
var childIndex = parseInt(usePrivate ? c.slice(0, c.length - 1) : c) & 0x7fffffff;