From 45b4e834718631e53f74f3f370a7f8b7c7a24221 Mon Sep 17 00:00:00 2001 From: Jan W Date: Wed, 31 Jul 2024 11:46:52 +0200 Subject: [PATCH 1/2] feat: expose DerivationPath instance via getPath --- .../__tests__/key-identifier.test.js | 15 +++++++++++++++ libraries/key-identifier/src/key-identifier.d.ts | 4 ++++ libraries/key-identifier/src/key-identifier.js | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/libraries/key-identifier/__tests__/key-identifier.test.js b/libraries/key-identifier/__tests__/key-identifier.test.js index 1a7151b3..a3bd8671 100644 --- a/libraries/key-identifier/__tests__/key-identifier.test.js +++ b/libraries/key-identifier/__tests__/key-identifier.test.js @@ -1,5 +1,6 @@ import { createKeyIdentifierForExodus } from '@exodus/key-ids' import KeyIdentifier from '../src/key-identifier.js' +import { DerivationPath } from '@exodus/key-utils' describe('KeyIdentifier', () => { it('should fail on incorrect construction', () => { @@ -104,6 +105,20 @@ describe('KeyIdentifier', () => { }).toThrow() }) + describe('getPath', () => { + test('returns derivation path', () => { + const keyId = new KeyIdentifier({ + derivationAlgorithm: 'BIP32', + assetName: 'ethereum', + derivationPath: 'm/44/60/0/0/0', + }) + + const derivationPath = keyId.getPath() + expect(derivationPath).toBeInstanceOf(DerivationPath) + expect(derivationPath.toPathArray()).toEqual([44, 60, 0, 0, 0]) + }) + }) + describe('.extend()', () => { test('extends derivation path', () => { const keyId = new KeyIdentifier({ diff --git a/libraries/key-identifier/src/key-identifier.d.ts b/libraries/key-identifier/src/key-identifier.d.ts index 7e7121aa..34e38551 100644 --- a/libraries/key-identifier/src/key-identifier.d.ts +++ b/libraries/key-identifier/src/key-identifier.d.ts @@ -1,3 +1,5 @@ +import type { DerivationPath } from '@exodus/key-utils' + type PathIndex = number | string type KeyType = 'legacy' | 'nacl' | 'secp256k1' type DerivationAlgorithm = 'BIP32' | 'SLIP10' @@ -26,6 +28,8 @@ export default class KeyIdentifier { */ derive(pathLike: string | PathIndex[]): KeyIdentifier + getPath(): DerivationPath + toJSON(): { assetName?: string derivationAlgorithm: DerivationAlgorithm diff --git a/libraries/key-identifier/src/key-identifier.js b/libraries/key-identifier/src/key-identifier.js index e97858fc..0c5f331b 100644 --- a/libraries/key-identifier/src/key-identifier.js +++ b/libraries/key-identifier/src/key-identifier.js @@ -58,6 +58,10 @@ export default class KeyIdentifier { }) } + getPath() { + return this.#derivationPath + } + toString() { return `${this.derivationPath} (${this.derivationAlgorithm})` } From 9efc646b0f9611ca5f2ad91c6b5b039cd292fc19 Mon Sep 17 00:00:00 2001 From: Jan W Date: Wed, 31 Jul 2024 15:36:34 +0200 Subject: [PATCH 2/2] chore: bump key-utils --- libraries/key-identifier/package.json | 2 +- yarn.lock | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libraries/key-identifier/package.json b/libraries/key-identifier/package.json index a688c440..89d80ce1 100644 --- a/libraries/key-identifier/package.json +++ b/libraries/key-identifier/package.json @@ -26,7 +26,7 @@ "todo:reenable:test:integration": "jest --testMatch='**/*.integration-test.js'" }, "dependencies": { - "@exodus/key-utils": "^3.5.1", + "@exodus/key-utils": "^3.6.1", "minimalistic-assert": "^1.0.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 028a50e1..5597a058 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1986,7 +1986,7 @@ __metadata: resolution: "@exodus/key-identifier@workspace:libraries/key-identifier" dependencies: "@exodus/key-ids": ^1.2.2 - "@exodus/key-utils": ^3.5.1 + "@exodus/key-utils": ^3.6.1 "@exodus/keychain": "workspace:^" minimalistic-assert: ^1.0.1 languageName: unknown @@ -2035,6 +2035,18 @@ __metadata: languageName: node linkType: hard +"@exodus/key-utils@npm:^3.6.1": + version: 3.6.1 + resolution: "@exodus/key-utils@npm:3.6.1" + dependencies: + "@exodus/bip32": ^2.1.0 + "@exodus/hdkey": ^2.1.0-exodus.0 + bip32-path: ^0.4.2 + minimalistic-assert: ^1.0.1 + checksum: d3e8e9832f28ea93188bde94a22be248d4a5bc46bc62dd54d79a783fbc7eb233dbbef3b8f6bf47539a9ac808adca9ea8cd5465a6307f1790fdefda0b9832d4da + languageName: node + linkType: hard + "@exodus/keychain@npm:^5.0.1": version: 5.0.1 resolution: "@exodus/keychain@npm:5.0.1"