Change XOnlyPublicKey::to_public_key to take self
What changed, and why it matters
This commit is a routine API cleanup, not a security fix. It changes one function so it takes its input by value instead of by reference, matching normal Rust conventions for small copyable types. There is no bug being fixed and no security relevance stated.
No security action needed. Treat as a normal API/ergonomics change; review downstream callers only if you rely on the previous signature.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies XOnlyPublicKey::to_public_key in bitcoin/src/crypto/key.rs to accept self by value rather than &self. The old implementation deliberately used &self to avoid a copy and suppressed the resulting clippy::wrong_self_convention lint. The new implementation accepts self, relying on the Copy trait and compiler optimizations. The underlying cryptographic computation (as_inner().public_key(self.parity()).into()) is unchanged.
Changed components
bitcoin/src/crypto/key.rsXOnlyPublicKey::to_public_keyInspect captured patch +3 / −5
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index ad385140..09b62ff0 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -310,11 +310,9 @@ impl XOnlyPublicKey {
///
/// The [`PublicKey`] is constructed using the parity in this x-only public key.
#[inline]
- // to_* functions are used for non-free conversions to owned types. Clippy complains
- // since XOnlyPublicKey is Copy but we intentionally use &self to remove a copy and
- // to_* to indicate the cost of the operation.
- #[allow(clippy::wrong_self_convention)]
- pub fn to_public_key(&self) -> PublicKey { self.as_inner().public_key(self.parity()).into() }
+ pub fn to_public_key(self) -> PublicKey {
+ self.as_inner().public_key(self.parity()).into()
+ }
/// Verifies that a tweak produced by [`XOnlyPublicKey::add_tweak`] was computed correctly.
///
Why this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.