Remove parity argument and rename public_key
What changed, and why it matters
This commit is a routine API cleanup, not a security fix. It renames a method from `public_key` to `to_public_key` and removes a now-redundant `parity` argument because the parity information is already stored inside the x-only public key object. The code still produces the same public keys; callers just provide the parity in a different way. There is no indication this change fixes a vulnerability.
No security action required. Treat as a normal API-breaking change and update downstream code accordingly.
Security signals we found
No security-relevant keywords in commit title or message
No bug-fix language or vulnerability description
API rename and argument removal consistent with routine refactoring
No changes to cryptographic validation or secret handling
Evidence from the diff
The patch refactors XOnlyPublicKey::public_key(parity: Parity) into XOnlyPublicKey::to_public_key(&self), using the parity field already stored on XOnlyPublicKey. It also updates one PSBT call site to use with_parity(...).to_public_key() when both even and odd parities must be tried. The behavior is functionally equivalent; it is a naming and ergonomics change, not a security patch.
Changed components
bitcoin/src/crypto/key.rsbitcoin/src/psbt/mod.rsInspect captured patch +11 / −5
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 4512342f..773f07bd 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -232,10 +232,16 @@ impl XOnlyPublicKey {
(self.as_inner().serialize(), self.parity())
}
- /// Converts this x-only public key to a full public key given the parity.
+ /// Converts this x-only public key to a full public key.
+ ///
+ /// The [`PublicKey`] is constructed using the parity in this x-only public key.
#[inline]
- pub fn public_key(&self, parity: Parity) -> PublicKey {
- self.as_inner().public_key(parity).into()
+ // 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()
}
/// Verifies that a tweak produced by [`XOnlyPublicKey::add_tweak`] was computed correctly.
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index 907cf09e..8f37b7a3 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -880,14 +880,14 @@ impl GetKey for $map<PublicKey, PrivateKey> {
match key_request {
KeyRequest::Pubkey(pk) => Ok(self.get(&pk).cloned()),
KeyRequest::XOnlyPubkey(xonly) => {
- let pubkey_even = xonly.public_key(secp256k1::Parity::Even);
+ let pubkey_even = xonly.with_parity(secp256k1::Parity::Even).to_public_key();
let key = self.get(&pubkey_even).cloned();
if key.is_some() {
return Ok(key);
}
- let pubkey_odd = xonly.public_key(secp256k1::Parity::Odd);
+ let pubkey_odd = xonly.with_parity(secp256k1::Parity::Odd).to_public_key();
if let Some(priv_key) = self.get(&pubkey_odd).copied() {
let negated_priv_key = priv_key.negate();
return Ok(Some(negated_priv_key));
Why this scored 17/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.