Bitcoin Forum

Other => Beginners & Help => Topic started by: DannyHamilton on June 25, 2012, 02:24:50 PM



Title: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 25, 2012, 02:24:50 PM
I tried searching, but all my attempts turned up advice about using bitcoind.  I don't see bitcoind on my computer (although perhaps I just don't know where to look).

I'm using OSX Lion, and running Bitcoin-Qt 0.6.2.2 with an encrypted wallet.

I'd like to identify what the private key is for one of my bitcoin addresses.  I'm guessing this is a simple thing to do, so I've posted my question here instead of "Technical Support". I'm sure this question has to have been asked before, so I apologize for asking a question that people are tired of answering.

Given a bitcoin address of ABC and an encryption password of XYZ, how would I go about finding the private key?

I'm aware that it isn't possible from the GUI, but was really hoping there was a way to do it from a command line.  I'm relatively fluent in BASH, KSH, PERL, AWK, SED so if there is a script that can help me, that would be fine as well.

Thanks in advance for any advice.


Title: Re: OSX Bitcoin-Qt private key
Post by: John (John K.) on June 25, 2012, 02:47:52 PM
Dump your keys from the wallet.dat file by using pywallet : https://bitcointalk.org/index.php?topic=34028.0 and running the command pywallet.py --dumpwallet  --password=PASSWORD

Bitcoind is not present on OSX.


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 04:18:25 PM
Ok, so if pywallet is the answer, then I guess my new question is: Can anyone help me get pywallet working in OSX Lion?

I understand that to run pywallet I need some libraries from MacPorts, and I understand the MacPorts website says that I'll also need Apple's Xcode Developer Tools.

I believe I've taken care of installing both, but when I try to run:

Quote
sudo port install python27 py27-twisted py27-pip py-bsddb python_select

I get the following error:

Quote
Error: Unable to open port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?

Any idea what I've done wrong?


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on June 27, 2012, 04:45:59 PM
See the following post: https://bitcointalk.org/index.php?topic=88477.msg974356#msg974356


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 05:03:20 PM
See the following post: https://bitcointalk.org/index.php?topic=88477.msg974356#msg974356

I was really hoping this was going to work.  It seemed so simple and useful.  Unfortunately, when I ran the curl command:
Quote
curl --user <user> --data-binary '{"method": "dumpprivkey", "params": ["<address>"] }' http://127.0.0.1:8332/
I got the following:
Quote
{"result":null,"error":{"code":-4,"message":"Private key for address <address> is not known"},"id":null}

Where <address> is a bitcoin address copied from Bitcoin-qt and pasted into the curl command, and <user> is the value I assigned to rpcuser in the bitcoin.conf


Title: Re: OSX Bitcoin-Qt private key
Post by: Rugatu on June 27, 2012, 05:18:19 PM
See the following post: https://bitcointalk.org/index.php?topic=88477.msg974356#msg974356

I was really hoping this was going to work.  It seemed so simple and useful.  Unfortunately, when I ran the curl command I got the following:

Quote
{"result":null,"error":{"code":-4,"message":"Private key for address <address> is not known"},"id":null}

Where <address> is a bitcoin address copied from Bitcoin-qt and pasted into the curl command.

If you got that far, is already working but probably you didn't format your command correctly. Try this one:

Code:
curl --user username --data-binary '{"method": "getinfo"}' http://127.0.0.1:8332/


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on June 27, 2012, 05:25:07 PM
Did you leave the quotation marks around the address? You should have left them there.

Example using the address I have on my signature, just replace it with yours.


Code:
curl --user <username> --data-binary '{"method": "dumpprivkey", "params": ["1PKyq6aMKcCwn8cmb9Jc5SkNydLsQb5n7K"] }' http://127.0.0.1:8332/

