Should be able to import an xpub descriptor to a privkey-enabled wallet if the wallet has the privkeys #27336

issue apoelstra openend this issue on March 27, 2023
  1. apoelstra commented at 0:02 am on March 27, 2023: contributor

    Please describe the feature you’d like to see added.

    If you have a privkey-enabled wallet, you should be able to import a public descriptor where your wallet knows the private keys corresponding to (some of) the xpubs in the descriptor.

    If you try to import a descriptor into a Core wallet that has private keys, and you only provide the public descriptor, it will fail with the error Cannot import descriptor without private keys to a wallet with private keys enabled. To do the import, you need to pull the private keys out of the wallet, populate the descriptor with them, recompute the checksum, then try again. This is unsafe and unnecessary.

    Describe the solution you’d like

    Before erroring out, the wallet should check whether it actually has private keys that would allow it to import the descriptor.

    Describe any alternatives you’ve considered

    No response

    Please leave any additional context

    No response

  2. apoelstra added the label Feature on Mar 27, 2023
  3. apoelstra commented at 0:06 am on March 27, 2023: contributor

    It looks like the wallet actually does the right thing already. The only fix needed is to delete the lines https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpc/backup.cpp#L1539-L1541 which cause the importdescriptors RPC to fail unnecessarily.

    Edit: Ah, no, it can do “the right thing” by recognizing balances, but it is unable to spend coins.

  4. apoelstra commented at 2:29 pm on March 27, 2023: contributor
    Feel free to close this – I’m not planning to work on it anytime soon and I think it implies a fairly large rearchitecture of the wallet. Basically, I would like if spkmans could share private keys.
  5. josibake commented at 7:12 am on March 28, 2023: member

    FWIW, I think this is a good idea. I recently ran into this when trying to create a fairly complicated miniscript fragment: I created the wallet with private keys enabled and copied out some of the xpubs to use in my wsh(miniscript) descriptor. I was then unable to import it into the wallet until I ran listdescriptors true and replaced the xpub with the xpriv before then re-importing.

    I agree that it’s dangerous to require dumping the xpriv to the command line. I suppose the counter-argument is the keys would ideally be on a signing device and you would only be creating a watch-only wallet in core, but I think there is merit to supporting a hot-wallet use case, as well.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me