Additional tests for hdValidatePath (#897)

* Additional tests for hdValidatePath

* Additional

* slip for Polkadot
This commit is contained in:
Jaco Greeff
2021-02-26 10:43:55 +01:00
committed by GitHub
parent 2e0b8e4d11
commit 46bfe643a6
3 changed files with 36 additions and 6 deletions
+7 -5
View File
@@ -8,9 +8,11 @@ export function hdValidatePath (path: string): boolean {
return false;
}
return !path
.split('/')
.slice(1)
.map((n) => parseInt(n.replace("'", ''), 10))
.some((n) => isNaN(n) && n < HARDENED);
const parts = path.split('/').slice(1);
return parts.every((n) => /^\d+'?$/.test(n)) && (
!parts
.map((n) => parseInt(n.replace("'", ''), 10))
.some((n) => isNaN(n) || (n >= HARDENED) || (n < 0))
);
}