EDIT: I tried without the quotation marks and it gave me the following error, so that wasn't your problem.
Code:
{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

Are you sure you didn't paste a Bitcoin address taken from the Address Book, that is, a Bitcoin address that belongs to someone else and not to you?
Your addresses are listed on the "Receive Coins" separator only.


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 05:58:21 PM

If you got that far, is already working but probably you didn't format your command correctly. Try this one:

Code:
curl --user username --data-binary '{"method": "getinfo"}' http://127.0.0.1:8332/

Ok, this is promising. I get the following:

Code:
{"result":{"version":60300,"protocolversion":60001,"walletversion":40000,"balance":<xxxxxx>,"blocks":186513,"connections":8,"proxy":"","difficulty":1726566.55919348,"testnet":false,"keypoololdest":1330757976,"keypoolsize":101,"paytxfee":0.00000000,"unlocked_until":0,"errors":""},"error":null,"id":null}



Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 06:07:02 PM
Are you sure you didn't paste a Bitcoin address taken from the Address Book, that is, a Bitcoin address that belongs to someone else and not to you?
Your addresses are listed on the "Receive Coins" separator only.

Yes, I double checked the address and it definitely was correct, but here is another I just copied and pasted.  You can verify on the blockchain that it is a valid address since I received coins there in the past (although I suppose you have to take my word for it that I own the address and it is in my wallet)

Command copied from my terminal and pasted into this post:

Code:
curl --user testUser --data-binary '{"method": "dumpprivkey", "params": ["1GrEBzpFfquAk81zaHnL8pKHRRn3kGHhD5"] }' http://127.0.0.1:8332/

Result copied from my terminal and pasted into this post:

Code:
{"result":null,"error":{"code":-4,"message":"Private key for address 1GrEBzpFfquAk81zaHnL8pKHRRn3kGHhD5 is not known"},"id":null}


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 06:14:04 PM
Honestly, I'm surprised that the curl command would work without my encryption password.  That seems to me to be a serious security flaw if any malicious program could look up a password in bitcoin.conf and access the private keys in my wallet.  Are you sure there isn't a need to pass in the encryption password somehow?


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on June 27, 2012, 06:20:58 PM
Sign a message with that address, please. :P No need to take your word for it.
But looking at the blockchain.info page and seeing as it only received half a bitcent in there and never sent anything, it really is yours and not an address that happened to send you coins.

BTW, I was just joking about the message signing ;)

But I'm not joking about this: Your wallet is encrypted! You need to decrypt it before sending the commands :P
And given that there is no bitcoind on Mac I don't know of a way for you to do it on the Terminal.

This is the way to do it on linux:
Quote
Oh, you need to unencrypt your wallet temporarily so it can add the new key. I do the following, so my passphrase doesn't end up in my shell history. It unlocks the wallet for 60 seconds: read x; ./bitcoind walletpassphrase "$x" 60; unset x
From: http://bitcoin.stackexchange.com/questions/3530/how-to-import-a-private-key-to-an-encrypted-wallet-on-standard-client

Well, I guess it's time for you to figure out how to install pywallet ;D
You'll be able to give it the password to decrypt the wallet.


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 06:41:16 PM
Your wallet is encrypted! You need to decrypt it before sending the commands :P
Yep see my original post here:
I'm using OSX Lion, and running Bitcoin-Qt 0.6.2.2 with an encrypted wallet.

But one thing I can say: pywallet will also not work on an encrypted wallet. Well, at least not before you decrypt it.

So this post in this thread was wrong/misleading?

Dump your keys from the wallet.dat file by using pywallet : https://bitcointalk.org/index.php?topic=34028.0 and running the command pywallet.py --dumpwallet  --password=PASSWORD

I took that to mean that pywallet would accept a PASSWORD parameter on the command line that would decrypt the private key in the wallet?

Nevermind, I see you already mentioned that.  So back to my question...


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 06:43:49 PM
Ok, so if pywallet is the answer, then I guess my new question is: Can anyone help me get pywallet working in OSX Lion?

I understand that to run pywallet I need some libraries from MacPorts, and I understand the MacPorts website says that I'll also need Apple's Xcode Developer Tools.

I believe I've taken care of installing both, but when I try to run:

Quote
sudo port install python27 py27-twisted py27-pip py-bsddb python_select

I get the following error:

Quote
Error: Unable to open port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?

Any idea what I've done wrong?


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on June 27, 2012, 06:50:01 PM
Try this:
Code:
curl --user testUser --data-binary '{"method": "walletpassphrase", "params": ["<passphrase>", 120] }' http://127.0.0.1:8332/
replacing <passphrase> with your walletpassphrase

and next
Code:
curl --user testUser --data-binary '{"method": "dumpprivkey", "params": ["1GrEBzpFfquAk81zaHnL8pKHRRn3kGHhD5"] }' http://127.0.0.1:8332/

When done,
Code:
curl --user testUser --data-binary '{"method": "walletlock"}' http://127.0.0.1:8332/
To lock the wallet again with the passphrase as it seems the timeout doesn't work quite well when unlocking, so better safe than sorry.

After all that you may wish to delete your terminal history or else the passphrase will be left in there.
http://www.mactricksandtips.com/2012/01/clear-terminal-history.html


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on June 27, 2012, 07:04:48 PM
Good news and bad news.

