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

Add extended key to BIP-44 coin type node #59

Merged
merged 3 commits into from
Apr 27, 2022
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
23 changes: 23 additions & 0 deletions src/BIP44CoinTypeNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fixtures from '../test/fixtures';
import { encodeExtendedKey, PRIVATE_KEY_VERSION } from './extended-keys';
import {
BIP_44_COIN_TYPE_DEPTH,
BIP44Node,
Expand Down Expand Up @@ -396,6 +397,28 @@ describe('BIP44CoinTypeNode', () => {
});
});

describe('extendedKey', () => {
it('returns the extended private key for nodes with a private key', async () => {
const coinType = 60;
const node = await BIP44CoinTypeNode.fromDerivationPath([
defaultBip39NodeToken,
BIP44PurposeNodeToken,
`bip32:${coinType}'`,
]);

const extendedKey = encodeExtendedKey({
version: PRIVATE_KEY_VERSION,
privateKey: node.privateKeyBuffer as Buffer,
chainCode: node.chainCodeBuffer,
depth: node.depth,
parentFingerprint: node.parentFingerprint,
index: node.index,
});

expect(node.extendedKey).toStrictEqual(extendedKey);
});
});

describe('toJSON', () => {
it('returns a JSON-compatible representation of the node', async () => {
const coinType = 60;
Expand Down
4 changes: 4 additions & 0 deletions src/BIP44CoinTypeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export class BIP44CoinTypeNode implements BIP44CoinTypeNodeInterface {
return this.#node.curve;
}

public get extendedKey(): string {
return this.#node.extendedKey;
}

/**
* Derives a BIP-44 `address_index` key corresponding to the path of this
* node and the specified `account`, `change`, and `address_index` values.
Expand Down