pub enum DescriptorPublicKey {
SinglePub(DescriptorSinglePub),
XPub(DescriptorXKey<ExtendedPubKey>),
}
Expand description
The MiniscriptKey corresponding to Descriptors. This can either be Single public key or a Xpub
Variants§
Implementations§
Source§impl DescriptorPublicKey
impl DescriptorPublicKey
Sourcepub fn master_fingerprint(&self) -> Fingerprint
pub fn master_fingerprint(&self) -> Fingerprint
The fingerprint of the master key associated with this key, 0x00000000
if none.
Sourcepub fn full_derivation_path(&self) -> DerivationPath
pub fn full_derivation_path(&self) -> DerivationPath
Full path, from the master key
For wildcard keys this will return the path up to the wildcard, so you can get full paths by appending one additional derivation step, according to the wildcard type (hardened or normal)
Sourcepub fn is_deriveable(&self) -> bool
pub fn is_deriveable(&self) -> bool
Whether or not the key has a wildcards
Sourcepub fn derive(self, index: u32) -> DescriptorPublicKey
pub fn derive(self, index: u32) -> DescriptorPublicKey
If this public key has a wildcard, replace it by the given index
Panics if given an index ≥ 2^31
Sourcepub fn derive_public_key<C: Verification>(
&self,
secp: &Secp256k1<C>,
) -> Result<PublicKey, ConversionError>
pub fn derive_public_key<C: Verification>( &self, secp: &Secp256k1<C>, ) -> Result<PublicKey, ConversionError>
Computes the public key corresponding to this descriptor key.
When deriving from an XOnlyPublicKey, it adds the default 0x02 y-coordinate
and returns the obtained full bitcoin::PublicKey
. All BIP32 derivations
always return a compressed key
Will return an error if the descriptor key has any hardened derivation steps in its path, or if the key has any wildcards.
To ensure there are no wildcards, call .derive(0)
or similar;
to avoid hardened derivation steps, start from a DescriptorSecretKey
and call as_public
, or call TranslatePk2::translate_pk2
with
some function which has access to secret key data.
Examples found in repository?
23fn main() {
24 // For deriving from descriptors, we need to provide a secp context
25 let secp_ctx = secp256k1::Secp256k1::verification_only();
26 // P2WSH and single xpubs
27 let addr_one = Descriptor::<DescriptorPublicKey>::from_str(
28 "wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH))",
29 )
30 .unwrap()
31 .translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
32 .unwrap()
33 .address(bitcoin::Network::Bitcoin).unwrap();
34
35 let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
36 "wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB))",
37 )
38 .unwrap()
39 .translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
40 .unwrap()
41 .address(bitcoin::Network::Bitcoin).unwrap();
42 let expected = bitcoin::Address::from_str(
43 "bc1qpq2cfgz5lktxzr5zqv7nrzz46hsvq3492ump9pz8rzcl8wqtwqcspx5y6a",
44 )
45 .unwrap();
46 assert_eq!(addr_one, expected);
47 assert_eq!(addr_two, expected);
48
49 // P2WSH-P2SH and ranged xpubs
50 let addr_one = Descriptor::<DescriptorPublicKey>::from_str(
51 "sh(wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*)))",
52 )
53 .unwrap()
54 .derived_descriptor(&secp_ctx, 5)
55 .unwrap()
56 .address(bitcoin::Network::Bitcoin).unwrap();
57
58 let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
59 "sh(wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*)))",
60 )
61 .unwrap()
62 .derived_descriptor(&secp_ctx, 5)
63 .unwrap()
64 .address(bitcoin::Network::Bitcoin).unwrap();
65 let expected = bitcoin::Address::from_str("325zcVBN5o2eqqqtGwPjmtDd8dJRyYP82s").unwrap();
66 assert_eq!(addr_one, expected);
67 assert_eq!(addr_two, expected);
68}
Trait Implementations§
Source§impl Clone for DescriptorPublicKey
impl Clone for DescriptorPublicKey
Source§fn clone(&self) -> DescriptorPublicKey
fn clone(&self) -> DescriptorPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more