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

Ready for Review: Improve consistency for bip32::ChildNumber #126

Merged
merged 2 commits into from Aug 11, 2018

Conversation

dongcarl
Copy link
Member

There seemed to be some confusion as to whether the internal
represenation of a ChildNumber is supposed to be the index (0..2^31-1
for both Normal and Hardened) or the actual number (0..2^31-1 for
Normal and 2^31..2^32-1 for Hardened). This commits fixes this
confusion.

  • Make clear that the internal representation is the index rather
    than the actual number
  • Make the internal representation non-public
  • Provide methods for creating valid ChildNumbers
  • Change relevant callers and tests to conform to this new ChildNumber

My rationale for using index rather than the actual number as internal
representation is that the difference between the two enum variants
already encode wether a ChildNumber is a normal one or a hardened one,
so the only bit of extra information left to be encoded is its index.

There seemed to be some confusion as to whether the internal
represenation of a ChildNumber is supposed to be the index (0..2^31-1
for _both_ Normal and Hardened) or the actual number (0..2^31-1 for
Normal and 2^31..2^32-1 for Hardened). This commits fixes this
confusion.

- Make clear that the internal representation is the index rather
  than the actual number
- Make the internal representation non-public
- Provide methods for creating valid ChildNumbers
- Change relevant callers and tests to conform to this new ChildNumber

My rationale for using index rather than the actual number as internal
representation is that the difference between the two enum variants
already encode wether a ChildNumber is a normal one or a hardened one,
so the only bit of extra information left to be encoded is its index.
@dongcarl dongcarl changed the title Improve consistency for bip32::ChildNumber Ready for Review: Improve consistency for bip32::ChildNumber Aug 11, 2018
@apoelstra
Copy link
Member

Can you add helper methods is_hardened and is_normal ?

Copy link
Contributor

@jeandudey jeandudey left a comment

Choose a reason for hiding this comment

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

Concept ACK

@dongcarl
Copy link
Member Author

@apoelstra Done.

@apoelstra apoelstra merged commit 147259d into rust-bitcoin:master Aug 11, 2018
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.

None yet

3 participants