-
Notifications
You must be signed in to change notification settings - Fork 281
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
Improve API ergonomics #27
Improve API ergonomics #27
Conversation
Concept ACK. @TheBlueMatt can I get a concept ACK on this before I do a detailed review? It'll break the API in a ton of ways but moves runtime checks into compile-time checks which is awesome. |
Oh this is awesome, definitely Concept ACK, but can we make sure to flush all changes to crates.io in a minor version bump before we merge this (with a major version bump?). |
Yep for sure. Will make sure all current changes are on crates before merging any part of this. |
Pushed current |
Awesome news! |
Can you squash the first three commits together, and move
out of |
Add type parameter to Secp256k1 Add PhantomData for C Separate into structs and traits Move constructors to own impl blocks
7ceaebf
to
fa02b67
Compare
I squashed the first commits. This one now compiles. The second commit makes the tests pass. I also fixed the warnings about missing documentation by adding documentation to the public items I added. |
This looks great. ACK, except that there's one remaining warning (in the Let me know if you want to clean up the history at all. It looks like the unit tests pass for every commit except the first, which is fine by me. |
Oh I must have overlooked that one! Will fix asap! I will take another look at the history. The commits are indeed probably a bit too fine grained. |
The new API allows us to remove a bunch of tests which are now checked by the compiler.
Remove ContextFlag enum Remove InvalidContext error-enum variant Remove unused imports
This introduces the actual breaking API change.
86a9e37
to
20222d5
Compare
Let me know if the new history is better now :) |
Much better, thanks :) |
While working with the library, I noticed a slight inconvenience regarding the error handling: All methods on the
Secp256k1
struct which deal with signing return aResult
because the context might not have been initialized for signing.However, if the code invoking the sign-methods created the instance of
Secp256k1
itself, it can be sure that the context will always be correct. It still has to handle the error although it will never occur, which is inconvenient.The PR proposes a different approach regarding the capabilities of the underlying context of the
Secp256k1
struct. Through the use of generics, the check of "can this instance of Secp256k1 sign a message" is covered by the compiler. This does not only resolve the above stated inconvenience but actually makes it possible to 'request' an instance ofSecp256k1
with certain capabilities from the caller of your code.The downside of this PR is that it introduces a few breaking changes:
Secp256k1#sign
does no longer return aResult
Secp256k1#sign_recoverable
does no longer return aResult
Secp256k1#generate_keypair
does no longer return aResult
PublicKey#from_secret_key
does no longer return aResult
ContextFlag
has been removed (and all methods using it)IncapableContext
of theError
enum has been removed.Let me know what you think about the approach :)