Skip to content

Commit 0888fe9

Browse files
committed
Implement MiniscriptKey for secp256k1 PublicKey
1 parent 75ff627 commit 0888fe9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub mod psbt;
116116

117117
mod util;
118118

119+
use std::io::Write;
119120
use std::str::FromStr;
120121
use std::{error, fmt, hash, str};
121122

@@ -155,6 +156,23 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
155156
fn to_pubkeyhash(&self) -> Self::Hash;
156157
}
157158

159+
impl MiniscriptKey for bitcoin::secp256k1::PublicKey {
160+
/// `is_uncompressed` always returns `false`
161+
fn is_uncompressed(&self) -> bool {
162+
false
163+
}
164+
165+
type Hash = hash160::Hash;
166+
167+
fn to_pubkeyhash(&self) -> Self::Hash {
168+
let mut engine = hash160::Hash::engine();
169+
engine
170+
.write_all(&self.serialize())
171+
.expect("engines don't error");
172+
hash160::Hash::from_engine(engine)
173+
}
174+
}
175+
158176
impl MiniscriptKey for bitcoin::PublicKey {
159177
/// `is_uncompressed` returns true only for
160178
/// bitcoin::Publickey type if the underlying key is uncompressed.

0 commit comments

Comments
 (0)