aboutsummaryrefslogtreecommitdiff
path: root/bip39-standalone.html
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-08-15 16:03:01 +1000
committerIan Coleman <coleman.ian@gmail.com>2016-08-15 16:03:25 +1000
commit30c9e79de32e529e9b87b836a1bc808e6dbbc646 (patch)
tree15e7ba8106c1503c4c704629cce03d8a15663b33 /bip39-standalone.html
parent38523d36dcce2c11baaf8dd742d02b94c41c7b23 (diff)
downloadBIP39-30c9e79de32e529e9b87b836a1bc808e6dbbc646.tar.gz
BIP39-30c9e79de32e529e9b87b836a1bc808e6dbbc646.tar.zst
BIP39-30c9e79de32e529e9b87b836a1bc808e6dbbc646.zip
Derivation Path errors are detected.
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