Addition of Import Private Key Menu #2050

pull n1bor wants to merge 5 commits into bitcoin:master from n1bor:importprivatekey changing 13 files +571 −4
  1. n1bor commented at 9:13 PM on November 28, 2012: none

    Does what it says on the tin. Has full validation of private key before trying to import. Includes logic to request passphrase if wallet is locked. Include progress bar when scanning transactions as can take a few mins.

    Motivation was to make it easier for people to import vanity addresses. I wrote bitcoinvanity.appspot.com and so want to make importing key easier for users.

    1st attempt at QT programming so could be improved I expect.

  2. Added menu and dialog for entering private key
    need to remove tick in menu and add space for comment with address
    also need to link up with actual command so it does something!
    6583dfa187
  3. first version with import working.
    Need more error checking and inform user of issues.
    7126850ae0
  4. added progress dialog for import of private key
    linked scanwalletfortransactions back to progess box
    1b75f64dbf
  5. changing progress to display number of blocks
    adding in code to unlock wallet if required
    7854a045d8
  6. Merge remote-tracking branch 'origin/master' into importprivatekey
    Conflicts:
    	src/qt/bitcoingui.cpp
    1e84f9794d
  7. BitcoinPullTester commented at 9:27 PM on November 28, 2012: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/1e84f9794d07e234344c71b177906b0b2dac543b for binaries and test log.

  8. luke-jr commented at 9:49 PM on November 28, 2012: member

    I don't think the importprivkey functionality should be exposed to normal users. It's really pretty dangerous. Instead, I would suggest implementing the sweepprivkey ("import" the key, flagged as "not part of my balance, but automatically move any funds seen to another address") functionality.

  9. sipa commented at 10:18 PM on November 28, 2012: member

    I'm not sure about this. It's a feature many people will like, and it certainly has legitimate uses. On the other hand, I don't like encouraging moving private keys around or vanity addresses...

  10. gavinandresen commented at 3:26 AM on November 29, 2012: contributor

    I don't like encouraging moving private keys around either. They're called "private" for a reason.

    I agree that "sweep" (and "sweep again if more coins are received on the swept address") is a much better way to go, and useful in more cases.

  11. laanwj commented at 6:25 AM on November 29, 2012: member

    What makes importing private keys so dangerous? I suppose it's because it is a kind of trojan horse:

    1. Other people could be spending coins from it. This is not a scenario currently supported by the client, and result in non-consisent internal administration (wrong balances, double spends, etc).
    2. The client could potentially use the key as change address, after which the other person that have the key can steal a large part of your coins.
    3. The user could accidentally use the public key associated to the private key as public bitcoin address, ask others to send to it, after which someone else can steal the coins like in 2.

    I suppose this could be worked around by marking the key as "foreign", not using it for change or showing the public key in the address book, and then either sweeping it or using it for spends only (while carefully monitoring other's transactions so that no double spends happen).

  12. robbak commented at 6:33 AM on November 29, 2012: contributor

    If people are importing private keys, then the private key is in two places. We'll have people emailing private keys too themselves, private keys on every other USB stick on the planet, and people posting angry bugs about bitcoin loosing their coins and you'd better compensate me!!!!!

    Private key is private. Two people can keep a secret if one of them is dead, and all that.

    On 29 November 2012 16:25, Wladimir J. van der Laan < notifications@github.com> wrote:

    What makes importing private keys so dangerous? I suppose it's because it is a kind of trojan horse:

    1. Other people could be spending coins from it. This is not a scenario currently supported by the client, and result in non-consisent internal administration (wrong balances, double spends, etc).
    2. The client could potentially use the key as change address, after which the other person that have the key can steal a large part of your coins.
    3. The user could accidentally use the public key associated to the private key as public bitcoin address, ask others to send to it, after which someone else can steal the coins like in 2.

    I suppose this could be worked around by marking the key as "foreign", not using it for change or showing the public key in the address book, and then either sweeping it or using it for spends only (while carefully monitoring other's transactions so that no double spends happen).

    — Reply to this email directly or view it on GitHubhttps://github.com/bitcoin/bitcoin/pull/2050#issuecomment-10836678.

  13. laanwj commented at 6:33 AM on November 29, 2012: member

    BTW your implementation looks very good, haven't looked in full detail, but on a high level you're doing everything as it's supposed it.

  14. in src/qt/bitcoingui.cpp:None in 1e84f9794d
     261 | @@ -260,6 +262,9 @@ void BitcoinGUI::createActions()
     262 |      encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
     263 |      encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
     264 |      encryptWalletAction->setCheckable(true);
     265 | +    importPrivateKeyAction = new QAction(QIcon(":/icons/key"), tr("&Import Private Key..."), this);
     266 | +    importPrivateKeyAction->setStatusTip(tr("Import private key into wallet."));
    


    Diapolo commented at 7:00 AM on November 29, 2012:

    Nit-pick: Can you please remove . at the end, to ensure all that status tip formats match.

  15. in src/qt/bitcoingui.cpp:None in 1e84f9794d
     853 | @@ -847,6 +854,8 @@ void BitcoinGUI::setEncryptionStatus(int status)
     854 |          encryptWalletAction->setChecked(false);
     855 |          changePassphraseAction->setEnabled(false);
     856 |          encryptWalletAction->setEnabled(true);
     857 | +
    


    Diapolo commented at 7:01 AM on November 29, 2012:

    Why 2 empty lines here and below again?

  16. in src/qt/importprivatekeydialog.cpp:None in 1e84f9794d
      42 | +    ui(new Ui::ImportPrivateKeyDialog)
      43 | +{
      44 | +    ui->setupUi(this);
      45 | +    QValidator *validator = new PrivateKeyValidator(this);
      46 | +    ui->privateKeyEdit1->setValidator(validator);
      47 | +    //QObject::connect(validator, SIGNAL(keyValidityChanged(bool)),
    


    Diapolo commented at 7:06 AM on November 29, 2012:

    Is this a left-over or a to-do?

  17. in src/qt/forms/progressdialog.ui:None in 1e84f9794d
       0 | @@ -0,0 +1,51 @@
       1 | +<?xml version="1.0" encoding="UTF-8"?>
    


    Diapolo commented at 7:08 AM on November 29, 2012:

    Would it be possible to use the status bar in the main window for this? So no need to invent a whole new class.


    laanwj commented at 7:11 AM on November 29, 2012:

    In principe it would be better, I thought about it too, but the problem is that the entire UI is held up during import, so it would probably only be confusing right now.


    Diapolo commented at 7:16 AM on November 29, 2012:

    Couldn't that import run in an own thread and just block usage of the status bar for other stuff, while doing that?


    laanwj commented at 7:31 AM on November 29, 2012:

    I'm sure it could, but that'd be a huge change to the core (and things like balance would be invalid for the duration of the rescan!), whereas this is a tractable UI feature addition. Even better would be to optimize adding keys so that a complete rescan is not needed (may be easier when the new wallet format arrives).

  18. Diapolo commented at 7:21 AM on November 29, 2012: none

    @n1bor I would like to only comment on some style stuff I saw. There are some places where you added unneeded line-breaks (2 in a row). I also think it's much nicer to use speaking names for GUI elements like labels and such (eg: transactionFeeLabel or okButton). Consider this feedback constructive and it's mostly nit-picking, but I'm known to have eagle eyes for such small things, sorry ;).

  19. n1bor commented at 8:09 AM on December 5, 2012: none

    Diapolo - thanks for comments happy to tidy them all up! Just not going to do till someone posts on here that they are going to merge the pull. As currently looks like the the consensus is against including this in the client.

  20. BitcoinPullTester commented at 7:10 AM on January 24, 2013: none

    Automatic sanity-testing: FAILED MERGE, see http://jenkins.bluematt.me/pull-tester/1e84f9794d07e234344c71b177906b0b2dac543b for test log.

    This pull does not merge cleanly onto current master

  21. luke-jr commented at 5:33 AM on April 8, 2013: member

    Please rebase.

  22. n1bor commented at 7:05 AM on April 8, 2013: none

    Luke - happy to rebase, but only if you are going to pull into client.

    Thought consensus was you did not want to encourage this sort of thing?

  23. sipa commented at 8:37 AM on April 8, 2013: member

    I'm personally much more in favor of exporting/importing entire wallets. It has much less risk for shooting yourself in the foot, and doesn't require micromanagement from the user. For that reason, it's something I also would object less against to put in the GUI. I intend to work on that soon.

  24. jgarzik commented at 6:43 PM on June 19, 2013: contributor

    Importing private keys really should include a sweep feature for safety. Creating a transaction immediately spending all coins associated with the imported key to a new address.

    It sounds like consensus is mixed, though I'm a bit more friendly to privkey importing than other devs. But I don't want us to leave the poor pull requestor in limbo. We should ACK the general direction or close this.

  25. sipa commented at 6:59 PM on June 19, 2013: member

    I'm in favor of closing this. It may make sense to have a feature like this that is accessible through an expert mode (coin control comes very close to that), but if made generally available, it would lead to even more misunderstanding about wallets.

    However, I wouldn't be opposed to having the functionality of #2592 accessible through the GUI. If a sweepprivkey gets implemented, that would seem safe as well.

  26. jgarzik closed this on Jun 19, 2013

  27. HashUnlimited referenced this in commit c5bb3fdec0 on May 11, 2018
  28. sidhujag referenced this in commit 2d578d5920 on Jul 13, 2018
  29. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 18:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me