Cater for non-slash derived paths (#377)

This commit is contained in:
Jaco Greeff
2019-03-21 11:48:08 +01:00
committed by GitHub
parent 673906fb37
commit 828688bd10
3 changed files with 15 additions and 3 deletions
+5
View File
@@ -1,3 +1,8 @@
# 0.40.1
- Add additional derivation path extraction mechanisms to util-crypto
- Add createFromUri function to keypair (creates, does not add it)
# 0.39.1
- Pull in bip39 generation functions from @poladkot/wasm-crypto with a fallback to the pure JS versions
@@ -44,4 +44,10 @@ describe('keyExtractPath', () => {
() => keyExtractPath('1/2')
).toThrow(/does not match input/);
});
it('does not extract from invalid paths', () => {
expect(
() => keyExtractPath('hello')
).toThrow(/does not match input/);
});
});
+4 -3
View File
@@ -18,17 +18,18 @@ type ExtractResult = {
export default function keyExtractPath (derivePath: string): ExtractResult {
const parts = derivePath.match(RE_JUNCTION);
const path: Array<DeriveJunction> = [];
let constructed = '';
if (parts) {
const constructed = parts.join('');
assert(constructed === derivePath, `Re-constructed path "${constructed}" does not match input`);
constructed = parts.join('');
parts.forEach((value: string) => {
path.push(DeriveJunction.from(value.substr(1)));
});
}
assert(constructed === derivePath, `Re-constructed path "${constructed}" does not match input`);
return {
parts,
path