Remove redundant code on Legacy -> XOnly key From
What changed, and why it matters
This is a small internal code cleanup in the rust-bitcoin library. It replaces a slightly longer implementation of converting one public key type to another with a shorter one that calls an existing conversion. There is no change in behavior and no security issue.
No action needed. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the From<LegacyPublicKey> for XOnlyPublicKey implementation in crypto/src/key.rs. The old implementation manually called pk.to_inner().x_only_public_key() and then Self::from_secp(xonly, parity). The new implementation simply delegates to the existing From<secp256k1::PublicKey> for XOnlyPublicKey via pk.to_inner().into(). Since LegacyPublicKey::to_inner() returns a secp256k1::PublicKey, the behavior is identical. This is a pure simplification with no functional or security change.
Changed components
crypto/src/key.rsInspect captured patch +1 / −4
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index 571820c9..5efc8fb8 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -450,10 +450,7 @@ impl From<secp256k1::PublicKey> for XOnlyPublicKey {
impl From<LegacyPublicKey> for XOnlyPublicKey {
#[inline]
- fn from(pk: LegacyPublicKey) -> Self {
- let (xonly, parity) = pk.to_inner().x_only_public_key();
- Self::from_secp(xonly, parity)
- }
+ fn from(pk: LegacyPublicKey) -> Self { pk.to_inner().into() }
}
impl From<FullPublicKey> for XOnlyPublicKey {
Why this scored 15/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.