Bitcoin Forum
April 16, 2024, 06:07:48 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [PATCH] dumpprivkey and importprivkey RPC commands  (Read 9316 times)
Pieter Wuille (OP)
Legendary
*
qt
Offline Offline

Activity: 1072
Merit: 1174


View Profile WWW
February 26, 2011, 06:24:14 PM
Last edit: June 14, 2011, 07:38:47 AM by Pieter Wuille
 #1

EDIT: this patch is for version 0.3.20 and isn't updated anymore. It is incorporated in my showwallet branch. See this thread for more information: http://forum.bitcoin.org/index.php?topic=3906.0

Hello all,

after working Hal's challenge to import a private key into a wallet last week, I created a patch for bitcoin which adds 2 new RPC commands:
* dumpprivkey <bitcoinaddress> reveals the private key corresponding to the given address (if known)
* importprivkey <bitcoinprivkey> adds a private key to the wallet.

See http://bitcoin.sipa.be/bitcoin-0.3.20-dumpprivkey.patch

The format is similar to that of addresses, but:
* contains the 256-bit private key instead of a 160-bit hash of a public key (resulting in 51-character strings)
* uses version byte 128 (239 for testnet) instead of 0 (111 for testnet)

This is not the same format as used by Hal initially (adds version number and checksum, but I think these are useful properties).

importprivkey will perform a rescan of the block chain after adding the key, to discover transactions based on it.
dumpprivkey does not delete a key from the wallet though, so it is not really intended as a way of moving funds from one client to another, but it's a first step towards making handling private keys more accessible.

I do Bitcoin stuff.
1713247668
Hero Member
*
Offline Offline

Posts: 1713247668

View Profile Personal Message (Offline)

Ignore
1713247668
Reply with quote  #2

1713247668
Report to moderator
The block chain is the main innovation of Bitcoin. It is the first distributed timestamping system.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713247668
Hero Member
*
Offline Offline

Posts: 1713247668

View Profile Personal Message (Offline)

Ignore
1713247668
Reply with quote  #2

1713247668
Report to moderator
1713247668
Hero Member
*
Offline Offline

Posts: 1713247668

View Profile Personal Message (Offline)

Ignore
1713247668
Reply with quote  #2

1713247668
Report to moderator
Cdecker
Hero Member
*****
Offline Offline

Activity: 489
Merit: 504



View Profile WWW
February 26, 2011, 07:26:32 PM
 #2

Looks promising to me, although I didn't test it yet. Looks clean ^^

+1 for inclusion

Want to see what developers are chatting about? http://bitcoinstats.com/irc/bitcoin-dev/logs/
Bitcoin-OTC Rating
Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652
Merit: 2216


Chief Scientist


View Profile WWW
February 26, 2011, 10:02:52 PM
 #3

What happens if:

-- you dump a private key from bitcoin client 'A'
-- shutdown A
-- import it into bitcoin client 'B'
-- spend it from B
 ... wait for a confirmation or three...
-- restart A

Does A notice that the coin's been spent?  I think there's a bug that it does not, and I think that bug needs to be fixed before we make it easy to export/import private keys.  So, please bang on sipa's patch and see if anything else breaks!

How often do you get the chance to work on a potentially world-changing project?
Binford 6100
Hero Member
*****
Offline Offline

Activity: 504
Merit: 500


PGP OTC WOT: EB7FCE3D


View Profile
February 26, 2011, 10:14:08 PM
 #4

What happens if:

-- you dump a private key from bitcoin client 'A'
-- shutdown A
-- import it into bitcoin client 'B'
-- spend it from B
 ... wait for a confirmation or three...
-- restart A

Does A notice that the coin's been spent?  I think there's a bug that it does not, and I think that bug needs to be fixed before we make it easy to export/import private keys.  So, please bang on sipa's patch and see if anything else breaks!

not yet intimately familiar with the way wallet & client work but after dumping the key from A & executing your scenario
the attempted spending from A would be rejected as double spending by the network.
wait, not rejected, there would be no key to sign the spending transaction

A wallet probably would not notice (guessing here, do not really know how the balance info is internaly managed)
but a rescan with next start would help. maybe adding a flag to wallet after dumping keys that would force rescan on restart could be accepted as workaround without having to rescan after each dump.

You can't build a reputation on what you are going to do.
Cdecker
Hero Member
*****
Offline Offline

Activity: 489
Merit: 504



View Profile WWW
February 27, 2011, 12:24:20 AM
 #5

Actually I think the default client will detect it. there was an early pool that used to split the gained coins directly in the generation block :-)

Want to see what developers are chatting about? http://bitcoinstats.com/irc/bitcoin-dev/logs/
Bitcoin-OTC Rating
Pieter Wuille (OP)
Legendary
*
qt
Offline Offline

