Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose DerivationPath instance via getPath #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libraries/key-identifier/__tests__/key-identifier.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion libraries/key-identifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions libraries/key-identifier/src/key-identifier.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DerivationPath } from '@exodus/key-utils'

type PathIndex = number | string
type KeyType = 'legacy' | 'nacl' | 'secp256k1'
type DerivationAlgorithm = 'BIP32' | 'SLIP10'
Expand Down Expand Up @@ -26,6 +28,8 @@ export default class KeyIdentifier {
*/
derive(pathLike: string | PathIndex[]): KeyIdentifier

getPath(): DerivationPath

toJSON(): {
assetName?: string
derivationAlgorithm: DerivationAlgorithm
Expand Down
4 changes: 4 additions & 0 deletions libraries/key-identifier/src/key-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export default class KeyIdentifier {
})
}

getPath() {
return this.#derivationPath
}

toString() {
return `${this.derivationPath} (${this.derivationAlgorithm})`
}
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Loading