Bitcoin Forum
April 20, 2014, 09:58:05 PM *
News: Due to the OpenSSL heartbleed bug, changing your forum password is recommended.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [PATCH] dumpprivkey and importprivkey RPC commands  (Read 5359 times)
Pieter Wuille
Hero Member
*****
qt
Offline Offline

Activity: 938


View Profile WWW

Ignore
February 26, 2011, 06:24:14 PM
 #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.

aka sipa, core dev team

Tips and donations: 1KwDYMJMS4xq3ZEWYfdBRwYG2fHwhZsipa
1398031085
Hero Member
*
Offline Offline

Posts: 1398031085

View Profile Personal Message (Offline)

Ignore
1398031085
Reply with quote  #2

1398031085
Report to moderator
1398031085
Hero Member
*
Offline Offline

Posts: 1398031085

View Profile Personal Message (Offline)

Ignore
1398031085
Reply with quote  #2

1398031085
Report to moderator
1398031085
Hero Member
*
Offline Offline

Posts: 1398031085

View Profile Personal Message (Offline)

Ignore
1398031085
Reply with quote  #2

1398031085
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1398031085
Hero Member
*
Offline Offline

Posts: 1398031085

View Profile Personal Message (Offline)

Ignore
1398031085
Reply with quote  #2

1398031085
Report to moderator
1398031085
Hero Member
*
Offline Offline

Posts: 1398031085

View Profile Personal Message (Offline)

Ignore
1398031085
Reply with quote  #2

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

Activity: 487



View Profile WWW

Ignore
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
Hero Member
*****
qt
Offline Offline

Activity: 1330


Chief Scientist


View Profile WWW

Ignore
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!

Will I see you in Amsterdam?
  http://bitcoin2014.com/
Binford 6100
Hero Member
*****
Offline Offline

Activity: 504


PGP OTC WOT: EB7FCE3D


View Profile

Ignore
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: 487



View Profile WWW

Ignore
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
Hero Member
*****
qt
Offline Offline

Activity: 938


View Profile WWW

Ignore
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.

aka sipa, core dev team

Tips and donations: 1KwDYMJMS4xq3ZEWYfdBRwYG2fHwhZsipa
Pieter Wuille
Hero Member
*****
qt
Offline Offline

Activity: 938


View Profile WWW

Ignore
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.

aka sipa, core dev team

Tips and donations: 1KwDYMJMS4xq3ZEWYfdBRwYG2fHwhZsipa
xf2_org
Member
**
Offline Offline

Activity: 70


View Profile WWW

Ignore
May 12, 2011, 01:40:25 AM
 #8

Bump.  Let's make sure this is not forgotten.

Jeff Garzik, bitcoin core dev team

Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
forgotmypassword6x
Newbie
*
Offline Offline

Activity: 8


View Profile

Ignore
May 12, 2011, 01:54:25 AM
 #9

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

Activity: 70


View Profile WWW

Ignore
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.


Jeff Garzik, bitcoin core dev team

Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
nelisky
Hero Member
*****
Offline Offline

Activity: 1218


View Profile

Ignore
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

we measure long periods of time in bitcoin blocks, and short ones in vodka tonics
DividendRippler  | DICEonCRACK | The Amazing Anonymous Bitcoin Lottery
enmaku
Hero Member
*****
Offline Offline

Activity: 728



View Profile WWW

Ignore
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
Hero Member
*****
Offline Offline

Activity: 1218


View Profile

Ignore
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.

we measure long periods of time in bitcoin blocks, and short ones in vodka tonics
DividendRippler  | DICEonCRACK | The Amazing Anonymous Bitcoin Lottery
Pieter Wuille
Hero Member
*****
qt
Offline Offline

Activity: 938


View Profile WWW

Ignore
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.

aka sipa, core dev team

Tips and donations: 1KwDYMJMS4xq3ZEWYfdBRwYG2fHwhZsipa
gim
Member
**
Offline Offline

Activity: 90


View Profile

Ignore
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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!