aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bip39-standalone.html34
-rw-r--r--src/js/index.js34
2 files changed, 66 insertions, 2 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
diff --git a/src/js/index.js b/src/js/index.js
index f131e01..6f0da65 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -232,7 +232,39 @@
232 } 232 }
233 233
234 function findDerivationPathErrors(path) { 234 function findDerivationPathErrors(path) {
235 // TODO 235 // TODO is not perfect but is better than nothing
236 // Inspired by
237 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
238 // and
239 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
240 var maxDepth = 255; // TODO verify this!!
241 var maxIndexValue = Math.pow(2, 31); // TODO verify this!!
242 if (path[0] != "m") {
243 return "First character must be 'm'";
244 }
245 if (path.length > 1) {
246 if (path[1] != "/") {
247 return "Separator must be '/'";
248 }
249 var indexes = path.split("/");
250 if (indexes.length > maxDepth) {
251 return "Derivation depth is " + indexes.length + ", must be less than " + maxDepth;
252 }
253 for (var depth = 1; depth<indexes.length; depth++) {
254 var index = indexes[depth];
255 var invalidChars = index.replace(/^[0-9]+'?$/g, "")
256 if (invalidChars.length > 0) {
257 return "Invalid characters " + invalidChars + " found at depth " + depth;
258 }
259 var indexValue = parseInt(index.replace("'", ""));
260 if (isNaN(depth)) {
261 return "Invalid number at depth " + depth;
262 }
263 if (indexValue > maxIndexValue) {
264 return "Value of " + indexValue + " at depth " + depth + " must be less than " + maxIndexValue;
265 }
266 }
267 }
236 return false; 268 return false;
237 } 269 }
238 270