Activity: 1072
Merit: 1174


View Profile WWW
February 27, 2011, 01:21:01 PM
 #6

Here are some (new) testnet coins to play with (thanks comboy) for those who have applied the patch: 93VYUMzRG9DdbRP72uQXjaWibbQwygnvaCu9DumcqDjGybD864T.

I do Bitcoin stuff.
Pieter Wuille (OP)
Legendary
*
qt
Offline Offline

Activity: 1072
Merit: 1174


View Profile WWW
March 07, 2011, 01:13:20 AM
 #7

What happens if:

-- you dump a private key from bitcoin client 'A'
-- shutdown A
-- import it into bitcoin client 'B'
-- spend it from B
 ... wait for a confirmation or three...
-- restart A

Does A notice that the coin's been spent?  I think there's a bug that it does not, and I think that bug needs to be fixed before we make it easy to export/import private keys.  So, please bang on sipa's patch and see if anything else breaks!

This was indeed not detected - incoming blocks and transactions were only checked for transactions to your own addresses, not from. Updated version of the patch fixes this as well: http://bitcoin.sipa.be/bitcoin-0.3.20.01-dumpprivkey.patch

PS: it also changes the unix makefile to use wx-config to find the locations of headers and libraries.  If necessary, i'll split this into separate patches.

I do Bitcoin stuff.
xf2_org
Member
**
Offline Offline

Activity: 98
Merit: 13


View Profile
May 12, 2011, 01:40:25 AM
 #8

Bump.  Let's make sure this is not forgotten.
forgotmypassword6x
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
May 12, 2011, 01:54:25 AM
 #9

what need is there for dumping private keys?
xf2_org
Member
**
Offline Offline

Activity: 98
Merit: 13


View Profile
May 12, 2011, 01:58:17 AM
 #10

what need is there for dumping private keys?

Implementing bitbills is one example.

Personally, I want to print out private keys and store them on paper, in a safety deposit box.

nelisky
Legendary
*
Offline Offline

Activity: 1540
Merit: 1001


View Profile
May 12, 2011, 01:41:23 PM
 #11

The only other thing this patch could do to make the thing complete is 'popkey', where the key is printed AND removed from wallet. I know it's kind of dangerous, maybe dump first would be required just to have some sanity check, but for bitbills it would make everything much simpler, no need for a new wallet for each bill, just address.

I do have other use cases in mind, like simple backup wallet creation on paper, that I can put in a safe box (which with the current patch I can already do) without all the stop client, move wallet, start client, new address, dump key, stop client, rm wallet, move old wallet back, start client... which is in itself very, very dangerous when undercaffeinated or overalcoholized Smiley
enmaku
Hero Member
*****
Offline Offline

Activity: 742
Merit: 500


View Profile
May 27, 2011, 06:25:30 PM
 #12

Did this get rolled into 0.3.21 and if not will the 0.3.20 patch still work?

Also, I'm assuming the .patch is linux-only which is fine for my home install, but I might want to export keys from the wallet on my work PC which (through no choice of my own) is a Win7 box. Anyone know if this is even possible in Windows at all?
nelisky
Legendary
*
Offline Offline

Activity: 1540
Merit: 1001


View Profile
May 27, 2011, 08:02:59 PM
 #13

Did this get rolled into 0.3.21 and if not will the 0.3.20 patch still work?

Also, I'm assuming the .patch is linux-only which is fine for my home install, but I might want to export keys from the wallet on my work PC which (through no choice of my own) is a Win7 box. Anyone know if this is even possible in Windows at all?

I don't think this got included yet, but you can use gnuwin on windows http://www.google.pt/url?sa=t&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F%2Fgnuwin32.sourceforge.net%2Fpackages%2Fpatch.htm&ei=LQPgTZOtF8-xhAezjtC_Cg&usg=AFQjCNF0DgIiBVNJjTXm07I_nySTN75Kzw or, for a prettier solution I think tortoisesvn had a tool iirc.
Pieter Wuille (OP)
Legendary
*
qt
Offline Offline

Activity: 1072
Merit: 1174


View Profile WWW
May 27, 2011, 10:01:52 PM
 #14

This patch is superceded by http://forum.bitcoin.org/index.php?topic=8091.0

It is not merged yet into mainline.

I do Bitcoin stuff.
gim
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
June 14, 2011, 01:09:22 AM
 #15

This patch is superceded by http://forum.bitcoin.org/index.php?topic=8091.0

It is not merged yet into mainline.


Ha! maybe you could edit your first post!
I've been following 3 full threads already to find this last link :-)
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!