Add fromSeed function to SLIP10Node, BIP44Node, BIP44CoinTypeNode#212
Merged
Add fromSeed function to SLIP10Node, BIP44Node, BIP44CoinTypeNode#212
fromSeed function to SLIP10Node, BIP44Node, BIP44CoinTypeNode#212Conversation
There was a problem hiding this comment.
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(); |
FrederikBolding
approved these changes
Mar 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new function to initialise a
key-treenode 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
secp256k1anded25519for now.ed25519Bip32may be added in the future.Closes #210