Skip to content

Commit 9581f2e

Browse files
committed
final
1 parent 7f3ee58 commit 9581f2e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/descriptor/key.rs

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use bitcoin::{
1212

1313
use MiniscriptKey;
1414

15+
// use crate::Descriptor;
16+
1517
/// The MiniscriptKey corresponding to Descriptors. This can
1618
/// either be Single public key or a Xpub
1719
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
@@ -668,6 +670,11 @@ impl MiniscriptKey for DescriptorPublicKey {
668670
}
669671
}
670672

673+
// impl Descriptor<DescriptorPublicKey> {
674+
// /// derive a [`Descriptor`] with a concrete [`bitcoin::PublicKey`] at a given index
675+
// /// You can use all the methods from descriptor trait on this
676+
// }
677+
671678
#[cfg(test)]
672679
mod test {
673680
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};

src/descriptor/mod.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::{
2929
str::{self, FromStr},
3030
};
3131

32-
use bitcoin::secp256k1;
32+
use bitcoin::secp256k1::{self, Secp256k1};
3333
use bitcoin::{self, Script};
3434

3535
use self::checksum::verify_checksum;
@@ -537,6 +537,24 @@ impl Descriptor<DescriptorPublicKey> {
537537
self.translate_pk2_infallible(|pk| pk.clone().derive(index))
538538
}
539539

540+
/// derive a [`Descriptor`] with a concrete [`bitcoin::PublicKey`] at a given index
541+
/// Removes all extended pubkeys and wildcards from the descriptor and only leaves
542+
/// concrete [`bitcoin::PublicKey`]
543+
///
544+
/// # Panics
545+
///
546+
/// Panics if given an index ≥ 2^31
547+
pub fn derive_desc<C: secp256k1::Verification>(
548+
&self,
549+
index: u32,
550+
secp_ctx: Secp256k1<C>,
551+
) -> Result<Descriptor<bitcoin::PublicKey>, ConversionError> {
552+
let derived = self
553+
.derive(index)
554+
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))?;
555+
todo!()
556+
}
557+
540558
/// Parse a descriptor that may contain secret keys
541559
///
542560
/// Internally turns every secret key found into the corresponding public key and then returns a

0 commit comments

Comments
 (0)