Repository navigation
wallet: Allow importing of descriptors without private keys when the wallet has the private keys - #35377
wallet: Allow importing of descriptors without private keys when the wallet has the private keys#35377achow101 wants to merge 4 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible typos and grammar issues:
2026-09-30 18:06:49 |
1250a06 to
2e6d8d0
Compare
|
Definite Concept ACK 2e6d8d0 because it allows the users to not deal with private keys manually. |
|
seems like a good idea, concept ACK Will review after #34861 is merged |
2e6d8d0 to
726006c
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
726006c to
53551be
Compare
53551be to
a0a1495
Compare
During the import process, the participant swaps their own key expression in the descriptor for the private one since importdescriptors reject a descriptor with no private keys when the wallet has private keys enabled. See bitcoin#35377
During the import process, the participant swaps their own key expression in the descriptor for the private one since importdescriptors reject a descriptor with no private keys when the wallet has private keys enabled. See bitcoin#35377
During the import process, the participant swaps their own key expression in the descriptor for the private one since importdescriptors reject a descriptor with no private keys when the wallet has private keys enabled. See bitcoin#35377
…criptors # Conflicts: # src/wallet/imports.cpp
polespinasa
left a comment
There was a problem hiding this comment.
did a first review, looks pretty good, I have a concept question/suggestion, left a comment below :)
| break; | ||
| } | ||
| } | ||
| if (derived.Neuter() != xpub_prov->m_root_extkey) continue; |
There was a problem hiding this comment.
in e59a2f2 descriptor: Implement SubstituteMasterExtPubs
Idk if what I am going to say makes sense but, shouldn't we only compare the pubkey? What if some metadata such as depth, fingerprint, etc. is missing (or is 0)? They key still a valid key but we would silently omit it.
Probably this with Core descriptors will not happen, but should we assume other wallets might miss this data?
There was a problem hiding this comment.
I think we want to be as specific as possible here to avoid any unexpected surprises. Given that changing any of the other fields in an xpub can drastically change how the xpub is encoded, I think it would be surprising to users if something very visually different to their private key magically gets a private key.
9f13f80 to
b58383a
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
The multisig tutorial runs every participant wallet on one online node, and the offline signing tutorial covers a single key. People who want both, an M-of-N multisig whose keys never touch a networked machine, have had to piece the procedure together from the two, or follow third-party guides that do. Add an "Offline Multisig" section to the offline signing tutorial that walks through the whole procedure with Bitcoin Core alone: - create the key wallets on the offline host (`addhdkey`), derive BIP 87 xpubs with `derivehdkey`, and build one `wsh(sortedmulti())` multipath descriptor, - import it into every key wallet so each can sign, and into a watch-only wallet for the online host, - back up each key with the watch-only wallet and the descriptor, and remove the keys from the offline host, - receive and spend, with the address and PSBT checks from the single-key part, - check every backup with one test deposit, by signing with each key and running `testmempoolaccept` on groups of M signatures, - recover from a lost online host or a lost backup, and handle key wallets that were asked to sign past their imported range. Two details are easy to get wrong offline, so they are called out: `"timestamp": "now"` means the best block's time, which is the genesis block on the offline node, and a pruned online node cannot restore the watch-only wallet once it has pruned blocks from after the wallet's timestamp. Importing an xpub-only descriptor into a key wallet that holds one of its keys depends on bitcoin#35377; on master without it the import fails with "Cannot import descriptor without private keys to a wallet with private keys enabled". Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019R9ppFkUwc5mTfpuBADAkX
|
Could turn into draft while CI is red? |
|
Tested b58383a: with the master key in the wallet, re-importing a descriptor the wallet already holds adds a duplicate. I computed 20 vectors with a separate BIP32 implementation and imported them on regtest. They cover hardened, unhardened and mixed origins, the master as origin, a wrong fingerprint, the right fingerprint with a wrong path, A wallet imports |
While we do our best to avoid importing duplicates, importing a duplicate is not world ending and this sort of duplication issue is one that we are not interested in solving. There are a variety of ways that a single descriptor can be textually represented and we cannot cover all cases where there may be duplication. |
b58383a to
7400986
Compare
SubstituteMasterExtPubs replaces Origin + BIP32 inside of a descriptor when a master xprv is provided that matches the origin and derives the BIP32 xpub.
When an imported descriptor contains pubkeys for which the wallet knows the private keys, substitute those pubkeys for the privkeys so that the descriptor can be imported. This allows such descriptors without private keys to be imported into wallets with private keys enabled.
Test that importdescriptors can import descriptors that don't have private keys, but the wallet already has the private key for them.
7400986 to
44a26c1
Compare

Currently importing a descriptor to a wallet that has private keys requires the descriptor to include the private keys. This is not ideal as it means exposing private key material. This PR makes it so that the wallet will lookup and substitute the private keys for their respective public keys in such descriptors, thus enabling importing of public descriptors into wallets with private keys.
The underlying mechanism is that the wallet retrieves all of the pubkeys from the descriptor and checks to see if any of them have private keys in any
ScriptPubKeyMan. Additionally, if the descriptor has a xpub with key origin info, we will check if any xprvs known to the wallet have a matching fingerprint and derive to the specified xpub. If so, the origin + xpub are replaced with the single xprv with the origin derivation path prepended to the key expression's derivation path.Possible future work is to allow the xpub substitution to work when the wallet has some child in the key origin, i.e. the wallet xprv has a key origin that is a prefix of the key origin specified for an xpub in the descriptor. Currently this kind of substitution is not being done, only root master xprvs will be substituted.
If a wallet does not have the private keys for a public descriptor, the import is still disallowed.
This PR is based on #34861 to avoid an annoying rebase.
Closes #27336