Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket1729 committed Nov 21, 2021
1 parent 7f3ee58 commit 9581f2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use bitcoin::{

use MiniscriptKey;

// use crate::Descriptor;

/// The MiniscriptKey corresponding to Descriptors. This can
/// either be Single public key or a Xpub
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
Expand Down Expand Up @@ -668,6 +670,11 @@ impl MiniscriptKey for DescriptorPublicKey {
}
}

// impl Descriptor<DescriptorPublicKey> {
// /// derive a [`Descriptor`] with a concrete [`bitcoin::PublicKey`] at a given index
// /// You can use all the methods from descriptor trait on this
// }

#[cfg(test)]
mod test {
use super::{DescriptorKeyParseError, DescriptorPublicKey, DescriptorSecretKey};
Expand Down
20 changes: 19 additions & 1 deletion src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
str::{self, FromStr},
};

use bitcoin::secp256k1;
use bitcoin::secp256k1::{self, Secp256k1};
use bitcoin::{self, Script};

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

/// derive a [`Descriptor`] with a concrete [`bitcoin::PublicKey`] at a given index
/// Removes all extended pubkeys and wildcards from the descriptor and only leaves
/// concrete [`bitcoin::PublicKey`]
///
/// # Panics
///
/// Panics if given an index ≥ 2^31
pub fn derive_desc<C: secp256k1::Verification>(
&self,
index: u32,
secp_ctx: Secp256k1<C>,
) -> Result<Descriptor<bitcoin::PublicKey>, ConversionError> {
let derived = self
.derive(index)
.translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))?;
todo!()
}

/// Parse a descriptor that may contain secret keys
///
/// Internally turns every secret key found into the corresponding public key and then returns a
Expand Down

0 comments on commit 9581f2e

Please sign in to comment.