diff options
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/index.js | 34 |
1 files changed, 33 insertions, 1 deletions
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 | ||