From 554cfd588497c46a07a11169018684ca61378791 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 May 2021 16:44:12 +0200 Subject: [PATCH 1/7] common/cmake/libeosio.cmake: set v0.1.3 needed for prefix parameter to wif_print_key() --- common/cmake/libeosio.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/cmake/libeosio.cmake b/common/cmake/libeosio.cmake index 91f1485..f741c08 100644 --- a/common/cmake/libeosio.cmake +++ b/common/cmake/libeosio.cmake @@ -2,7 +2,7 @@ # Variables # -------------------------------- set( LIBEOSIO_GIT_URL "https://github.com/eosswedenorg/libeosio.git" ) -set( LIBEOSIO_WANTED_VERSION v0.1.2 ) +set( LIBEOSIO_WANTED_VERSION v0.1.3 ) # -------------------------------- # Macros From 52e255850a599a723716336207256df4568ae52d Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 May 2021 16:45:59 +0200 Subject: [PATCH 2/7] cli/src/cli_key_search_result: Add prefix parameter to constructor. --- cli/src/cli_key_search_result.cpp | 8 +++++--- cli/src/cli_key_search_result.hpp | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/src/cli_key_search_result.cpp b/cli/src/cli_key_search_result.cpp index 0d527de..fa3d009 100644 --- a/cli/src/cli_key_search_result.cpp +++ b/cli/src/cli_key_search_result.cpp @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include #include #include #include @@ -37,8 +38,9 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos return len; } -CliKeySearchResult::CliKeySearchResult(const Dictionary& dict) : -m_dict (dict) +CliKeySearchResult::CliKeySearchResult(const Dictionary& dict, const std::string& prefix) : +m_dict (dict), +m_prefix (prefix) { } @@ -50,7 +52,7 @@ void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const std::cout << "----" << std::endl; std::cout << "Found: " << pub.substr(result.pos, result.len) << std::endl; - std::cout << "Public: EOS"; + std::cout << "Public: " << m_prefix.substr(0, 3); for(size_t i = 3; i < pub.length(); ) { if (i == result.pos) { diff --git a/cli/src/cli_key_search_result.hpp b/cli/src/cli_key_search_result.hpp index ac75cb1..4f1e47b 100644 --- a/cli/src/cli_key_search_result.hpp +++ b/cli/src/cli_key_search_result.hpp @@ -24,6 +24,7 @@ #ifndef EOSIOKEYGEN_KEY_SEARCH_HELPERS_H #define EOSIOKEYGEN_KEY_SEARCH_HELPERS_H +#include #include #include #include @@ -36,13 +37,15 @@ class Dictionary; class CliKeySearchResult : public IKeySearchResult { public: - CliKeySearchResult(const Dictionary& dict); + CliKeySearchResult(const Dictionary& dict, const std::string& prefix); virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result); protected : const Dictionary& m_dict; + + std::string m_prefix; }; } // namespace eoskeygen From 486d2c5030858bab7c31a1782b86a8e15f9bb0bb Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 May 2021 16:47:18 +0200 Subject: [PATCH 3/7] cli/src/main.cpp: implement "--fio" option to generate FIO keys. --- cli/src/main.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cli/src/main.cpp b/cli/src/main.cpp index 3d1f3f8..19248ac 100644 --- a/cli/src/main.cpp +++ b/cli/src/main.cpp @@ -39,6 +39,7 @@ // Command line options. bool option_l33t = false; +std::string key_prefix = "EOS"; #ifdef EOSIOKEYGEN_HAVE_THREADS size_t option_num_threads = eoskeygen::KeySearch::max_threads(); @@ -48,10 +49,10 @@ void usage(const char *name) { std::cout << std::endl << "Usage:" << std::endl - << " " << name << std::endl; + << " " << name << " [ options ]" << std::endl; std::cout << " " << name - << " search [ -m | --l33t" + << " [ options ] search [ -m | --l33t" #ifdef EOSIOKEYGEN_HAVE_THREADS << " | --threads=" #endif /* EOSIOKEYGEN_HAVE_THREADS */ @@ -60,7 +61,7 @@ void usage(const char *name) { << " ]" << std::endl; - std::cout << " " << name << " benchmark [ ]" << std::endl; + std::cout << " " << name << " [ options ] benchmark [ ]" << std::endl; std::cout << " " << name << " -h | --help" << std::endl; std::cout << " " << name << " -v" << std::endl; @@ -73,6 +74,8 @@ void usage(const char *name) { << " -h --help Shows this help text." << std::endl << std::endl << " -v Shows version." + << std::endl << std::endl + << " --fio Generate keys from FIO network instead of EOSIO." << std::endl << std::endl; std::cout << "search: " << std::endl @@ -112,7 +115,7 @@ void usage(const char *name) { int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& dict, int count) { eoskeygen::KeySearch ks; - eoskeygen::CliKeySearchResult rs(dict); + eoskeygen::CliKeySearchResult rs(dict, key_prefix); ks.setCallback(&rs); @@ -169,11 +172,16 @@ int main(int argc, char **argv) { // when parsing command line. int p = 1; + if (p < argc && !strcmp(argv[p], "--fio")) { + p++; + key_prefix = "FIO"; + } + // No args, just print a key. - if (argc <= 1) { + if (p >= argc) { struct libeosio::ec_keypair pair; libeosio::ec_generate_key(&pair); - libeosio::wif_print_key(&pair); + libeosio::wif_print_key(&pair, key_prefix); return 0; } From f7b84c7752395bb12e363b344a01c52080e4043b Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 May 2021 18:05:01 +0200 Subject: [PATCH 4/7] GUI: Adding Settings Component. --- gui/CMakeLists.txt | 1 + gui/src/Settings.cpp | 39 +++++++++++++++++++++++++++++++++++++++ gui/src/Settings.hpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 gui/src/Settings.cpp create mode 100644 gui/src/Settings.hpp diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 3628f7a..361dfeb 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -39,6 +39,7 @@ set( PROGRAM_SRC src/GenerateWindow.cpp src/SearchWindow.cpp src/MultiSelect.cpp + src/Settings.cpp src/helpers.cpp ) diff --git a/gui/src/Settings.cpp b/gui/src/Settings.cpp new file mode 100644 index 0000000..d49c408 --- /dev/null +++ b/gui/src/Settings.cpp @@ -0,0 +1,39 @@ +/** + * MIT License + * + * Copyright (c) 2020-2021 EOS Sw/eden + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "Settings.hpp" + +namespace priv { + bool fio_keys = false; + +} // namespace priv + +bool Settings::shouldGenerateFioKeys() +{ + return priv::fio_keys; +} + +void Settings::setGenerateFioKeys(bool value) +{ + priv::fio_keys = value; +} diff --git a/gui/src/Settings.hpp b/gui/src/Settings.hpp new file mode 100644 index 0000000..d47c26f --- /dev/null +++ b/gui/src/Settings.hpp @@ -0,0 +1,34 @@ +/** + * MIT License + * + * Copyright (c) 2020-2021 EOS Sw/eden + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef SETTINGS_H +#define SETTINGS_H + +namespace Settings +{ + bool shouldGenerateFioKeys(); + + void setGenerateFioKeys(bool value); +}; + +#endif /* SEARCH_WINDOW_H */ From 8c9047d71600aed1e41aaa52d25980c9b2e2f4be Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 7 May 2021 13:38:17 +0200 Subject: [PATCH 5/7] gui/src/SearchWindow.cpp: Check Settings::shouldGenerateFioKeys() to know if we should use "FIO" or "EOS" prefix. --- gui/src/SearchWindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/src/SearchWindow.cpp b/gui/src/SearchWindow.cpp index 758ff43..23e2cf3 100644 --- a/gui/src/SearchWindow.cpp +++ b/gui/src/SearchWindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "Settings.hpp" #include "gui_text.h" #include "config.hpp" #include "helpers.hpp" @@ -149,7 +150,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct { int pos = (int) result.pos; int len = (int) result.len; - QString pub = QString::fromStdString(libeosio::wif_pub_encode(key->pub)); + QString pub = QString::fromStdString(libeosio::wif_pub_encode(key->pub, Settings::shouldGenerateFioKeys() ? "FIO" : "EOS")); QString mid = pub.mid(pos, len); QString left = pub.left(pos); QString right = pub.mid(pos + len, pub.size() - pos); From 6bd84b1d8d4db1ea35f0390d59961e739dbd3299 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 7 May 2021 13:38:32 +0200 Subject: [PATCH 6/7] gui/src/GenerateWindow.cpp: Check Settings::shouldGenerateFioKeys() if we should use "FIO" or "EOS" prefix. --- gui/src/GenerateWindow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gui/src/GenerateWindow.cpp b/gui/src/GenerateWindow.cpp index 00fa48f..8880ffb 100644 --- a/gui/src/GenerateWindow.cpp +++ b/gui/src/GenerateWindow.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "Settings.hpp" #include "GenerateWindow.hpp" void _initKeyWidget(QLineEdit& w) { @@ -91,12 +92,13 @@ m_btn_copy_both ("Copy keys") void GenerateWindow::generate_key() { - std::string pubstr, privstr; + std::string pubstr; struct libeosio::ec_keypair pair; libeosio::ec_generate_key(&pair); - m_pub.setText(QString::fromStdString(libeosio::wif_pub_encode(pair.pub))); + pubstr = libeosio::wif_pub_encode(pair.pub, Settings::shouldGenerateFioKeys() ? "FIO" : "EOS"); + m_pub.setText(QString::fromStdString(pubstr)); m_priv.setText(QString::fromStdString(libeosio::wif_priv_encode(pair.secret))); } From 7fb1774359fe7baf67eefc01c21487883d6678ff Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 7 May 2021 13:40:47 +0200 Subject: [PATCH 7/7] gui/src/MainWindow: Add menu item to switch between FIO/EOS key prefixes. --- gui/src/MainWindow.cpp | 22 ++++++++++++++++++++-- gui/src/MainWindow.hpp | 6 ++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gui/src/MainWindow.cpp b/gui/src/MainWindow.cpp index 3648bf7..8000ac1 100644 --- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -26,12 +26,14 @@ #include #include #include "gui_text.h" +#include "Settings.hpp" #include "GenerateWindow.hpp" #include "SearchWindow.hpp" #include "MainWindow.hpp" MainWindow::MainWindow(QWidget *parent) : -QMainWindow (parent) +QMainWindow (parent), +m_fio_action (nullptr) { // Create sub windows and stacked widget. m_stacked = new QStackedWidget(); @@ -40,10 +42,21 @@ QMainWindow (parent) setCentralWidget(m_stacked); - // Menu bar. + // Add to menu bar. menuBar()->addAction("Generate", this, SLOT(switchToGenerate())); menuBar()->addAction("Search", this, SLOT(switchToSearch())); + + // Settings + + m_fio_action = new QAction("FIO Keys", this); + m_fio_action->setCheckable(true); + connect(m_fio_action, SIGNAL(triggered()), this, SLOT(fioKeysCheckboxChanged())); + + QMenu *settings_menu = menuBar()->addMenu("Settings"); + settings_menu->addAction(m_fio_action); + + // About menuBar()->addAction("About", this, SLOT(showAbout())); } @@ -63,3 +76,8 @@ void MainWindow::showAbout() EOSIOKEYGEN_GUI_TEXT_ABOUT_TITLE, EOSIOKEYGEN_GUI_TEXT_ABOUT_BODY); } + +void MainWindow::fioKeysCheckboxChanged() +{ + Settings::setGenerateFioKeys(m_fio_action ? m_fio_action->isChecked() : false); +} diff --git a/gui/src/MainWindow.hpp b/gui/src/MainWindow.hpp index c42e574..1658195 100644 --- a/gui/src/MainWindow.hpp +++ b/gui/src/MainWindow.hpp @@ -24,6 +24,8 @@ #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H +#include +#include #include class QStackedWidget; @@ -44,9 +46,13 @@ private slots : void showAbout(); + void fioKeysCheckboxChanged(); + private : QStackedWidget* m_stacked; + + QPointer m_fio_action; }; #endif /* MAIN_WINDOW_H */