Good news first.  It WORKED!  Hurray! Thanks so much for your help.

Bad news.  Even though it worked, I got odd results.

First to keep my password out of the terminal history I tried:
Code:
read x; curl --user testUser --data-binary '{"method": "walletpassphrase", "params": ["$x", "120"] }' http://127.0.0.1:8332/; unset x
and got
Code:
{"result":null,"error":{"code":-14,"message":"Error: The wallet passphrase entered was incorrect."},"id":null}
Even though I could see my passphrase where I typed it, and it was correct.

So then I tried:
Code:
curl --user testUser --data-binary '{"method": "walletpassphrase", "params": ["<passphrase>", "120"] }' http://127.0.0.1:8332/
Using my actual passphrase in place of <passphrase>, and I got
Code:
{"result":null,"error":{"code":-1,"message":"value is type str, expected int"},"id":null}

The only string I saw in the command where an INT might be expected was the "120", so I tried:
Code:
curl --user testUser --data-binary '{"method": "walletpassphrase", "params": ["<passphrase>", 120] }' http://127.0.0.1:8332/
And this time, oddly enough, I got
Code:
{"result":null,"error":{"code":-17,"message":"Error: Wallet is already unlocked."},"id":null}
???

So my best guess is that when I got the
Code:
{"code":-1,"message":"value is type str, expected int"}
error, it must have unlocked the wallet anyhow and just not set any timeout, because the "dumpprivkey" then worked.

Thanks again for all your help!  Hopefully this thread will be useful for many other OSX users.


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on June 27, 2012, 07:18:20 PM
OK, glad it worked.
Edited my post to insert the correct command, as not to confuse anyone else ;)


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on September 17, 2012, 03:45:25 PM
See the following post: https://bitcointalk.org/index.php?topic=88477.msg974356#msg974356
Anyone have any ideas?
I don't, but if you get this resolved, please post your resolution back here. I'll avoid upgrading to Mountain Lion until I'm sure this is going to work.


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on September 17, 2012, 05:31:34 PM
See the following post: https://bitcointalk.org/index.php?topic=88477.msg974356#msg974356
Anyone have any ideas?
I don't, but if you get this resolved, please post your resolution back here. I'll avoid upgrading to Mountain Lion until I'm sure this is going to work.

Bitcoin-Qt has worked fine on 10.8 for me.
It just crashes after I manually added the optional bitcoin.conf file so I can get pywallet working.

You don't need and you shouldn't have bitcoin running when messing with the wallet.dat using pywallet. ???
Not sure what you're trying to do, but you're not doing it right.


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on September 17, 2012, 05:48:56 PM
That's not to use pywallet. That's to use bitcoin-qt in server mode and pass it the commands using curl because there is no bitcoind for Mac.

Those instructions I gave to that other user were for him to avoid installing pywallet as he was having trouble installing it.


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on September 17, 2012, 05:58:53 PM
Then you are out of luck it seems. Can't install pywallet and bitcoin-qt doesn't work with a config file...

Is the config file text encoding UTF-8? I know for a fact Mac's like to fuck up text files with odd encodings. lol


Title: Re: OSX Bitcoin-Qt private key
Post by: DannyHamilton on September 17, 2012, 07:03:47 PM
Then you are out of luck it seems. Can't install pywallet and bitcoin-qt doesn't work with a config file...

Is the config file text encoding UTF-8? I know for a fact Mac's like to fuck up text files with odd encodings. lol
I converted it to plain text, then changed the extension to .conf and the command went though perfectly.
Glad to hear it.  If I'm understanding correctly, bitcoin-qt will run properly with a .conf file in Mountain Lion? So it is safe for me to upgrade (at least regarding this particular issue).


Title: Re: OSX Bitcoin-Qt private key
Post by: Raoul Duke on September 17, 2012, 07:21:06 PM
Then you are out of luck it seems. Can't install pywallet and bitcoin-qt doesn't work with a config file...

Is the config file text encoding UTF-8? I know for a fact Mac's like to fuck up text files with odd encodings. lol
I converted it to plain text, then changed the extension to .conf and the command went though perfectly.
Glad to hear it.  If I'm understanding correctly, bitcoin-qt will run properly with a .conf file in Mountain Lion? So it is safe for me to upgrade (at least regarding this particular issue).

Yes, as long as it is a real text file with a .conf extension. He had a .rtf file, which is a binary file, hence why Bitcoin-qt crashed.