feat: implement xpub network consistency check#848
Merged
apoelstra merged 1 commit intoAug 1, 2025
Conversation
Member
|
Nice! In general we prefer the detailed messages to be on both the PR description and the commit message. For a single-commit PR it's fine. (And you could've reduced the detail, but everything here is somewhat informative even if it's wordy and has a bunch of unnecessary headings.) |
Contributor
Author
|
Noted! Thanks for reviewing & testing |
heap-coder
added a commit
to heap-coder/rust-miniscript
that referenced
this pull request
Sep 27, 2025
…consistency check
497e9943d766eaeae70f57e27514c8310d03775c feat: implement xpub network consistency check (nahem)
Pull request description:
## Description
This PR addresses issue #844 by implementing a network consistency check for extended public keys (xpubs) in descriptors. The change introduces an `XKeyNetwork` enum and a `xkey_network()` method on `Descriptor<DescriptorPublicKey>` and `Descriptor<DefiniteDescriptorKey>` to:
- Detect the presence of xpubs.
- Identify if they belong to a single network (e.g., mainnet or testnet).
- Flag cases where xpubs have mixed networks, which could lead to unsafe usage (e.g., sending mainnet funds to testnet addresses).
The implementation iterates over keys to determine consistency, returning `XKeyNetwork::NoXKeys`, `XKeyNetwork::Mixed`, or `XKeyNetwork::Single(Network)`.
## Changes
- Added `XKeyNetwork` enum to represent network states.
- Implemented `xkey_network()` method.
## Testing
- Added unit tests to verify behavior with single-network, mixed-network, and no-xpub descriptors.
- Tested against existing descriptor examples to ensure compatibility.
## Notes
- This is a safety feature and does not enforce network consistency at parse time by default.
## Related Issues
- Closes #844
ACKs for top commit:
apoelstra:
ACK 497e9943d766eaeae70f57e27514c8310d03775c; successfully ran local tests
Tree-SHA512: 5e4aa1ecf63201b45e4f8003427cfb7c178074416dcbe79d9cc39fca5e327a48c74f10d1daaad1ad8fbc99a09e7e76f30867a29bb111a0ced0db907ba73f69c6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses issue #844 by implementing a network consistency check for extended public keys (xpubs) in descriptors. The change introduces an
XKeyNetworkenum and axkey_network()method onDescriptor<DescriptorPublicKey>andDescriptor<DefiniteDescriptorKey>to:The implementation iterates over keys to determine consistency, returning
XKeyNetwork::NoXKeys,XKeyNetwork::Mixed, orXKeyNetwork::Single(Network).Changes
XKeyNetworkenum to represent network states.xkey_network()method.Testing
Notes
Related Issues
DescriptorPublicKeyandDefiniteDescriptorKey#844