-
-
Notifications
You must be signed in to change notification settings - Fork 17
Add fromSeed function to SLIP10Node, BIP44Node, BIP44CoinTypeNode
#212
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
Conversation
There was a problem hiding this 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📈
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