Depend on bitcoin_hashes v0.12

Upgrade to use the newly released `bitcoin_hashes`.
This commit is contained in:
Tobin C. Harding 2023-02-02 00:31:53 +11:00
parent c9310884b6
commit 8e772493dc
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
5 changed files with 11 additions and 11 deletions

View File

@ -42,7 +42,7 @@ serde = { version = "1.0", default-features = false, optional = true }
# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
# the respective -std feature e.g., bitcoin-hashes-std
bitcoin_hashes = { version = "0.11", default-features = false, optional = true }
bitcoin_hashes = { version = "0.12", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, optional = true }
[dev-dependencies]

View File

@ -11,7 +11,7 @@ fn verify<C: Verification>(
pubkey: [u8; 33],
) -> Result<bool, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_slice(&msg)?;
let msg = Message::from_slice(msg.as_ref())?;
let sig = ecdsa::Signature::from_compact(&sig)?;
let pubkey = PublicKey::from_slice(&pubkey)?;
@ -24,7 +24,7 @@ fn sign<C: Signing>(
seckey: [u8; 32],
) -> Result<ecdsa::Signature, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_slice(&msg)?;
let msg = Message::from_slice(msg.as_ref())?;
let seckey = SecretKey::from_slice(&seckey)?;
Ok(secp.sign_ecdsa(&msg, &seckey))
}

View File

@ -11,7 +11,7 @@ fn recover<C: Verification>(
recovery_id: u8,
) -> Result<PublicKey, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_slice(&msg)?;
let msg = Message::from_slice(msg.as_ref())?;
let id = ecdsa::RecoveryId::from_i32(recovery_id as i32)?;
let sig = ecdsa::RecoverableSignature::from_compact(&sig, id)?;
@ -24,7 +24,7 @@ fn sign_recovery<C: Signing>(
seckey: [u8; 32],
) -> Result<ecdsa::RecoverableSignature, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_slice(&msg)?;
let msg = Message::from_slice(msg.as_ref())?;
let seckey = SecretKey::from_slice(&seckey)?;
Ok(secp.sign_ecdsa_recoverable(&msg, &seckey))
}

View File

@ -260,7 +260,7 @@ mod tests {
engine.input(&xy.as_ref()[..32]);
let secret_bh = sha256::Hash::from_engine(engine);
assert_eq!(secret_bh.as_inner(), secret_sys.as_ref());
assert_eq!(secret_bh.as_byte_array(), secret_sys.as_ref());
}
#[test]

View File

@ -216,19 +216,19 @@ pub trait ThirtyTwoByteHash {
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256::Hash {
fn into_32(self) -> [u8; 32] { self.into_inner() }
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256d::Hash {
fn into_32(self) -> [u8; 32] { self.into_inner() }
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
fn into_32(self) -> [u8; 32] { self.into_inner() }
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
/// A (hashed) message input to an ECDSA signature.
@ -1046,12 +1046,12 @@ mod tests {
let hash = hashes::sha256::Hash::hash(test_bytes);
let msg = Message::from(hash);
assert_eq!(msg.0, hash.into_inner());
assert_eq!(msg.0, hash.to_byte_array());
assert_eq!(msg, Message::from_hashed_data::<hashes::sha256::Hash>(test_bytes));
let hash = hashes::sha256d::Hash::hash(test_bytes);
let msg = Message::from(hash);
assert_eq!(msg.0, hash.into_inner());
assert_eq!(msg.0, hash.to_byte_array());
assert_eq!(msg, Message::from_hashed_data::<hashes::sha256d::Hash>(test_bytes));
}
}