From 828688bd109aef25ae36d50741d8e1850f6f0cd5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 21 Mar 2019 11:48:08 +0100 Subject: [PATCH] Cater for non-slash derived paths (#377) --- CHANGELOG.md | 5 +++++ packages/util-crypto/src/key/extractPath.spec.ts | 6 ++++++ packages/util-crypto/src/key/extractPath.ts | 7 ++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3099bc5..c3f571bab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/util-crypto/src/key/extractPath.spec.ts b/packages/util-crypto/src/key/extractPath.spec.ts index 6e4acd064..3ab5c187f 100644 --- a/packages/util-crypto/src/key/extractPath.spec.ts +++ b/packages/util-crypto/src/key/extractPath.spec.ts @@ -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/); + }); }); diff --git a/packages/util-crypto/src/key/extractPath.ts b/packages/util-crypto/src/key/extractPath.ts index 92f3a34fe..3d9b315e7 100644 --- a/packages/util-crypto/src/key/extractPath.ts +++ b/packages/util-crypto/src/key/extractPath.ts @@ -18,17 +18,18 @@ type ExtractResult = { export default function keyExtractPath (derivePath: string): ExtractResult { const parts = derivePath.match(RE_JUNCTION); const path: Array = []; + 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