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 property to SLIP10Node #196

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 4 additions & 42 deletions src/BIP44Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import {
MIN_BIP_44_DEPTH,
} from './constants';
import type { SupportedCurve } from './curves';
import {
decodeExtendedKey,
encodeExtendedKey,
PRIVATE_KEY_VERSION,
PUBLIC_KEY_VERSION,
} from './extended-keys';
import { decodeExtendedKey, PRIVATE_KEY_VERSION } from './extended-keys';
import { SLIP10Node, validateBIP32Depth } from './SLIP10Node';
import { isHardened } from './utils';

Expand Down Expand Up @@ -161,24 +156,10 @@ export class BIP44Node implements BIP44NodeInterface {
});
}

const {
privateKey,
publicKey,
chainCode,
depth,
parentFingerprint,
index,
} = options;

validateBIP44Depth(depth);
validateBIP44Depth(options.depth);

const node = await SLIP10Node.fromExtendedKey({
privateKey,
publicKey,
chainCode,
depth,
parentFingerprint,
index,
...options,
Mrtenz marked this conversation as resolved.
Show resolved Hide resolved
curve: 'secp256k1',
});

Expand Down Expand Up @@ -279,26 +260,7 @@ export class BIP44Node implements BIP44NodeInterface {
}

public get extendedKey(): string {
const data = {
depth: this.depth,
parentFingerprint: this.parentFingerprint,
index: this.index,
chainCode: this.chainCodeBytes,
};

if (this.privateKeyBytes) {
return encodeExtendedKey({
...data,
version: PRIVATE_KEY_VERSION,
privateKey: this.privateKeyBytes,
});
}

return encodeExtendedKey({
...data,
version: PUBLIC_KEY_VERSION,
publicKey: this.publicKeyBytes,
});
return this.#node.extendedKey;
}

public get curve(): SupportedCurve {
Expand Down
Loading
Loading