Author

Topic: export change addresses (Read 1771 times)

newbie
Activity: 1
Merit: 0
March 16, 2021, 07:12:01 AM
#10
Did you manage to export the change address private keys in the end? Just got here a few years later, and tried to export from Android Bitcoin Wallet. When I use the extracted seed or the extracted private keys and import into Electrum, I get all but one of the change addresses.
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 14, 2015, 01:37:32 AM
#9
Follow up, it seems that I didn't even have to use the wallet tool or the python program that btchris linked me to in order to extract the seed from the HD backup.  Good ol' tr was enough to do it (at least in one case that I tried).

Andreas' helpful instructions for recovery use `tr -cd' to print only the printable characters and delete the rest from a decrypted wallet (he then pipes this to awk and prints the first field to see if it's the java package name org.bitcoinj.production).  Well, if you leave off awk and put it into a file (or use less) you can look at the other printable characters in there pretty easily:

Code:
$ cat decrypted-wallet-backup | tr -cd [:print:] | less

Once I realized that this seed is in there in plaintext, it's pretty easy to find in your favorite hex editor (xxd) or even just opening the file with vi.

Thanks again for the great software (andreas) and the helpful resources (btchris)!  My next adventure will probably be generating keypairs from these seeds but for this I'll have to do a bit of reading on the HD algorithm (and possibly study the source from bitcoin wallet for android!).  So, I'll take that up in another thread if I get stuck.
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 02:07:27 PM
#8
However, it doesn't address the question I have about getting a hold of those private keys myself.  Perhaps I want to do something else with them like write them in blood on my wall, use them to dig CLAMS , etc, etc.

It's not possible to organize your own backup by just keeping private keys. As you found out yourself, each transaction would invalidate your backup because a new key is derived.

Instead, you'd use wallet-tool (and in future the app itself) to get your "seed phrase" (12 words) and write that in blood on your wall. Later, you can use wallet-tool (or again, in future the app) to restore from these 12 words. It's probably quite similar to what the Python tool does.

Yes, I understand.  However this is still working under the assumption that I'm trying to use this to "organize my own backup".  I completely trust that your program (alongside the bitcoinj/wallet-tool) takes care of all sane functionality here. But what if I just want to print these keys in ascii hex so that I can win a bet with my mate about how often the character "f" appears with respect to other characters?  I hope you understand my point.  You are, most reasonably, focusing on the end functionality that any sane user might be looking for from you/your program.  But I am not interested in the functionalities provided by the software, but on the principles of what I can or can't squeeze out of it.

I should emphasize that this thread has already been extremely enlightening for me.  Thank you both for engaging with me here.
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 01:33:46 PM
#7
Yes, this may be exactly what I want.  Is ver. 4.12 using an HD seed?

Yes, as of version 4.0, but please be aware that if you used to run a 3.x version and then upgraded to a 4.x version, your wallet and its backup will contain both HD keys and "loose" keys, the latter of which are not backed up by the seed.

EDIT: just began looking more closely at the program, seems it's a gui clicky thing.  I may indeed pull out the actual method here and set it up to run on the command line as it's what I'm more comfortable with.

If you run it as so, it prompt you for info in the terminal and will not do any GUI.
Code:
./decrypt_bitcoinj_seed.pyw bitcoinj-wallet-file

If you'd rather use it as a library, you can do something like this:
Code:
import decrypt_bitcoinj_seed

backup_password = '...'  # or None if you've already done the OpenSSL-style decryption
spending_pin    = '...'  # or None if there is no spending PIN

with wallet_file as open('bitcoinj-wallet-file', 'rb'):
    wallet = load_wallet(wallet_file, lambda arg_ignored: backup_password)

mnemonic = extract_mnemonic(wallet, lambda arg_ignored: spending_pin)
print mnemonic

Wonderful!

I haven't yet tried to run it, I've just been reading through the code for the moment.  Thanks a lot btchris!
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 01:31:33 PM
#6
As far as I can tell, backup/restore facility won't be helping me if my android device goes down and I don't have another android device to install your app on.  If I need to restore to another software solution, it seems that I'll be missing any bitcoins associated with the change addresses for which I can't get a private key from the backup.

In this case, take your backup and use it with these instructions: https://raw.githubusercontent.com/schildbach/bitcoin-wallet/master/wallet/README.recover

Yes, that is a helpful resource!

I understand that I can use wallet-tool to send all funds to another address.  This does address the scenario I mentioned above.

However, it doesn't address the question I have about getting a hold of those private keys myself.  Perhaps I want to do something else with them like write them in blood on my wall, use them to dig CLAMS , etc, etc.

It looks to me like the software bitchris linked me to will help me to get a hold of the HD seed and then, with a little study, I may be able to generate my public/private keypairs for my change addresses.

Thanks again Andreas for the cool software.  I really love it!
hero member
Activity: 672
Merit: 504
a.k.a. gurnec on GitHub
April 09, 2015, 01:31:07 PM
#5
Yes, this may be exactly what I want.  Is ver. 4.12 using an HD seed?

Yes, as of version 4.0, but please be aware that if you used to run a 3.x version and then upgraded to a 4.x version, your wallet and its backup will contain both HD keys and "loose" keys, the latter of which are not backed up by the seed.

EDIT: just began looking more closely at the program, seems it's a gui clicky thing.  I may indeed pull out the actual method here and set it up to run on the command line as it's what I'm more comfortable with.

If you run it as so, it prompt you for info in the terminal and will not do any GUI.
Code:
./decrypt_bitcoinj_seed.pyw bitcoinj-wallet-file

If you'd rather use it as a library, you can do something like this:
Code:
import decrypt_bitcoinj_seed

backup_password = '...'  # or None if you've already done the OpenSSL-style decryption
spending_pin    = '...'  # or None if there is no spending PIN

with wallet_file as open('bitcoinj-wallet-file', 'rb'):
    wallet = load_wallet(wallet_file, lambda arg_ignored: backup_password)

mnemonic = extract_mnemonic(wallet, lambda arg_ignored: spending_pin)
print mnemonic
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 12:41:55 PM
#4
Note: I reread andrea's earlier response and he said my question was best asked on bitcoinj, somehow I had read it as "has been asked".  I say this to explain my confusing response: "I'll search through the list for the resource you're referring to".  Smiley

Private keys are a wallet-internal thing. They are created and used on the fly. If you're trying to organize your own backup based on single private keys you will almost inevitably loose Bitcoins. This is one of the reasons why the app doesn't support key export. Use the backup/restore facility of the app!

As far as I can tell, backup/restore facility won't be helping me if my android device goes down and I don't have another android device to install your app on.  If I need to restore to another software solution, it seems that I'll be missing any bitcoins associated with the change addresses for which I can't get a private key from the backup.

In re "inevitably losing bitcoins", I take you at face value when you include the GPL v3 sections 15 and 16 "disclaimer of warranty" and "limitation of liability".  Therefore you have nothing to worry about and I'm responsible for my own actions (and my own bitcoins).  Nevertheless, I appreciate your friendly warning.  I have said this recently in another thread talking with btchris but I think it may bear repeating here: I like to take things apart to see how they work.  This is a fundamental part of how I learn.  I'm enjoying bitcoin software in this way, looking under the hood and experimenting and learning.  I don't keep any serious amounts of bitcoin in the wallets that I play with in this way. This is for my educational purposes only!

This is an open source tool that will extract the HD seed from a wallet backup file: https://github.com/gurnec/decrypt_bitcoinj_seed (please note that this tool is not endorsed by anyone.... but me -- and it's none too wise to download and run stuff like this from strangers).

Indeed but since it's a python script I can just look through the code myself before running anything (or reimplement it in my own way if any section seems fishy).

EDIT: just began looking more closely at the program, seems it's a gui clicky thing.  I may indeed pull out the actual method here and set it up to run on the command line as it's what I'm more comfortable with.

Quote
Given the seed, you can use tools such as this one to derive addresses and keys from it: https://dcpos.github.io/bip39/. Use the "Hive Wallet" derivation path for external addresses/keys. Use "BIP32" with a derivation path of "m/0'/1" for your internal/change addresses/keys.

You can also use the seed with a compatible wallet (MultiBit HD, Hive web or mobile, or breadwallet).


Yes, fun, thanks btchris.  I'll be checking this out and it sounds like what I'm looking for.  I'm just not really comfortable with using bitcoin addresses for change that I can't in some way get the privkeys of.

And thanks also Andreas, for your wonderfully useful, open-source android wallet.  I've been using it happily for several years now.
hero member
Activity: 672
Merit: 504
a.k.a. gurnec on GitHub
April 09, 2015, 11:23:09 AM
#3
What you probably will want is access to the HD seed (which is used to derive all the private keys).

This is an open source tool that will extract the HD seed from a wallet backup file: https://github.com/gurnec/decrypt_bitcoinj_seed (please note that this tool is not endorsed by anyone.... but me -- and it's none too wise to download and run stuff like this from strangers).

Given the seed, you can use tools such as this one to derive addresses and keys from it: https://dcpos.github.io/bip39/. Use the "Hive Wallet" derivation path for external addresses/keys. Use "BIP32" with a derivation path of "m/0'/1" for your internal/change addresses/keys.

You can also use the seed with a compatible wallet (MultiBit HD, Hive web or mobile, or breadwallet).

tspacepilot: I realize you know this already, but it's worth repeating for anyone else reading this... messing around with your seed and keys in such a manner is just asking for trouble / bitcoin loss. It's fine for educational purposes, but that's about it.
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 02:26:37 AM
#2
That question is best asked on the bitcoinj mailing list.

Ok, I'll search through that list and see if I can turn up what you're referring to.  Thanks!

Quote
I guess nobody is using that feature of wallet-tool the way you do. Note Bitcoin Wallet does not support key export at all.

Sad

So my private keys aren't mine?  They just belong to the memory of my phone somewhere but I should be able to see them and use them for myself?  That brings a little tear to my eye.

Seems like at least one terrible consequence is that if my phone crashes, I thought I could import the private keys that I've got out of my backup into some other client and save my bitcoins but wait, no, my bitcoins got sent to a change address that only belongs to my phone not to me.

If my keys are somewhere in my the memory of my phone there's gotta be some way to get them out.

Alternatively, can I send the bitcoins to myself at one of my "receiving" addresses where I do own the private key?  Maybe that would fix the connundrum of an an inaccessible change address.

Thanks again for any recommendations!
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
April 09, 2015, 01:41:20 AM
#1
I recently sent some btc from my bitcoin wallet for android but it wasn't the entire amount in the wallet.  I later happened to look on the blockchain and realized that the address that I expected to still have some BTC didn't have any!  OMG, am I hacked?  No, no, I look in my Bitcoin Wallet for Android and the expected balance is there.

This wallet only has two sending addresses in the address book.  When I look on the blockchain, I can see that the change address that was used is not one of these two addresses.  When I do the Safety --> Backup Wallet I can get an encrypted protobuf format wallet that I can dump the private keys out of with the wallet-tool of bitcoinj:

Code:
$ ./wallet-tool dump --dump-privkeys --wallet=/path/to/decrypted/protobuf/wallet

But the only keys dumped are the ones corresponding to the two "sending addresses".  The change addresses being used by the wallet don't seem to be in there.

What am I missing?  How can I get *all* the private keys from my wallet?
Jump to: