mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-18 08:22:16 +00:00
Derivation Path errors are detected.
This commit is contained in:
@@ -14838,7 +14838,39 @@ var Mnemonic = function(language) {
|
||||
}
|
||||
|
||||
function findDerivationPathErrors(path) {
|
||||
// TODO
|
||||
// TODO is not perfect but is better than nothing
|
||||
// Inspired by
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
|
||||
// and
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
|
||||
var maxDepth = 255; // TODO verify this!!
|
||||
var maxIndexValue = Math.pow(2, 31); // TODO verify this!!
|
||||
if (path[0] != "m") {
|
||||
return "First character must be 'm'";
|
||||
}
|
||||
if (path.length > 1) {
|
||||
if (path[1] != "/") {
|
||||
return "Separator must be '/'";
|
||||
}
|
||||
var indexes = path.split("/");
|
||||
if (indexes.length > maxDepth) {
|
||||
return "Derivation depth is " + indexes.length + ", must be less than " + maxDepth;
|
||||
}
|
||||
for (var depth = 1; depth<indexes.length; depth++) {
|
||||
var index = indexes[depth];
|
||||
var invalidChars = index.replace(/^[0-9]+'?$/g, "")
|
||||
if (invalidChars.length > 0) {
|
||||
return "Invalid characters " + invalidChars + " found at depth " + depth;
|
||||
}
|
||||
var indexValue = parseInt(index.replace("'", ""));
|
||||
if (isNaN(depth)) {
|
||||
return "Invalid number at depth " + depth;
|
||||
}
|
||||
if (indexValue > maxIndexValue) {
|
||||
return "Value of " + indexValue + " at depth " + depth + " must be less than " + maxIndexValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user