decred / dcrdex

The Decred Decentralized Exchange (DEX), powered by atomic-swaps.
Other
182 stars 90 forks source link

client/asset/btc: enable descriptor wallets for bitcoin core v23 #1601

Closed chappjc closed 2 years ago

chappjc commented 2 years ago

Bitcoin Core v23 was tagged a few days ago, and it includes the ability to get private keys with descriptor wallets. However, this is not done with dumpprivkey, but via listdescriptors with the private option: https://github.com/decred/dcrdex/pull/1367

Of importance is that v23 also makes descriptor wallets by default: https://github.com/bitcoin/bitcoin/issues/20160 / https://github.com/bitcoin/bitcoin/pull/23002. As such, we should really support descriptor wallets.

I suspect it's more than just dumpprivkey that was the problem and there may be other RPCs that we'll have to deal with, but dumpprivkey was the showstopper at the last release.

Specification of "output script descriptors": https://github.com/bitcoin/bips/blob/master/bip-0380.mediawiki#key-expressions Unfortunately getaddressinfo does not similarly have a private option, or contain the key afaict.

chappjc commented 2 years ago

Spent a couple hours on this and I seem to have it worked out.

listdescriptors private=true is giving the wallet's actual master key (not just an account/branch extended key) followed by the path to the point where a range of addresses get derived (indicated by a *). e.g. tprv8Zg.../84'/1'/0'/0/*

getaddressinfo gives the full path to the address, where the master key from listdescriptors is represented by its fingerprint (first 4 bytes of hash160 of the public key). e.g. [b940190e/84'/1'/0'/0/0]

Everything agrees and I can both identify the master key from listdescriptors based on the finger print in getaddressinfo, and derive the address from the master key and path.

Assigning myself to make this happen for descriptor wallets in place of dumpprivkey.