Skip to content

at_derivation_index panics with "The key should not contain any wildcards at this point" #912

Description

@Velnbur

I accidentally found out that if you try to build a Descriptor with DescriptorXKey and hardened derivation path, the at_derivation_index panics with The key should not contain any wildcards at this point.

use bitcoin::{
    bip32::{ChildNumber, DerivationPath, Xpriv, Xpub},
    Network,
};
use miniscript::{
    descriptor::{DescriptorXKey, Wildcard},
    Descriptor, DescriptorPublicKey,
};

fn main() {
    let xpriv = Xpriv::new_master(Network::Regtest, &[1u8; 256]).unwrap();

    let desc =
        Descriptor::<DescriptorPublicKey>::new_pkh(DescriptorPublicKey::XPub(DescriptorXKey {
            origin: None,
            xkey: Xpub::from_priv(&secp256k1::Secp256k1::new(), &xpriv),
            derivation_path: DerivationPath::from_iter([ChildNumber::Hardened { index: 1 }]),
            wildcard: Wildcard::Unhardened,
        }))
        .unwrap();

    desc.at_derivation_index(1).unwrap(); // panics because of .expect() inside
}

It makes sense that the function "fails", because at this point at_derivation_index can't derive a descriptor, but the message seems internal and misleading regarding the true cause. I expected it to return an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions