How do Bitcoin Core descriptor wallets export private keys?

source刘教链·刘教链·23:40 编辑
How do Bitcoin Core descriptor wallets export private keys?

Last year 2024.6.23 teaching link article“Real or fake? Bitcoin Core doesn't support importing private keys?》This section explains how to import a BTC private key into Bitcoin Core's latest descriptor wallet (descriptor wallet) and related specific instructions. A friend asked some extended questions after reading it and made a brief addition to this article.


Question 1: Does the descriptor wallet support importing BIP39 mnemonics?


A: Not supported.


Although descriptor wallets support BIP32 hierarchical deterministic wallets, they do not support BIP39 mnemonics.


This is why the teaching chain is there“Liu Jiaochain's Super Little White Course”It is not recommended to use mnemonic words to create a cold wallet to store BTC; instead, it is one of the reasons to directly create and copy private keys. And even if it's a mnemonic, different software and hardware wallets may be implemented according to different specifications. As a result, the mnemonic words you created in the A software cannot be imported into the B software, or you get a completely different address after importing it, so you can't find the BTC you have stored.


Question 2: How do I create a descriptor wallet that supports private keys?


A: The latest version of Bitcoin Core won't automatically initialize your wallet. You'll need to use the command to create your own wallet. If the private key is disabled during creation, it will be created as a watch-only wallet (watch-only wallet), and the private key will not be disabled to create a standard wallet. The specific command is as follows:

$ bitcoin-cli -named createwallet wallet_name="testwallet" descriptors=true disable_private_keys=false


Note that disable_private_keys=false in the above command explicitly states that private keys are not disabled.


For added security, it's best to encrypt your wallet.

$ bitcoin-cli -rpcwallet=testwallet encryptwallet "你的本地加密密码"


Question 3: So, how do you export a private key describing an address in the wallet?


A: Very easy! Just show the descriptor directly. Specific instructions:

$ bitcoin-cli listdescriptors true{  "wallet_name": "testwallet",  "descriptors": [    {      "desc": "pkh(5KQ2upQdz2wPfYCT2MfXdgmqZKZtFPDmzm8ubXimR76pYMANUdM)#8rrz94h2",      "timestamp": 1753270055,      "active": false    },...


The result of the above command shows the 2024.6.23 teaching link article“Real or fake? Bitcoin Core doesn't support importing private keys?》The private key descriptor imported in. As you can see, Bitcoin Core neither encrypts nor hides the descriptors you imported, but rather shows them in their entirety.


Note the true parameter after the listdescriptors command, which indicates that the private key descriptor should be displayed. If you don't add this parameter, only the public key descriptor will be displayed, so you won't be able to see the private key.


Once we see the private key descriptor, we can use 2024.6.23 to teach the link article“Real or fake? Bitcoin Core doesn't support importing private keys?》Verify with getdescriptorinfo as described in:

$ bitcoin-cli getdescriptorinfo "pkh(5KQ2upQdz2wPfYCT2MfXdgmqZKZtFPDmzm8ubXimR76pYMANUdM)"{  "descriptor": "pkh(04e510bfa12225bbc2044a1847eda44a26e8a842cbf45c11d74ade893e506fc9e209c7c0044c5321ea22edf9dc1d8e45bed3663ed7c637eb564a7dd0a23ca8e45c)#afvrzgrk",  "checksum": "8rrz94h2",  "isrange": false,  "issolvable": true,  "hasprivatekeys": true}


The results aren't very intuitive; you can't see the BTC address corresponding to the private key descriptor. We also need to use the following command to view the corresponding address:


$ bitcoin-cli deriveaddresses "pkh(04e510bfa12225bbc2044a1847eda44a26e8a842cbf45c11d74ade893e506fc9e209c7c0044c5321ea22edf9dc1d8e45bed3663ed7c637eb564a7dd0a23ca8e45c)#afvrzgrk"[  "13cuZK94jvtCBPDoXd86MiiFTyMnQWkCS6"]


Note that the parameter given after the deriveaddresses command above is the public key descriptor in the execution result of the previous command.


At this point, we have enough confidence in the private key descriptor we initially obtained from the descriptor list and its corresponding address.


Isn't that easy? Ah, actually not! So the teaching chain is lazy; it actually uses electrum. This has already been mentioned in previous articles such as Hand Crushing Private Keys.


In addition, the instruction chain shown above is actually operated using Bitcoin Knots. Knots is a branch version of Core that adds some filtering and slimming features to help save resources needed to run nodes.


What, you still want to ask about the HD wallet address and private key? This post is too long. Let's save this more complicated and difficult topic for later!

Original Link
#刘教链
说明: All Bitpush articles reflect the author's views only and do not constitute investment advice.

Related

Loading...