Skip to content

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Nov 18, 2021

Builds on top of #25907 and one commit from #22341.

First this PR introduces a descriptor wallet RPC addhdseed. Similar to its legacy wallet counterpart sethdseed it either generates a fresh random seed, for use on a blank wallet, or the user can provide a WIF. Unlike sethdseed this RPC call does not add keys / fill the keypool.

This allows a user to create a blank wallet (createwallet), provide it with a seed (addhdseed) and then craft custom descriptors. (An alternative approach would to add a nodescriptors argument to createwallet, but this RPC seems useful anyway)

An example use case of this is setting up a multisig between Core and a hardware wallet. After adding the seed to an otherwise empty wallet, the user would call getxpub m/87'/0'/0'. They would then combine this xpub and origin info with the one from their hardware wallet (e.g. using hwi --fingerprint .... getxpub m/87'/0'/0' and craft a descriptor like wsh(sorted_multi(2, [...../87'/0'/0']our_xpub, [..../87'/0'/0']their_xpub)), and import that. The resulting wallet will be able to sign its part of the transaction.

The second part of this PR enables to ability descriptors, such as in the multisig example above, in such a way that any fingerprint + xpub that is covered by our hd seed(s) can be signed for.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 18, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK Rspigler

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #bitcoin-core/gui/650 (Add Import to Wallet GUI by KolbyML)
  • #26627 (wallet: Migrate non-HD keys with single combo containing a list of keys by achow101)
  • #26596 (wallet: Migrate legacy wallets to descriptor wallets without requiring BDB by achow101)
  • #26573 (Wallet: don't underestimate the fees when spending a Taproot output by darosior)
  • #26567 (Wallet: estimate the size of signed inputs using descriptors by darosior)
  • #26462 (wallet: fix crash on loading descriptor wallet containing legacy key type entries by theStack)
  • #26008 (wallet: cache IsMine scriptPubKeys to improve performance of wallets with a lot of non-ranged descriptors by achow101)
  • #25991 (Wallet: Add foreign_outputs metadata to support CoinJoin transactions by luke-jr)
  • #25766 (wallet: Include a signature with encrypted keys to mitigate a wallet scam by achow101)
  • #25680 (rpc, docs: Add note for commands that supports only legacy wallets by yusufsahinhamza)
  • #24914 (wallet: Load database records in a particular order by achow101)
  • #24897 ([Draft / POC] Silent Payments by w0xlt)
  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)
  • #22341 (rpc: add getxpub by Sjors)

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.

@Rspigler
Copy link
Contributor

Concept ACK! Thanks for continuing this work

@Rspigler
Copy link
Contributor

So cool! 🚀

I tried testing this as far as I could.

First Node:

Created an empty wallet.

listdescriptors:

{
"wallet_name": "1",
"descriptors": [
]
}

✔️

addhdseed:

{
"fingerprint": "2aba6847"
}

getxpub "m/87'/0'/0'":

{
"xpub": "xpub6Bp9vBsEbMipghoCm7fnWbSvXc9gVyZS5Duzfc8WgrEEbCC8mDeg8YGHAtihrLg1XdjJT1qKYgM4Q7REz8B7zgoH6mWEHdMPDwMCihsbSgK",
"fingerprint": "2aba6847",
"origin": "[2aba6847/87'/0'/0']"
}

Now on to second node, since I don't have any HWW:

Created an empty wallet:

listdescriptors:

{
"wallet_name": "2",
"descriptors": [
]
}

✔️

addhdseed:

{
"fingerprint": "ad8a04e6"
}

getxpub "m/87'/0'/0'":

{
"xpub": "xpub6DR65ocDPDwTphuxNogrNSWWsmUnFEpBWjhZABGxupZ65st8kaSWVmFripasF8in6JELXPNPbjwyqE8s7dqiGSYyrE9k5UGDF4XQCSALkqi",
"fingerprint": "ad8a04e6",
"origin": "[ad8a04e6/87'/0'/0']"
}

Now back to first node, to combine into descriptor:

