Bitcoin Forum
May 05, 2024, 03:57:44 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Can armoryd export public keys.  (Read 719 times)
Crystal Ball (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
November 24, 2015, 09:05:36 PM
 #1

I feel like this must be incredibly simple, but for the life of me, I just can't seem to figure it out.

If I want to export a public key in the GUI client, I just open the corresponding wallet, right click on the address I want the key of, and click "copy public key (hex)", bam, there's my public key in uncompresed "04" hex format - dunno if that's the official name for it, just what I call it.

I can't seem to find the command to do this in the command line interface though. The only real hack I can think of, reading the source code, is to do:

Code:
dumpprivkey <address>
importprivkey <address>

Because apparently importing the private key is supposed to show you the corresponding public key at the same time. BUT... This obviously doesn't work in the case of a watching only wallet... You just get

Code:
{
    "Error": "An error occurred in dumpprivkey",
    "Error Type": "PrivateKeyNotFound",
    "Error Value": ""
}


I know it's got to be something simple, and it's really annoying me that I just can't see it.
1714881464
Hero Member
*
Offline Offline

Posts: 1714881464

View Profile Personal Message (Offline)

Ignore
1714881464
Reply with quote  #2

1714881464
Report to moderator
"Bitcoin: mining our own business since 2009" -- Pieter Wuille
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 24, 2015, 09:30:43 PM
 #2

AFAIK there is no way to do that. You would have to write your own code and add it to armoryd in order to have such a function.

Crystal Ball (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
November 24, 2015, 11:36:41 PM
 #3

OK, so upon learning that strangely, this command really isn't included, I've broken out a hex editor.

I made a backup of my backup wallet, and opened that. Searching through it for the ascii string of the address I want the key for - nothing.

So then I decided to search for the hex string of a public key I already know (because the GUI interface gave it to me). Predictably, it's there, so I decided to search around for the wallet format.

Here it is: https://bitcoinarmory.com/wallet-format/


So now it looks like my best bet is going to be to seek past all those bytes at the front of the file. Then from there, start looking for address entries.

...So if I don't get a byte value of 0x00, then seek to the 2 bytes that tells me how many bytes N is, then seek past that as well.

Each time I do get an address entry, seek past the first 156 bytes, then read 65 bytes, and also the 4 after it for the checksum. If the checksum passes OK, then hex decode the 130 bytes, that's my public key...


Then, using the method shown here:   https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses   if the address I create is the address I want the key for, then that's the key I want, if not keep searching through the file... Sheer laziness says if I've just created the address with getnewaddress, then it's likely to be the very last entry in the file, but tempted as I am, I'll avoid it because it's not guaranteed.


It sounds like quite a headache if I'm honest. So before I set about attempting to build that solution, does anyone have a better idea they'd like to share? Since Python's already not a language I'm familiar with, if I do take it on, I'll probably do it in C++ and then upload it in case anyone wants to translate it back into python.
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 24, 2015, 11:38:28 PM
 #4

I can probably add the function to armoryd for you. All of the functions are already included in the python code, it is just a matter of linking them to do what you want.

Crystal Ball (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
November 25, 2015, 12:01:40 AM
 #5

It'd be very nice if you would since it sounds like you have an idea of where in the code to look for what I'm trying so hard to find.

My searching for "pubkey", "publickey", "pub-key" and "pub_key" didn't seem to turn up many results except for importprivkey, createrawtransaction and createlockbox.

Even I can figure out, I'm not searching for the right word. I get this feeling I'm looking for one line out of several thousand, which is why it's so irritating. Without knowing the magic keyword I'm left with searching line by line...

achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 25, 2015, 12:48:52 AM
Last edit: November 25, 2015, 01:45:33 AM by knightdk
 #6

I wrote a patch, but I haven't tested it yet. You can get the full source at https://github.com/achow101/BitcoinArmory/tree/pubkey-dump. All you really need is the armoryd.py file from it and replace the one you already have.

edit: had to fix something. The latest version in that branch works. I tested it.

Crystal Ball (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
November 25, 2015, 12:00:59 PM
 #7

Thanks, I'll check it out now. It was last thing at night so I went to bed before you published it. Been up for 20 hours, drunk loads of caffeine -- not sleepy but absolutely shattered, I'm sure you know how it goes...


After testing it, it does work, so uh, have a beer or something. (As in, that mysterious address in your sidebar)



When I first tried it, it kept returning an error of "no private key". I didn't know why dumppubkey would say this, so I thought I'd have to go looking a little deeper. Then I had an idea...

Maybe there's something wrong the address I'm using. So, getnewaddress and then immediately dumppubkey on that... It worked! I think you know what my problem was... getactivewallet


Bam, wrong wallet. The address I'd used in the GUI was in my normal wallet, so I just had to call setactivewallet to the right one. Try the old address again and yep, there's my public key.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!