-
Notifications
You must be signed in to change notification settings - Fork 276
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
BIP 0340 followups #253
BIP 0340 followups #253
Conversation
fa26333
to
37049d7
Compare
let err = ffi::secp256k1_xonly_pubkey_tweak_add_check( | ||
secp.ctx, | ||
tweaked_ser.as_c_ptr(), | ||
if tweaked_parity { 1 } else { 0 }, |
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.
You can do tweaked_parity as u8
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 nice. Though I'd have to cast to a c_int
... with the export, the if statement is actually shorter, and in any case it's more explicit.
src/schnorrsig.rs
Outdated
secp.ctx, | ||
tweaked_ser.as_c_ptr(), | ||
if tweaked_parity { 1 } else { 0 }, | ||
&self.0 as *const _, |
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.
Can you replace with self.0.as_c_ptr()
?
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 don't think so, this is a FFI type not a byte array
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.
References coerce to pointers, so you wouldn't actually need the cast: &self.0
.
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 I had no idea. Added a commit which fixes this across the library.
src/schnorrsig.rs
Outdated
tweaked_key: &Self, | ||
tweaked_parity: bool, | ||
tweak: &[u8], | ||
) -> Result<(), Error> { |
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.
What do you think about passing tweak: [u8; 32]
and then returning bool
instead of a Result?
In general I feel like it would be nicer to use the type system to require sizes instead of adding dozens of results/errors (especially with TryFrom
that let's you slice.try_into()?
for converting to array, but that's 1.34)
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.
if for ergonomic pre 1.34 reasons you want to keep it as a slice then that's ok
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.
Yeah I think it'd be reasonable to use arrays here.
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.
Welll, for what it's worth we already have an error return here if the user passes an invalid tweak. If you know you're giving a hash then it can't fail, but that's still an error you have to .unwrap
away.
I'm not sure there's any additonal ergonomics loss to using a slice.
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.
LGTM
Couple things on #237 that weren't done in the original PR.