-
Notifications
You must be signed in to change notification settings - Fork 305
Deprecate generate_schnorrsig_keypair method #372
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
Conversation
3645800 to
dc04e55
Compare
apoelstra
left a comment
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 dc04e55
Good to be consistent in naming, though I'm a bit confused about what this method does or why it exists. A KeyPair already contains a secret key and a public key, which can be extracted using upstream functions secp256k1_keypair_pub and secp256k1_keypair_sec (although we don't expose these, presumably an historical accident).
Also the comment doesn't really make sense to me. What is "batch keypair generation" and why would calling those methods directly be more efficient than calling this one?
|
I've ACKed this because it makes sense as a cleanup PR, but I think a better approach would be to deprecate this method, expose accessors for the secret/public part of the keypair, and suggest people just use |
lol, I assumed this 'batching' was just another part of the Taproot code I had not fully groked yet, funny you pointed this out. I'll re-work this PR. |
Currently to get the `XOnlyPublicKey` from a `KeyPair` users must do `XOnlyPublicKey::from_keypair(&kp)`. While this does the job we can make the lib more ergonomic by providing a method directly on `KeyPair` that calls through to `XOnlyPublicKey::from_keypair`. Add method `KeyPair::public_key(&self)`.
We have deprecated all other functions that use the identifier 'schnorrsig' but we missed `generate_schnorrsig_keypair`. This function is purely a helper function and serves no real purpose other than to reduce two lines of code to a single line. Downstream users can write this function themselves if they need it. Also, we recently added a new public method to `KeyPair` to get the public key in a slightly more ergonomic fashion. Use `kp.public_key()` when replacing usage of now deprecated `generate_schnorrsig_keypair` function.
dc04e55 to
97524b2
Compare
|
@apoelstra I've not added functionality for exposing secret key as you suggest because I'm not fully aware of why it was not exposed before hand. Seems like a different PR anyways. I have added a Re-review at your leisure please. |
apoelstra
left a comment
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 97524b2
|
|
||
| /// Gets the [XOnlyPublicKey] for this [KeyPair]. | ||
| #[inline] | ||
| pub fn public_key(&self) -> XOnlyPublicKey { |
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.
@tcharding @apoelstra
Post merge comment: The name is somewhat confusing because there is already a PublicKey(different from XOnlyPublicKey) type that the impl shown below. I know that we have had the discussion of return type in function names several times, but I think based on confusion between XOnlyPublicKey and PublicKey, we should have named to x_only_public_key. Perhaps we should add another method public_key that actually returns a full PublicKey.
Because this is already released code, we can perhaps use the names pub_key and x_only_pub_key ? What do you think?
impl From<KeyPair> for PublicKey {
#[inline]
fn from(pair: KeyPair) -> Self {
PublicKey::from_keypair(&pair)
}
}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.
The deprecate thing is just to try and be kind to our users, right? No need to be dogmatic with it if we botch something up and there is no nice way to fix it nicely while using 'deprecated since'. Also trait impls can't be deprecated anyways so we cannot be dogmatic about it.
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.
Sorry, for the long unclear previous comment. I was talking about the first commit in this PR. Not the second one that deprecates another method. My basic objection was that .public_key should have returned the PublicKey type, but it returns the XonlyPublicKey type.
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 my bad :)
…keypair method 97524b2da7885d74a7c15d23d9db22882b53f0f2 Deprecate generate_schnorrsig_keypair (Tobin Harding) 389abddcc789da672071aa9ae452664aeecce9ec Add method KeyPair::public_key (Tobin Harding) Pull request description: Recently we deprecated a bunch of functions/methods that used the term `schnorrsig`. Seems we left `generate_schnorrsig_keypair` in there, along with some stale docs on it. - Patch 1: Adds method `KeyPair::public_key` that calls through to `XOnlyPublicKey::from_keypair`. - Patch 2: Deprecates `generate_schnorrsig_keypair` and uses the newly defined `pk.public_key()` everywhere. ### Note to reviewers Please note, this PR has been totally re-written using the suggestions below by @apoelstra. ACKs for top commit: apoelstra: ACK 97524b2da7885d74a7c15d23d9db22882b53f0f2 Tree-SHA512: a10255d04b86c0031d5cfe4b6357224bc7bcd31c7e278d28af414a34ba4f158dd05d712c4878dfdc327ff8cb42b4421cc0a4b2605c6781691a3158b237fda2d3
…keypair method 97524b2da7885d74a7c15d23d9db22882b53f0f2 Deprecate generate_schnorrsig_keypair (Tobin Harding) 389abddcc789da672071aa9ae452664aeecce9ec Add method KeyPair::public_key (Tobin Harding) Pull request description: Recently we deprecated a bunch of functions/methods that used the term `schnorrsig`. Seems we left `generate_schnorrsig_keypair` in there, along with some stale docs on it. - Patch 1: Adds method `KeyPair::public_key` that calls through to `XOnlyPublicKey::from_keypair`. - Patch 2: Deprecates `generate_schnorrsig_keypair` and uses the newly defined `pk.public_key()` everywhere. ### Note to reviewers Please note, this PR has been totally re-written using the suggestions below by @apoelstra. ACKs for top commit: apoelstra: ACK 97524b2da7885d74a7c15d23d9db22882b53f0f2 Tree-SHA512: a10255d04b86c0031d5cfe4b6357224bc7bcd31c7e278d28af414a34ba4f158dd05d712c4878dfdc327ff8cb42b4421cc0a4b2605c6781691a3158b237fda2d3
Recently we deprecated a bunch of functions/methods that used the term
schnorrsig. Seems we leftgenerate_schnorrsig_keypairin there, along with some stale docs on it.KeyPair::public_keythat calls through toXOnlyPublicKey::from_keypair.generate_schnorrsig_keypairand uses the newly definedpk.public_key()everywhere.Note to reviewers
Please note, this PR has been totally re-written using the suggestions below by @apoelstra.