-
Notifications
You must be signed in to change notification settings - Fork 245
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
Remove mentions of 32-byte slice from tweak APIs #453
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,8 +270,7 @@ impl SecretKey { | |
/// | ||
/// # Errors | ||
/// | ||
/// Returns an error if the resulting key would be invalid or if the tweak was not a 32-byte | ||
/// length slice. | ||
/// Returns an error if the resulting key would be invalid. | ||
#[inline] | ||
pub fn add_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> { | ||
unsafe { | ||
|
@@ -301,8 +300,7 @@ impl SecretKey { | |
/// | ||
/// # Errors | ||
/// | ||
/// Returns an error if the resulting key would be invalid or if the tweak was not a 32-byte | ||
/// length slice. | ||
/// Returns an error if the resulting key would be invalid. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can only error when Scalar is zero. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above about mutating self. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's the case. The resulting key would be invalid if it's 0, so scalar being zero can cause error only if the key is already invalid which this library prevents. This should produce error though: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anycase, these are unrelated to the PR itself. We can tackle this in separate issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, annoying GitHub UI... |
||
#[inline] | ||
pub fn mul_tweak(mut self, tweak: &Scalar) -> Result<SecretKey, Error> { | ||
unsafe { | ||
|
@@ -1255,7 +1253,7 @@ impl XOnlyPublicKey { | |
/// | ||
/// # Errors | ||
/// | ||
/// If the resulting key would be invalid or if the tweak was not a 32-byte length slice. | ||
/// If the resulting key would be invalid. | ||
/// | ||
/// # Examples | ||
/// | ||
|
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.
We can be more specific and say, returns an error only if the resultant key is zero. This only happens when Scalar is the negation of Secret Key.
The upstream documentation also states:
We should either 1) document this or 2) Make a copy and make sure self is not mutated 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.
It's already copied. :)
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.
This comment is for
tweak_add
. This only happens when Scalar is the negation of Secret Key.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 we let the
other
parameter beSecretKey
, we can safely unwrapThere 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
other
isSecretKey
we can unwrap fortweak_mul
but not fortweak_add
. To represent it in the type system:Then accept
IntoScalar
intweak_mul()