Skip to content

Add public-key-only validation for wallet_name_from_descriptor#482

Open
AmosOO7 wants to merge 3 commits into
bitcoindevkit:masterfrom
AmosOO7:add_check_for_descriptors-wallet_name_from_descriptor
Open

Add public-key-only validation for wallet_name_from_descriptor#482
AmosOO7 wants to merge 3 commits into
bitcoindevkit:masterfrom
AmosOO7:add_check_for_descriptors-wallet_name_from_descriptor

Conversation

@AmosOO7
Copy link
Copy Markdown
Contributor

@AmosOO7 AmosOO7 commented May 11, 2026

Summary

  • Enforce that wallet_name_from_descriptor only accepts descriptors with public keys
  • Rejects descriptors whose parsed KeyMap contains private keys
  • Applies same validation to optional change descriptor
  • Adds a regression test for public and private descriptor handling

Testing

cargo test test_wallet_name_from_descriptor_public_key_check

Checklists

All Submissions:

Closes #481

AmosOO7 added 2 commits May 11, 2026 12:07
…_name_from_descriptor

- Add check that parsed KeyMap is empty after descriptor parsing
- Reject descriptors containing private keys with clear error message
- Apply validation to both main and change descriptors
- Add test_wallet_name_from_descriptor_public_key_check regression test

Resolves TODO comment in wallet_name_from_descriptor function.
Ensures wallet names are derived from public information only.
…_name_from_descriptor

- Add check that parsed KeyMap is empty after descriptor parsing
- Reject descriptors containing private keys with clear error message
- Apply validation to both main and change descriptors
- Add test_wallet_name_from_descriptor_public_key_check regression test

Resolves TODO comment in wallet_name_from_descriptor function.
Ensures wallet names are derived from public information only.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.91%. Comparing base (4b612f5) to head (7aaa1d3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #482      +/-   ##
==========================================
+ Coverage   80.30%   80.91%   +0.60%     
==========================================
  Files          24       24              
  Lines        5417     5469      +52     
  Branches      245      244       -1     
==========================================
+ Hits         4350     4425      +75     
+ Misses        989      967      -22     
+ Partials       78       77       -1     
Flag Coverage Δ
rust 80.91% <100.00%> (+0.60%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/wallet/mod.rs Outdated
.to_string();
let (descriptor, keymap) = descriptor.into_wallet_descriptor(secp, network_kind)?;
if !keymap.is_empty() {
return Err(DescriptorError::Miniscript(miniscript::Error::Unexpected(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since there are already dedicated variants for validation rules like this (HardenedDerivationXpub and ExternalAndInternalAreTheSame), would it make sense to add one here so callers can match on this condition without inspecting the message string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, after the comments from @ValuedMammal in #481, this will be removed entirely.

Comment thread src/wallet/mod.rs Outdated
assert!(result.is_ok());

// Test with empty descriptor
let public_empty = "";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test returns early at parse_descriptor before keymap.is_empty() is ever checked. It's testing parse error propagation, not the new check. Maybe clarify the comment to reflect that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, This will be removed entirely.

Copy link
Copy Markdown

@aagbotemi aagbotemi left a comment

Choose a reason for hiding this comment

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

Well done working on this @AmosOO7. The docs for wallet_name_from_descriptor look slightly stale.

Comment thread src/wallet/mod.rs Outdated
Err(DescriptorError::Miniscript(Unexpected(..)))
));
// Test with change descriptor containing public keys (should be ok)
let public_change_without_private = "wpkh([9a6a2580/84'/1'/0']tpubDDnGNapGEY6AZAdQbfRJgMg9fvz8pUBrLwvyvUqEgcUfgzM6zc2eVK4vY9x9L5FJWdX8WumXuLEDV5zDZnTfbn87vLe9XceCFwTu9so9Kks/1/*)";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a duplicate of public_change above, as they have same descriptor string. One can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, thanks

Comment thread src/wallet/mod.rs Outdated
@@ -2797,16 +2797,23 @@ where
T: IntoWalletDescriptor,
{
// TODO: check descriptors contains only public keys
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be removed now that the check is implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, nice catch

…or checksums

- Update `wallet_name_from_descriptor` to compute descriptor checksum explicitly
- Remove reliance on `to_string()` implicitly containing `#checksum`
- Clarify that wallet name is defined by public descriptor checksums
- Add regression test for equivalent xpub/xprv wallet names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Implement Public Key Check in wallet_name_from_descriptor

3 participants