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

wallet-core: Add EIP2333 derivation #3529

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

wallet-core: Add EIP2333 derivation #3529

wants to merge 3 commits into from

Conversation

fed-franz
Copy link
Contributor

Implements #3476

@fed-franz fed-franz added type:feature implementing a new feature module:wallet-core labels Feb 28, 2025
@fed-franz fed-franz self-assigned this Feb 28, 2025
@fed-franz fed-franz linked an issue Feb 28, 2025 that may be closed by this pull request
@fed-franz fed-franz force-pushed the eip2333 branch 3 times, most recently from 4d92d1b to d729030 Compare March 4, 2025 10:44
moCello
moCello previously approved these changes Mar 6, 2025
Copy link
Member

@moCello moCello left a comment

Choose a reason for hiding this comment

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

Very good work!
I only have minor and mostly structural comments:
Please move the module under the keys module.
And maybe consider having all functions private except derive_bls_sk. The reasoning here is that in case we need them somewhen in the future, making them public will only cause a minor version update. But if we need to change them for some reason and they are public, the change will trigger a major version bump.

/// * `lamport_sk` - A container for the resulting lamport SK
///
/// # Panics
/// Panics if the HKDF expansion fails due to an invalid output length.
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I wonder what is an invalid output length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// the master key to a child key with a given index.
#[test]
fn test_child_derivation() {
// All test cases are taken from the EIP2333 specification
Copy link
Member

Choose a reason for hiding this comment

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

Can you link the website of the test-data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link to EIP2333 specification is provided at the beginning of the document. Should I duplicate it?

Comment on lines 306 to 309
// salt = H(salt)
if sk.is_zero().into() {
salt = Sha256::digest(salt);
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this if-statement is here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid computing the digest if the next iteration is not going to be executed.
Logically this digest should be computed at the beginning of each iteration, but it was a bit complicated to do it because the initialization value of salt has a different length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:wallet-core type:feature implementing a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wallet-core: implement EIP2333 key derivation
3 participants