diff --git a/src/lib.rs b/src/lib.rs index 15c9b5673..1d5d1353d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,6 +116,7 @@ pub mod psbt; mod util; +use std::io::Write; use std::str::FromStr; use std::{error, fmt, hash, str}; @@ -155,6 +156,23 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha fn to_pubkeyhash(&self) -> Self::Hash; } +impl MiniscriptKey for bitcoin::secp256k1::PublicKey { + /// `is_uncompressed` always returns `false` + fn is_uncompressed(&self) -> bool { + false + } + + type Hash = hash160::Hash; + + fn to_pubkeyhash(&self) -> Self::Hash { + let mut engine = hash160::Hash::engine(); + engine + .write_all(&self.serialize()) + .expect("engines don't error"); + hash160::Hash::from_engine(engine) + } +} + impl MiniscriptKey for bitcoin::PublicKey { /// `is_uncompressed` returns true only for /// bitcoin::Publickey type if the underlying key is uncompressed.