Skip to content

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Mar 6, 2025

This adds a new function to initialise a key-tree node from a BIP-39 seed. This can be used to skip the step from mnemonic phrase to seed, and can improve performance if the seed is already available.

This function is only supported for secp256k1 and ed25519 for now. ed25519Bip32 may be added in the future.

Closes #210

@Mrtenz Mrtenz requested a review from a team as a code owner March 6, 2025 15:19
@Mrtenz Mrtenz requested a review from Copilot March 6, 2025 18:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces a new "fromSeed" function for SLIP10Node, BIP44Node, and BIP44CoinTypeNode that allows initializing a key-tree node directly from a seed rather than from a mnemonic phrase. It updates tests and internal derivation logic to use a Uint8Array seed when available and adjusts types and error messages accordingly.

  • Adds a direct seed-based initialization method for hierarchical nodes.
  • Updates test fixtures and related tests to use the seed value.
  • Adjusts utility and conversion functions to support seed-based derivation.

Reviewed Changes

File Description
src/BIP44CoinTypeNode.test.ts Adds tests for initializing a BIP44CoinTypeNode from a seed, including custom crypto support
src/BIP44Node.test.ts Adds tests for initializing a BIP44Node from a seed and updates path inputs from mnemonic to seed
src/utils.ts Updates utility functions and types to support seed-based derivation
src/derivers/bip39.ts Updates derivation functions to use a Uint8Array seed when provided
src/derivers/bip39.test.ts Adds tests for getDerivationPathWithSeed and updates paths to use seed conversions
src/SLIP10Node.ts Adds a new static async fromSeed method and updates the derivation logic accordingly
src/BIP44CoinTypeNode.ts Adds a fromSeed static method using the new derivation function
src/BIP44Node.ts Adds a fromSeed static method and updates derivation path validations
src/derivation.test.ts Updates many tests to use seed inputs and getDerivationPathWithSeed for key derivation
test/fixtures.ts Adds a seed fixture computed from the mnemonic
test/reference-implementations.test.ts Updates reference tests with new seed-based derivation method
src/constants.ts Adds new type definitions to differentiate seed-based derivation paths
src/SLIP10Node.test.ts Updates tests to use fixtures.local.seed and new error messages for fromSeed

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/SLIP10Node.ts:430

  • Ensure that the derivationPath passed to fromSeed is already in seed format (i.e. its first element is a Uint8Array) as expected, or consider invoking getDerivationPathWithSeed for additional conversion to enforce consistency with fromDerivationPath.
static async fromSeed({ derivationPath, network, curve }: SLIP10DerivationPathOptions, cryptographicFunctions?: CryptographicFunctions): Promise<SLIP10Node> {

src/BIP44CoinTypeNode.ts:175

  • [nitpick] Since the expected derivation path for a coin type node should have exactly three segments (seed, purpose, and coin type), consider explicitly validating that derivationPath.length is exactly 3 instead of using (derivationPath.length - 1) for depth validation.
static async fromSeed({ derivationPath, network }: BIP44CoinTypeSeedOptions, cryptographicFunctions?: CryptographicFunctions): Promise<BIP44CoinTypeNode> {

expect(node.path).toStrictEqual(pathString);

expect(functions.hmacSha512).toHaveBeenCalledTimes(3);
expect(functions.pbkdf2Sha512).not.toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📈

@Mrtenz Mrtenz merged commit 04e0066 into main Mar 7, 2025
21 checks passed
@Mrtenz Mrtenz deleted the mrtenz/from-seed branch March 7, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support specifying the master seed instead of the raw mnemonic bytes for root nodes

3 participants