Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: ironfeast on October 11, 2018, 05:57:17 PM



Title: Messy Private Keys Dump
Post by: ironfeast on October 11, 2018, 05:57:17 PM
Hi there,

Could anyone explain me how to export and import bitcoin's private keys in bitcoin core. I have exported private keys, it's a text file and have something like:

# Wallet dump created by Bitcoin v0.16.0
# * Created on 2018-10-08T10:01:00Z
# * Best block at time of backup was 544879 (00000000000000000010c6fe1edd3f236745b6af51929969bdaba2d59200dcc5),
#   mined on 2018-10-08T09:51:59Z

 "# extended private masterkey: <some long key>"
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/0'/699'
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/1'/947'
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/0'/86

This is a long list which goes on about four thosand lines. Then I see:

<Some Random Text(Not sure if it's a key)> 0 script=1 # addr=<some address>
<Some Random Text(Not sure if it's a key)> 0 script=1 # addr=<some address>

This goes till some eight thousand lines and the file end with # End of dump

Please help to understand all this messy thing.




Title: Re: Messy Private Keys Dump
Post by: AdolfinWolf on October 11, 2018, 06:24:49 PM
I don't think you're able to derive adresses in Bitcoin core itself from an (outside) XPRIV key. You'll need to use another library to do so.

See:
https://bitcoin.stackexchange.com/questions/52384/how-to-restore-bitcoin-core-hd-wallet-private-keys-by-master-key

Which lists this as a tool to do so; https://github.com/prusnak/bip32utils, but this tool is no longer available or has since moved. This should work aswell? https://iancoleman.io/bip39/
(https://github.com/iancoleman/bip39) (Always make sure you're running this safely!)

I haven't exactly tried it so i could be wrong.


You can then obviously import all your private keys generated with such a tool using

Code:
importprivkey

A more detailed guide can be found here:
https://bitcoin.stackexchange.com/questions/5941/how-do-i-import-a-private-key-into-bitcoin-core

Quote
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/0'/699'
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/1'/947'
<some key> 2018-04-26T17:08:10Z change=1 # addr=<some address> hdkeypath=m/0'/0'/86

The <some key> should be importable, (as i presume this is a "change" adress.) Try using above method to import these and see if it works.

I'm not exactly an expert on Bitcoin Core, but the

Quote
<Some Random Text(Not sure if it's a key)> 0 script=1 # addr=<some address>
Doesn't seem right, and is not something i've seen before.


Title: Re: Messy Private Keys Dump
Post by: Abdussamad on October 12, 2018, 04:36:56 PM
- If you're looking to import the private keys into different wallet software NOW then <some key> is what you want to import/sweep. You can ignore the rest.

- If you're looking to save this dump file for import years later then just don't. Instead use the backup wallet file option in the file menu of bitcoin core.


Title: Re: Messy Private Keys Dump
Post by: Thirdspace on October 13, 2018, 12:05:07 PM
Please help to understand all this messy thing.
that's why it's called wallet dump :D
basically each line represents info of a specific bitcoin address
<private-key-WIF> <creation-date> <label/reserve/change> # addr=<bitcoin-address> hdkeypath=<derivation-path>

Could anyone explain me how to export and import bitcoin's private keys in bitcoin core.
depending on your intentions, there are a few dos and don'ts on exporting/importing keys
and there are a few commands that you can use:
dumpprivkey (https://bitcoin.org/en/developer-reference#dumpprivkey): exports single private key of an address
dumpwallet (https://bitcoin.org/en/developer-reference#dumpwallet): exports all private keys to a file in wallet dump file format
importprivkey (https://bitcoin.org/en/developer-reference#importprivkey): imports single key into bitcoin core  
importaddress (https://bitcoin.org/en/developer-reference#importaddress): imports a watch-only address
importwallet (https://bitcoin.org/en/developer-reference#importwallet): imports private keys from a file in wallet dump file format

tell us your specific intention, so we can give you advise on how to do it properly and safely ;)


Title: Re: Messy Private Keys Dump
Post by: WelderInChief on August 09, 2019, 05:15:26 PM
- If you're looking to import the private keys into different wallet software NOW then <some key> is what you want to import/sweep. You can ignore the rest.

- If you're looking to save this dump file for import years later then just don't. Instead use the backup wallet file option in the file menu of bitcoin core.

Why not just backup the "extended private masterkey" for use years later? It would certainly be easier to write it down on paper or metal than each individual private key (assuming you are using many private keys from the same extended private masterkey so to break up your balance for privacy)?

Is it because you can't currently import it into bitcoin core and might need to use another app? It seems that this would give you all the benefits of bip39 without the downsides.


Title: Re: Messy Private Keys Dump
Post by: Abdussamad on August 09, 2019, 06:31:46 PM
- If you're looking to import the private keys into different wallet software NOW then <some key> is what you want to import/sweep. You can ignore the rest.

- If you're looking to save this dump file for import years later then just don't. Instead use the backup wallet file option in the file menu of bitcoin core.

Why not just backup the "extended private masterkey" for use years later? It would certainly be easier to write it down on paper or metal than each individual private key (assuming you are using many private keys from the same extended private masterkey so to break up your balance for privacy)?

Is it because you can't currently import it into bitcoin core and might need to use another app? It seems that this would give you all the benefits of bip39 without the downsides.

The xprv doesn't include all the information you need to restore the wallet. It doesn't tell you what derivation path was used or what script types were used i.e. whether you created p2pkh, p2wpkh etc. addresses. It doesn't tell you how many addresses you generated. And if you used addresses from imported private keys or pre-HD bitcoin core then those private keys can't be restored using the xprv.


Title: Re: Messy Private Keys Dump
Post by: WelderInChief on August 10, 2019, 08:16:17 PM
I get that it wouldn't include the imported keys, but if the software can't figure out those other details from the xpriv then how can it be used to. migrate to another wallet today? Is it because the new wallet makes some educated guesses that are probably correct, but might not be, but you still have the old wallet software in that edge case?



Title: Re: Messy Private Keys Dump
Post by: bob123 on August 11, 2019, 11:55:57 AM
I get that it wouldn't include the imported keys, but if the software can't figure out those other details from the xpriv then how can it be used to. migrate to another wallet today? Is it because the new wallet makes some educated guesses that are probably correct, but might not be, but you still have the old wallet software in that edge case?

It is because there are standards on how to derive private keys (i.e. which derivation path to use for which address type).
This data is stored in wallet files. The xpriv itself is only used to derive the private keys.

BIP32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and BIP44 (https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki) define the standard to derive private keys for different 'accounts' or coins. Following the standardization you will be able to derive your needed keys using your xpriv.


Title: Re: Messy Private Keys Dump
Post by: legendster on August 11, 2019, 08:00:48 PM
I've worked with masternode coins and in most of them you could just point to the dump file location and it parses the information on its own in the console.
So maybe mention where exactly you are trying to import and maybe you could get better responses here that way.


Title: Re: Messy Private Keys Dump
Post by: pooya87 on August 12, 2019, 03:22:10 AM
I get that it wouldn't include the imported keys, but if the software can't figure out those other details from the xpriv then how can it be used to. migrate to another wallet today? Is it because the new wallet makes some educated guesses that are probably correct, but might not be, but you still have the old wallet software in that edge case?

It is because there are standards on how to derive private keys (i.e. which derivation path to use for which address type).
This data is stored in wallet files. The xpriv itself is only used to derive the private keys.

BIP32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and BIP44 (https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki) define the standard to derive private keys for different 'accounts' or coins. Following the standardization you will be able to derive your needed keys using your xpriv.

actually BIPs aren't exactly "standards", they are more like suggestions which is why most wallets are not compatible with each other specially when it comes to BIP39 (mnemonic) and also choice of paths for BIP32.
so it is best, when you make a backup, you also write down the wallet name you used, the version of the wallet you used to create the data you are backing up and possibly if you knew anything more about their derivation paths or at least your address(es).


Title: Re: Messy Private Keys Dump
Post by: Abdussamad on August 12, 2019, 07:01:55 PM
BIP32 (https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and BIP44 (https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki) define the standard to derive private keys for different 'accounts' or coins. Following the standardization you will be able to derive your needed keys using your xpriv.

Bitcoin core doesn't use bip44.

I get that it wouldn't include the imported keys, but if the software can't figure out those other details from the xpriv then how can it be used to. migrate to another wallet today? Is it because the new wallet makes some educated guesses that are probably correct, but might not be, but you still have the old wallet software in that edge case?

Using an xpriv backup with the same wallet software i.e. bitcoin core is hard to do. So if it's hard to do it with the same software it's even harder with a different one. For example I know of no software that uses the same derivation path as bitcoin core.