From b3f8338d56c1fcde218140f413797d87e46ae456 Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 13 Aug 2015 15:40:42 +0200 Subject: [PATCH 1/3] NewAccount ui --- alethzero/CMakeLists.txt | 15 ++- alethzero/NewAccount.cpp | 78 +++++++++++++ alethzero/NewAccount.h | 44 +++++++ alethzero/NewAccount.ui | 245 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 alethzero/NewAccount.cpp create mode 100644 alethzero/NewAccount.h create mode 100644 alethzero/NewAccount.ui diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 29bfed259..73061b38a 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -42,6 +42,7 @@ qt5_wrap_ui(ui_AllAccounts.h AllAccounts.ui) qt5_wrap_ui(ui_LogPanel.h LogPanel.ui) qt5_wrap_ui(ui_BrainWallet.h BrainWallet.ui) qt5_wrap_ui(ui_OtherAccounts.h OtherAccounts.ui) +qt5_wrap_ui(ui_NewAccount.h NewAccount.ui) file(GLOB HEADERS "*.h") @@ -54,7 +55,19 @@ endif () # eth_add_executable is defined in cmake/EthExecutableHelper.cmake eth_add_executable(${EXECUTABLE} ICON alethzero - UI_RESOURCES alethzero.icns Main.ui Connect.ui Debugger.ui Transact.ui ExportState.ui GetPassword.ui GasPricing.ui AllAccounts.ui LogPanel.ui BrainWallet.ui OtherAccounts.ui + UI_RESOURCES alethzero.icns + Main.ui + Connect.ui + Debugger.ui + Transact.ui + ExportState.ui + GetPassword.ui + GasPricing.ui + AllAccounts.ui + LogPanel.ui + BrainWallet.ui + OtherAccounts.ui + NewAccount.ui WIN_RESOURCES alethzero.rc ) diff --git a/alethzero/NewAccount.cpp b/alethzero/NewAccount.cpp new file mode 100644 index 000000000..dfa808e19 --- /dev/null +++ b/alethzero/NewAccount.cpp @@ -0,0 +1,78 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file NewAccount.h + * @author Gav Wood + * @date 2015 + */ + +#include "NewAccount.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "ui_NewAccount.h" +using namespace std; +using namespace dev; +using namespace az; +using namespace eth; + +DEV_AZ_NOTE_PLUGIN(NewAccount); + +NewAccount::NewAccount(MainFace* _m): + Plugin(_m, "NewAccount") +{ + connect(addMenuItem("New Account...", "menuTools", true), SIGNAL(triggered()), SLOT(create())); +} + +NewAccount::~NewAccount() +{ +} + +void NewAccount::create() +{ + QDialog d; + Ui_NewAccount u; + u.setupUi(&d); + d.setWindowTitle("New Account Wallet"); + u.enterHexText->setEnabled(false); + u.enterPasswordText->setEnabled(false); + u.enterPasswordAgainText->setEnabled(false); + enum { NoVanity = 0, DirectICAP, FirstTwo, FirstTwoNextTwo, FirstThree, FirstFour, StringMatch }; + + QStringList items = {"No vanity (instant)", "Direct ICAP address", "Two pairs first (a few seconds)", "Two pairs first and second (a few minutes)", "Three pairs first (a few minutes)", "Four pairs first (several hours)", "Specific hex string"}; + u.selectTypeComboBox->addItems(items); + + void (QComboBox:: *indexChangedSignal)(int) = &QComboBox::currentIndexChanged; + connect(u.selectTypeComboBox, indexChangedSignal, [&](int index) { + u.enterHexText->setEnabled(index == StringMatch); + }); + + connect(u.additionalCheckBox, &QCheckBox::clicked, [&]() { + bool checked = u.additionalCheckBox->checkState() == Qt::CheckState::Checked; + u.enterPasswordText->setEnabled(checked); + u.enterPasswordAgainText->setEnabled(checked); + }); + + if (d.exec() == QDialog::Accepted) + { + //main()->noteKeysChanged(); + } +} diff --git a/alethzero/NewAccount.h b/alethzero/NewAccount.h new file mode 100644 index 000000000..d1ba1b747 --- /dev/null +++ b/alethzero/NewAccount.h @@ -0,0 +1,44 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file NewAccount.h + * @author Gav Wood + * @date 2015 + */ + +#pragma once + +#include "MainFace.h" + +namespace dev +{ +namespace az +{ + +class NewAccount: public QObject, public Plugin +{ + Q_OBJECT + +public: + NewAccount(MainFace* _m); + ~NewAccount(); + +private slots: + void create(); +}; + +} +} diff --git a/alethzero/NewAccount.ui b/alethzero/NewAccount.ui new file mode 100644 index 000000000..48d463fd5 --- /dev/null +++ b/alethzero/NewAccount.ui @@ -0,0 +1,245 @@ + + + NewAccount + + + + 0 + 0 + 511 + 600 + + + + Dialog + + + + + + + 16777215 + 50 + + + + <html><head/><body><p><span style=" font-weight:600;">Select new account type:</span></p></body></html> + + + true + + + + + + + + 16777215 + 16777215 + + + + + + + + + 16777215 + 50 + + + + <html><head/><body><p>Enter some hex digits it should begin with.<br/>NOTE: The more you enter, the longer generation will take.</p></body></html> + + + + + + + + 16777215 + 20 + + + + + + + + + 16777215 + 50 + + + + <html><head/><body><p><span style=" font-weight:600;">Enter this account name:</span></p></body></html> + + + + + + + + 16777215 + 20 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.Helvetica Neue DeskInterface'; font-size:13pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + + + + 16777215 + 100 + + + + <html><head/><body><p><span style=" font-weight:600;">Would you like to add additional security for this key? This lets you protect it with a different password to other keys, but also means that you need to re-enter the key's password every time you wish to use the account.</span></p></body></html> + + + true + + + + + + + Yes + + + false + + + + + + + + 16777215 + 50 + + + + <html><head/><body><p><span style=" font-weight:600;">Enter password:</span></p></body></html> + + + + + + + true + + + + 16777215 + 20 + + + + + + + + + 16777215 + 50 + + + + <html><head/><body><p><span style=" font-weight:600;">Enter password again:</span></p></body></html> + + + + + + + true + + + + 16777215 + 20 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + &Create + + + true + + + + + + + + + + + create + clicked() + NewAccount + accept() + + + 462 + 484 + + + 449 + 504 + + + + + cancel + clicked() + NewAccount + reject() + + + 381 + 483 + + + 351 + 506 + + + + + From cb2a5ec268f5d009f9ad51c931bb1fcfe39495ac Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 13 Aug 2015 23:31:25 +0200 Subject: [PATCH 2/3] new account plugin finished --- alethzero/Main.ui | 3 +- alethzero/MainWin.cpp | 77 ------------------------ alethzero/MainWin.h | 1 - alethzero/NewAccount.cpp | 125 +++++++++++++++++++++++++++++++++------ alethzero/NewAccount.h | 14 ++++- alethzero/NewAccount.ui | 99 ++++++++++++++++++------------- 6 files changed, 179 insertions(+), 140 deletions(-) diff --git a/alethzero/Main.ui b/alethzero/Main.ui index b059b4e07..69846f34c 100644 --- a/alethzero/Main.ui +++ b/alethzero/Main.ui @@ -132,7 +132,7 @@ 0 0 1617 - 24 + 22 @@ -162,7 +162,6 @@ - diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index a78949413..60455969a 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -2104,83 +2104,6 @@ void Main::keysChanged() onBalancesChange(); } -bool beginsWith(Address _a, bytes const& _b) -{ - for (unsigned i = 0; i < min(20, _b.size()); ++i) - if (_a[i] != _b[i]) - return false; - return true; -} - -void Main::on_newAccount_triggered() -{ - bool ok = true; - enum { NoVanity = 0, DirectICAP, FirstTwo, FirstTwoNextTwo, FirstThree, FirstFour, StringMatch }; - QStringList items = {"No vanity (instant)", "Direct ICAP address", "Two pairs first (a few seconds)", "Two pairs first and second (a few minutes)", "Three pairs first (a few minutes)", "Four pairs first (several hours)", "Specific hex string"}; - unsigned v = items.QList::indexOf(QInputDialog::getItem(this, "Vanity Key?", "Would you a vanity key? This could take several hours.", items, 1, false, &ok)); - if (!ok) - return; - - bytes bs; - if (v == StringMatch) - { - QString s = QInputDialog::getText(this, "Vanity Beginning?", "Enter some hex digits that it should begin with.\nNOTE: The more you enter, the longer generation will take.", QLineEdit::Normal, QString(), &ok); - if (!ok) - return; - bs = fromHex(s.toStdString()); - } - - KeyPair p; - bool keepGoing = true; - unsigned done = 0; - function f = [&]() { - KeyPair lp; - while (keepGoing) - { - done++; - if (done % 1000 == 0) - cnote << "Tried" << done << "keys"; - lp = KeyPair::create(); - auto a = lp.address(); - if (v == NoVanity || - (v == DirectICAP && !a[0]) || - (v == FirstTwo && a[0] == a[1]) || - (v == FirstTwoNextTwo && a[0] == a[1] && a[2] == a[3]) || - (v == FirstThree && a[0] == a[1] && a[1] == a[2]) || - (v == FirstFour && a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) || - (v == StringMatch && beginsWith(lp.address(), bs)) - ) - break; - } - if (keepGoing) - p = lp; - keepGoing = false; - }; - vector ts; - for (unsigned t = 0; t < std::thread::hardware_concurrency() - 1; ++t) - ts.push_back(new std::thread(f)); - f(); - for (std::thread* t: ts) - { - t->join(); - delete t; - } - - QString s = QInputDialog::getText(this, "Create Account", "Enter this account's name"); - if (QMessageBox::question(this, "Create Account", "Would you like to use additional security for this key? This lets you protect it with a different password to other keys, but also means you must re-enter the key's password every time you wish to use the account.", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) - { - bool ok = false; - std::string hint; - std::string password = getPassword("Create Account", "Enter the password you would like to use for this key. Don't forget it!", &hint, &ok); - if (!ok) - return; - m_keyManager.import(p.secret(), s.toStdString(), password, hint); - } - else - m_keyManager.import(p.secret(), s.toStdString()); - keysChanged(); -} - void Main::on_killAccount_triggered() { if (ui->ourAccounts->currentRow() >= 0) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index b23a33697..c110f54e8 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -152,7 +152,6 @@ private slots: void on_preview_triggered(); // Account management - void on_newAccount_triggered(); void on_killAccount_triggered(); void on_importKey_triggered(); void on_reencryptKey_triggered(); diff --git a/alethzero/NewAccount.cpp b/alethzero/NewAccount.cpp index dfa808e19..51b320c36 100644 --- a/alethzero/NewAccount.cpp +++ b/alethzero/NewAccount.cpp @@ -15,17 +15,14 @@ along with cpp-ethereum. If not, see . */ /** @file NewAccount.h - * @author Gav Wood + * @author Marek Kotewicz * @date 2015 */ #include "NewAccount.h" #include #include -#include -#include #include -#include #include #include #include "ui_NewAccount.h" @@ -34,6 +31,14 @@ using namespace dev; using namespace az; using namespace eth; +bool beginsWith(Address _a, bytes const& _b) +{ + for (unsigned i = 0; i < min(20, _b.size()); ++i) + if (_a[i] != _b[i]) + return false; + return true; +} + DEV_AZ_NOTE_PLUGIN(NewAccount); NewAccount::NewAccount(MainFace* _m): @@ -49,30 +54,116 @@ NewAccount::~NewAccount() void NewAccount::create() { QDialog d; - Ui_NewAccount u; + Ui::NewAccount u; u.setupUi(&d); d.setWindowTitle("New Account Wallet"); - u.enterHexText->setEnabled(false); - u.enterPasswordText->setEnabled(false); - u.enterPasswordAgainText->setEnabled(false); - enum { NoVanity = 0, DirectICAP, FirstTwo, FirstTwoNextTwo, FirstThree, FirstFour, StringMatch }; + u.hexText->setEnabled(false); + u.passwordText->setEnabled(false); + u.passwordAgainText->setEnabled(false); - QStringList items = {"No vanity (instant)", "Direct ICAP address", "Two pairs first (a few seconds)", "Two pairs first and second (a few minutes)", "Three pairs first (a few minutes)", "Four pairs first (several hours)", "Specific hex string"}; - u.selectTypeComboBox->addItems(items); + QStringList items = + { + "No vanity (instant)", + "Direct ICAP address", + "Two pairs first (a few seconds)", + "Two pairs first and second (a few minutes)", + "Three pairs first (a few minutes)", + "Four pairs first (several hours)", + "Specific hex string" + }; + u.typeComboBox->addItems(items); void (QComboBox:: *indexChangedSignal)(int) = &QComboBox::currentIndexChanged; - connect(u.selectTypeComboBox, indexChangedSignal, [&](int index) { - u.enterHexText->setEnabled(index == StringMatch); + connect(u.typeComboBox, indexChangedSignal, [&](int index) + { + u.hexText->setEnabled(index == StringMatch); }); - connect(u.additionalCheckBox, &QCheckBox::clicked, [&]() { + connect(u.additionalCheckBox, &QCheckBox::clicked, [&]() + { bool checked = u.additionalCheckBox->checkState() == Qt::CheckState::Checked; - u.enterPasswordText->setEnabled(checked); - u.enterPasswordAgainText->setEnabled(checked); + u.passwordText->setEnabled(checked); + u.passwordAgainText->setEnabled(checked); + }); + + connect(u.create, &QPushButton::clicked, [&]() + { + if (u.additionalCheckBox->checkState() == Qt::CheckState::Checked && !validatePassword(u)) + { + u.passwordAgainLabel->setStyleSheet("QLabel { color : red }"); + u.passwordAgainLabel->setText("Invalid! Please re-enter password correctly:"); + return; + } + + d.accept(); }); if (d.exec() == QDialog::Accepted) + onDialogAccepted(u); + +} + +bool NewAccount::validatePassword(Ui::NewAccount const& _u) +{ + return QString::compare(_u.passwordText->toPlainText(), _u.passwordAgainText->toPlainText()) == 0; +} + +void NewAccount::onDialogAccepted(Ui::NewAccount const& _u) +{ + Type v = (Type)_u.typeComboBox->currentIndex(); + bytes bs = fromHex(_u.hexText->toPlainText().toStdString()); + KeyPair p = newKeyPair(v, bs); + QString s = _u.nameText->toPlainText(); + if (_u.additionalCheckBox->checkState() == Qt::CheckState::Checked) + { + std::string hint = _u.hintText->toPlainText().toStdString(); + std::string password = _u.passwordText->toPlainText().toStdString(); + main()->keyManager().import(p.secret(), s.toStdString(), password, hint); + } + else + main()->keyManager().import(p.secret(), s.toStdString()); + + main()->noteKeysChanged(); +} + +KeyPair NewAccount::newKeyPair(Type _type, bytes const& _prefix) +{ + KeyPair p; + bool keepGoing = true; + unsigned done = 0; + function f = [&]() { + KeyPair lp; + while (keepGoing) + { + done++; + if (done % 1000 == 0) + cnote << "Tried" << done << "keys"; + lp = KeyPair::create(); + auto a = lp.address(); + if (_type == NoVanity || + (_type == DirectICAP && !a[0]) || + (_type == FirstTwo && a[0] == a[1]) || + (_type == FirstTwoNextTwo && a[0] == a[1] && a[2] == a[3]) || + (_type == FirstThree && a[0] == a[1] && a[1] == a[2]) || + (_type == FirstFour && a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) || + (_type == StringMatch && beginsWith(lp.address(), _prefix)) + ) + break; + } + if (keepGoing) + p = lp; + keepGoing = false; + }; + + vector ts; + for (unsigned t = 0; t < std::thread::hardware_concurrency() - 1; ++t) + ts.push_back(new std::thread(f)); + f(); + + for (std::thread* t: ts) { - //main()->noteKeysChanged(); + t->join(); + delete t; } + return p; } diff --git a/alethzero/NewAccount.h b/alethzero/NewAccount.h index d1ba1b747..b0031e7f1 100644 --- a/alethzero/NewAccount.h +++ b/alethzero/NewAccount.h @@ -15,7 +15,7 @@ along with cpp-ethereum. If not, see . */ /** @file NewAccount.h - * @author Gav Wood + * @author Marek Kotewicz * @date 2015 */ @@ -23,6 +23,12 @@ #include "MainFace.h" + +namespace Ui +{ +class NewAccount; +} + namespace dev { namespace az @@ -38,6 +44,12 @@ public: private slots: void create(); + +private: + enum Type { NoVanity = 0, DirectICAP, FirstTwo, FirstTwoNextTwo, FirstThree, FirstFour, StringMatch }; + bool validatePassword(Ui::NewAccount const& _u); + void onDialogAccepted(Ui::NewAccount const& _u); + KeyPair newKeyPair(Type _type, bytes const& _prefix); }; } diff --git a/alethzero/NewAccount.ui b/alethzero/NewAccount.ui index 48d463fd5..d793849d8 100644 --- a/alethzero/NewAccount.ui +++ b/alethzero/NewAccount.ui @@ -13,9 +13,12 @@ Dialog + + + - + 16777215 @@ -31,7 +34,7 @@ - + 16777215 @@ -41,7 +44,7 @@ - + 16777215 @@ -54,17 +57,17 @@ - + 16777215 - 20 + 21 - + 16777215 @@ -77,20 +80,13 @@ - + 16777215 - 20 + 21 - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'.Helvetica Neue DeskInterface'; font-size:13pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - @@ -120,7 +116,7 @@ p, li { white-space: pre-wrap; } - + 16777215 @@ -133,20 +129,17 @@ p, li { white-space: pre-wrap; } - - - true - + 16777215 - 20 + 21 - + 16777215 @@ -159,14 +152,28 @@ p, li { white-space: pre-wrap; } - - - true + + + + 16777215 + 21 + + + + + + + <html><head/><body><p><span style=" font-weight:600;">Enter hint:</span></p></body></html> + + + + + 16777215 - 20 + 50 @@ -188,6 +195,15 @@ p, li { white-space: pre-wrap; } + + + 83 + 16777215 + + + + Qt::LeftToRight + Cancel @@ -195,6 +211,21 @@ p, li { white-space: pre-wrap; } + + + 0 + 0 + + + + + 83 + 16777215 + + + + Qt::LeftToRight + &Create @@ -209,22 +240,6 @@ p, li { white-space: pre-wrap; } - - create - clicked() - NewAccount - accept() - - - 462 - 484 - - - 449 - 504 - - - cancel clicked() From f30991f6cbf657c18988a5d045ce0479629de8d0 Mon Sep 17 00:00:00 2001 From: debris Date: Fri, 14 Aug 2015 08:09:14 +0200 Subject: [PATCH 3/3] make hint text field enabled only when entering password is enabled --- alethzero/plugins/namers/NewAccount.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/alethzero/plugins/namers/NewAccount.cpp b/alethzero/plugins/namers/NewAccount.cpp index 51b320c36..64a3ea185 100644 --- a/alethzero/plugins/namers/NewAccount.cpp +++ b/alethzero/plugins/namers/NewAccount.cpp @@ -60,6 +60,7 @@ void NewAccount::create() u.hexText->setEnabled(false); u.passwordText->setEnabled(false); u.passwordAgainText->setEnabled(false); + u.hintText->setEnabled(false); QStringList items = { @@ -84,6 +85,7 @@ void NewAccount::create() bool checked = u.additionalCheckBox->checkState() == Qt::CheckState::Checked; u.passwordText->setEnabled(checked); u.passwordAgainText->setEnabled(checked); + u.hintText->setEnabled(checked); }); connect(u.create, &QPushButton::clicked, [&]()