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

doc: Keypair constructors #779

Merged
merged 2 commits into from
Feb 15, 2025

Conversation

uncomputable
Copy link
Contributor

@uncomputable uncomputable commented Feb 14, 2025

Clarify the conditions when Keypair construction fails and correct the error variant that is returned in one of the constructors. Fixes #758

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.
Copy link
Collaborator

@Kixunil Kixunil left a 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),
Copy link
Collaborator

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...

Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator

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"

Copy link
Contributor Author

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.

Copy link
Member

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.)

Copy link
Member

@apoelstra apoelstra left a 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

@apoelstra apoelstra merged commit 0ecd2a2 into rust-bitcoin:master Feb 15, 2025
29 of 30 checks passed
@uncomputable uncomputable deleted the 2025-02-fix-xonly-docs branch February 15, 2025 19:29
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.

Wrong doc for creating Keypair
3 participants