aboutsummaryrefslogtreecommitdiff
path: root/bip39-standalone.html
diff options
context:
space:
mode:
Diffstat (limited to 'bip39-standalone.html')
-rw-r--r--bip39-standalone.html34
1 files changed, 33 insertions, 1 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html
index 9d975eb..dfeaa65 100644
--- a/bip39-standalone.html
+++ b/bip39-standalone.html
@@ -14838,7 +14838,39 @@ var Mnemonic = function(language) {
14838 } 14838 }
14839 14839
14840 function findDerivationPathErrors(path) { 14840 function findDerivationPathErrors(path) {
14841 // TODO 14841 // TODO is not perfect but is better than nothing
14842 // Inspired by
14843 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
14844 // and
14845 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
14846 var maxDepth = 255; // TODO verify this!!
14847 var maxIndexValue = Math.pow(2, 31); // TODO verify this!!
14848 if (path[0] != "m") {
14849 return "First character must be 'm'";
14850 }
14851 if (path.length > 1) {
14852 if (path[1] != "/") {
14853 return "Separator must be '/'";
14854 }
14855 var indexes = path.split("/");
14856 if (indexes.length > maxDepth) {
14857 return "Derivation depth is " + indexes.length + ", must be less than " + maxDepth;
14858 }
14859 for (var depth = 1; depth<indexes.length; depth++) {
14860 var index = indexes[depth];
14861 var invalidChars = index.replace(/^[0-9]+'?$/g, "")
14862 if (invalidChars.length > 0) {
14863 return "Invalid characters " + invalidChars + " found at depth " + depth;
14864 }
14865 var indexValue = parseInt(index.replace("'", ""));
14866 if (isNaN(depth)) {
14867 return "Invalid number at depth " + depth;
14868 }
14869 if (indexValue > maxIndexValue) {
14870 return "Value of " + indexValue + " at depth " + depth + " must be less than " + maxIndexValue;
14871 }
14872 }
14873 }
14842 return false; 14874 return false;
14843 } 14875 }
14844 14876