Skip to content

Commit 6559557

Browse files
sgeislerdarosior
authored andcommitted
Implement ToPublicKey for DescriptorKey
1 parent ce5e219 commit 6559557

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/descriptor/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ impl MiniscriptKey for DescriptorPublicKey {
246246
}
247247
}
248248

249+
impl ToPublicKey for DescriptorPublicKey {
250+
fn to_public_key(&self) -> bitcoin::PublicKey {
251+
match *self {
252+
DescriptorPublicKey::PukKey(ref pk) => *pk,
253+
DescriptorPublicKey::XPub(ref xpub) => {
254+
let ctx = secp256k1::Secp256k1::verification_only();
255+
xpub.xpub
256+
.derive_pub(&ctx, &xpub.derivation_path)
257+
.expect("Shouldn't fail, only normal derivations")
258+
.public_key
259+
}
260+
}
261+
}
262+
263+
fn hash_to_hash160(hash: &Self::Hash) -> hash160::Hash {
264+
*hash
265+
}
266+
}
267+
249268
impl<Pk: MiniscriptKey> Descriptor<Pk> {
250269
/// Convert a descriptor using abstract keys to one using specific keys
251270
/// This will panic if translatefpk returns an uncompressed key when

0 commit comments

Comments
 (0)