Skip to content

fix(wallet_policy): apply template derivation in into_descriptor - #1018

Merged
apoelstra merged 1 commit into
rust-bitcoin:masterfrom
trevarj:fix/wallet-policy-template-derivation
Aug 11, 2026
Merged

fix(wallet_policy): apply template derivation in into_descriptor#1018
apoelstra merged 1 commit into
rust-bitcoin:masterfrom
trevarj:fix/wallet-policy-template-derivation

Conversation

@trevarj

@trevarj trevarj commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

BIP-388 key information items are bare KEY expressions and the derivation
comes from the template's key placeholders, but the translator returned the
key information item verbatim, so wpkh(@0/**) materialized as wpkh(xpub...)
instead of wpkh(xpub.../<0;1>/*).

  • take the derivation path and wildcard from the placeholder when
    materializing a descriptor key
  • reject a key information item that is not an extended key, since there is
    nothing to append a derivation to

Fixes #1014

BIP-388 key information items are bare KEY expressions and the derivation
comes from the template's key placeholders, but the translator returned the
key information item verbatim, so wpkh(@0/**) materialized as wpkh(xpub...)
instead of wpkh(xpub.../<0;1>/*).

- take the derivation path and wildcard from the placeholder when
  materializing a descriptor key
- reject a key information item that is not an extended key, since there is
  nothing to append a derivation to

Fixes rust-bitcoin#1014
@trevarj

trevarj commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Reminder to cherry pick into #1009 (comment) once merged

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 00b8e80; successfully ran local tests

@milah-247

Copy link
Copy Markdown

I reproduced this locally to verify the fix.

Checked out fix/wallet-policy-template-derivation, ran cargo build (clean build, no errors), then ran the exact reproduction case from #1014:

let mut policy = WalletPolicy::from_str("wpkh(@0/**)").unwrap();
let key = DescriptorPublicKey::from_str(
    "[6738736c/84'/0'/0']xpub6CRQzb8u9dmMcq5XAwwRn9gcoYCjndJkhKgD11WKzbVGd932UmrExWFxCAvRnDN3ez6ZujLmMvmLBaSWdfWVn75L83Qxu1qSX4fJNrJg2Gt",
).unwrap();
policy.set_key_info(&[key]).unwrap();
println!("{:#}", policy.into_descriptor().unwrap());

Output:
wpkh([6738736c/84'/0'/0']xpub6CRQzb8u9dmMcq5XAwwRn9gcoYCjndJkhKgD11WKzbVGd932UmrExWFxCAvRnDN3ez6ZujLmMvmLBaSWdfWVn75L83Qxu1qSX4fJNrJg2Gt/<0;1>/*)

The /<0;1>/* derivation path is now correctly present, matching the expected behavior in #1014. Confirms the fix works as described.

@apoelstra
apoelstra merged commit ffedeba into rust-bitcoin:master Aug 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WalletPolicy::into_descriptor drops template derivation paths

3 participants