wsh(sorted_multi(2,[2aba6847/87'/0'/0']xpub6Bp9vBsEbMipghoCm7fnWbSvXc9gVyZS5Duzfc8WgrEEbCC8mDeg8YGHAtihrLg1XdjJT1qKYgM4Q7REz8B7zgoH6mWEHdMPDwMCihsbSgK,[ad8a04e6/87'/0'/0']xpub6DR65ocDPDwTphuxNogrNSWWsmUnFEpBWjhZABGxupZ65st8kaSWVmFripasF8in6JELXPNPbjwyqE8s7dqiGSYyrE9k5UGDF4XQCSALkqi))

I tried various formats/syntax for importdescriptors, but all failed. I'm sure it is something I did on my end. Can you help? For example:

importdescriptors '[{ "desc": "wsh(sorted_multi(2,[2aba6847/87'/0'/0']xpub6Bp9vBsEbMipghoCm7fnWbSvXc9gVyZS5Duzfc8WgrEEbCC8mDeg8YGHAtihrLg1XdjJT1qKYgM4Q7REz8B7zgoH6mWEHdMPDwMCihsbSgK,[ad8a04e6/87'/0'/0']xpub6DR65ocDPDwTphuxNogrNSWWsmUnFEpBWjhZABGxupZ65st8kaSWVmFripasF8in6JELXPNPbjwyqE8s7dqiGSYyrE9k5UGDF4XQCSALkqi))>", "timestamp":now, "internal": true }

@Sjors
Copy link
Member Author

Sjors commented Dec 23, 2021

@Rspigler in your examples the descriptors you importing are missing a derivation rule after the xpub, e.g. xpub.../0/* and they're missing a checksum (add a wrong one and it will tell you the right answers, e.g. #00000000). Also the > seems out of place.

Btw, you could try running the Trezor or ColdCard emulator, it'll work with HWI.

@Rspigler
Copy link
Contributor

Those were silly mistakes, sorry.

Tried this:

importdescriptors '[{ "desc": "wsh(sorted_multi(2,[3c9567fe/87'/0'/0'/0/*]xpub6DJT4N7LcSaLhKPSRkczg1nfD5z2wy1Kw48LAZHGTKDdWcjCc95wdRwQogYUX7M4fyzcXo3wQUrTH86RJ5w8cZ6T6nYdWe6guBN8SEBkPyD,[ad8a04e6/87'/0'/0'/0/*]xpub6DR65ocDPDwTphuxNogrNSWWsmUnFEpBWjhZABGxupZ65st8kaSWVmFripasF8in6JELXPNPbjwyqE8s7dqiGSYyrE9k5UGDF4XQCSALkqi))#00000000", "timestamp": now, "internal": "true" }]'

But still received Error: Error parsing JSON error code.

(The first descriptor is different because I re-compiled on Node 1)

@Sjors
Copy link
Member Author

Sjors commented Dec 28, 2021

That's still the wrong format. The final /0/* needs to be after the xpub. And "now" is missing quotes, whereas true should not be in quotes, which is probably what triggers the JSON parsing error. (I know it's tedious). You probably also want to set internal to false if you want to generate receive addresses (true is used for change addresses)

@Rspigler
Copy link
Contributor

Rspigler commented Jan 7, 2022

Thanks for being patient with me.

Still getting errors but will continue to work on this myself rather than crowd the PR.

achow101 and others added 12 commits October 17, 2022 10:58
Key management will be done entirely by KeyManager, so
DescriptorScriptPubKeyMan does not need key loading functions.
We will need access to a function that sets up a singular
DescriptorSPKM, so refactor this out of the multiple DescriptorSPKM
setup function.
Descriptor wallets store an HD master key that is used for new
automatically generated descriptors. sethdseed is an existing RPC that
can be repurposed to allow the users to set that HD key whenever they
want.

Also fixes the whitespace of sethdseed. Best to review this with
--ignore-all-space
@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 5, 2022

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 5, 2023

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 3, 2023

There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@Sjors
Copy link
Member Author

Sjors commented Aug 1, 2023

This is very out of date and it's not on my priority list at the moment. Happy to review if someone else takes it over.

@Sjors Sjors closed this Aug 1, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants