-
Notifications
You must be signed in to change notification settings - Fork 280
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
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
@@ -891,7 +891,7 @@ impl Keypair { | |||
match from_hex(s, &mut res) { | |||
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
Clarify the conditions when
Keypair
construction fails and correct the error variant that is returned in one of the constructors. Fixes #758