1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-16 03:44:56 +02:00

Merge pull request #35 from eosswedenorg/fio

Adding FIO support
This commit is contained in:
Henrik Hautakoski 2021-05-07 13:59:51 +02:00 committed by GitHub
commit a73689e275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 130 additions and 16 deletions

View file

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <string>
#include <iostream>
#include <libeosio/WIF.hpp>
#include <eoskeygen/core/dictionary.hpp>
@ -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) {

View file

@ -24,6 +24,7 @@
#ifndef EOSIOKEYGEN_KEY_SEARCH_HELPERS_H
#define EOSIOKEYGEN_KEY_SEARCH_HELPERS_H
#include <string>
#include <libeosio/types.hpp>
#include <eoskeygen/core/string.hpp>
#include <eoskeygen/key_search.hpp>
@ -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

View file

@ -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=<num>"
#endif /* EOSIOKEYGEN_HAVE_THREADS */
@ -60,7 +61,7 @@ void usage(const char *name) {
<< " ]"
<< std::endl;
std::cout << " " << name << " benchmark [ <num:1000> ]" << std::endl;
std::cout << " " << name << " [ options ] benchmark [ <num:1000> ]" << 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;
}

View file

@ -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

View file

@ -39,6 +39,7 @@ set( PROGRAM_SRC
src/GenerateWindow.cpp
src/SearchWindow.cpp
src/MultiSelect.cpp
src/Settings.cpp
src/helpers.cpp
)

View file

@ -28,6 +28,7 @@
#include <QGuiApplication>
#include <libeosio/ec.hpp>
#include <libeosio/WIF.hpp>
#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)));
}

View file

@ -26,12 +26,14 @@
#include <QGridLayout>
#include <QStackedWidget>
#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);
}

View file

@ -24,6 +24,8 @@
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include <QAction>
#include <QPointer>
#include <QMainWindow>
class QStackedWidget;
@ -44,9 +46,13 @@ private slots :
void showAbout();
void fioKeysCheckboxChanged();
private :
QStackedWidget* m_stacked;
QPointer<QAction> m_fio_action;
};
#endif /* MAIN_WINDOW_H */

View file

@ -31,6 +31,7 @@
#include <libeosio/WIF.hpp>
#include <eoskeygen/core/leet.hpp>
#include <eoskeygen/core/string.hpp>
#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);

39
gui/src/Settings.cpp Normal file
View file

@ -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;
}

34
gui/src/Settings.hpp Normal file
View file

@ -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 */