Fix bug in PSBT `Deserialize` for `XOnlyPublicKey`

During upgrade of `secp256k1` a number of function calls needed to be
rewritten to not use `from_slice` but `from_byte_array`. Unfortunately,
the conversion wasn't correct and caused panics on invalid inputs
rather than errors.

This fixes it simply by calling `try_into` on the entire slice and
converting the error.
This commit is contained in:
Martin Habovstiak 2025-03-05 13:05:04 +01:00
parent 8efacd4dda
commit bbe87eccf2
1 changed files with 1 additions and 1 deletions

View File

@ -261,7 +261,7 @@ impl Serialize for XOnlyPublicKey {
impl Deserialize for XOnlyPublicKey { impl Deserialize for XOnlyPublicKey {
fn deserialize(bytes: &[u8]) -> Result<Self, Error> { fn deserialize(bytes: &[u8]) -> Result<Self, Error> {
XOnlyPublicKey::from_byte_array( XOnlyPublicKey::from_byte_array(
bytes[..32].try_into().expect("statistically impossible to hit"), bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?,
) )
.map_err(|_| Error::InvalidXOnlyPublicKey) .map_err(|_| Error::InvalidXOnlyPublicKey)
} }