Cater for non-slash derived paths (#377)
This commit is contained in:
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user