diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 7a045cfb5..d73f84180 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -466,7 +466,7 @@ impl PrivateKey { ) -> Result { Ok(PrivateKey::new( secp256k1::SecretKey::from_byte_array( - data[..32].try_into().expect("Slice should be exactly 32 bytes"), + data.try_into().map_err(|_| secp256k1::Error::InvalidSecretKey)?, )?, network, ))