-
Notifications
You must be signed in to change notification settings - Fork 300
doc: Keypair constructors #779
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
doc: Keypair constructors #779
Conversation
Clarify the conditions for returning the InvalidSecretKey error. Fixes rust-bitcoin#758
The constructor of a secret key should return InvalidSecretKey in case of error. I guess there was a typo / copy-and-paste error that was never tested.
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.
ACK aaf5fee
Ok(constants::SECRET_KEY_SIZE) => | ||
Keypair::from_seckey_slice(secp, &res[0..constants::SECRET_KEY_SIZE]), | ||
_ => Err(Error::InvalidPublicKey), | ||
_ => Err(Error::InvalidSecretKey), |
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.
Oh yes, the entire error type needs a lot of work...
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.
I think we should move deserialization/serialization into Rust and then we can provide sensible error types. Obviously in this case the variant was totally wrong, but in general the error types in this library are crappy because they're just thin wrappers around the numeric error returns from the C code.
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.
...lol, and half this API is "take a &[u8]
then length-check it" and should be replaced by an array-based on.
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.
Ye, I think we need to do all checks except "is on the curve"
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.
I remember that there was an initiative to replace slice-based methods with array-based ones. IDK if this was Miniscript or secp. In any case, I'm happy to write a follow-up PR to move the constructors to array parameters.
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.
@uncomputable that would be awesome.
If you want a fun weekend project you can also try to pull some parts out of #703 to replace point deserialization code with Rust. (That PR is out of sync and also IMO it does too much at once; we should practice Rust-ifying a couple functions and defining sensible APIs and error types.)
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.
ACK aaf5fee; successfully ran local tests
aaf5fee92e4200bb42c72cd67dd42b3dde07fb12 fix: Invalid secret key (Christian Lewe) d1d4ff9f01695526c01198dee643d273f0c32b9d doc: Keypair constructors accept odd keys (Christian Lewe) Pull request description: Clarify the conditions when `Keypair` construction fails and correct the error variant that is returned in one of the constructors. Fixes #758 ACKs for top commit: Kixunil: ACK aaf5fee92e4200bb42c72cd67dd42b3dde07fb12 apoelstra: ACK aaf5fee92e4200bb42c72cd67dd42b3dde07fb12; successfully ran local tests Tree-SHA512: 9b27c4ee1424619f9041183801e7c1214838f0b8d529e9c10a3e1f55264624b6b42b881e369bd9521bfa117d3dd5ce072caed4b8ee51c40e1016fc5be59a2894
Clarify the conditions when
Keypair
construction fails and correct the error variant that is returned in one of the constructors. Fixes #758