1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-07-03 11:53:41 +02:00

Merge branch 'k1' into develop

This commit is contained in:
Henrik Hautakoski 2023-04-05 19:20:45 +02:00
commit 3d5b163e9f
12 changed files with 114 additions and 45 deletions

View file

@ -38,22 +38,23 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos
return len; return len;
} }
CliKeySearchResult::CliKeySearchResult(const Dictionary& dict, const std::string& prefix) : CliKeySearchResult::CliKeySearchResult(const Dictionary& dict, const libeosio::wif_codec_t& codec) :
m_dict (dict), m_dict (dict),
m_prefix (prefix) m_codec (codec)
{ {
} }
void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) { void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result) {
std::string pub = libeosio::wif_pub_encode(key->pub); std::string pub = libeosio::wif_pub_encode(key->pub, m_codec.pub);
Dictionary::search_result_t dict_res = m_dict.search(pub); Dictionary::search_result_t dict_res = m_dict.search(pub);
int pub_prefix_len = (int) m_codec.pub.length();
std::cout << "----" << std::endl; std::cout << "----" << std::endl;
std::cout << "Found: " << pub.substr(result.pos, result.len) << std::endl; std::cout << "Found: " << pub.substr(result.pos, result.len) << std::endl;
std::cout << "Public: " << m_prefix.substr(0, 3); std::cout << "Public: " << m_codec.pub;
for(size_t i = 3; i < pub.length(); ) { for(size_t i = pub_prefix_len; i < pub.length(); ) {
if (i == result.pos) { if (i == result.pos) {
i += highlight(console::red, pub, result.pos, result.len); i += highlight(console::red, pub, result.pos, result.len);
@ -70,7 +71,7 @@ void CliKeySearchResult::onResult(const struct libeosio::ec_keypair* key, const
} }
std::cout << std::endl std::cout << std::endl
<< "Private: " << libeosio::wif_priv_encode(key->secret) << std::endl; << "Private: " << libeosio::wif_priv_encode(key->secret, m_codec.pvt) << std::endl;
} }
} // namespace eoskeygen } // namespace eoskeygen

View file

@ -26,6 +26,7 @@
#include <string> #include <string>
#include <libeosio/ec.hpp> #include <libeosio/ec.hpp>
#include <libeosio/WIF.hpp>
#include <eoskeygen/core/string.hpp> #include <eoskeygen/core/string.hpp>
#include <eoskeygen/key_search.hpp> #include <eoskeygen/key_search.hpp>
#include <eoskeygen/key_search_result.hpp> #include <eoskeygen/key_search_result.hpp>
@ -37,7 +38,7 @@ class Dictionary;
class CliKeySearchResult : public IKeySearchResult class CliKeySearchResult : public IKeySearchResult
{ {
public: public:
CliKeySearchResult(const Dictionary& dict, const std::string& prefix); CliKeySearchResult(const Dictionary& dict, const libeosio::wif_codec_t& codec);
virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result); virtual void onResult(const struct libeosio::ec_keypair* key, const struct KeySearch::result& result);
@ -45,7 +46,7 @@ protected :
const Dictionary& m_dict; const Dictionary& m_dict;
std::string m_prefix; libeosio::wif_codec_t m_codec;
}; };
} // namespace eoskeygen } // namespace eoskeygen

View file

@ -40,7 +40,7 @@
// Command line options. // Command line options.
bool option_l33t = false; bool option_l33t = false;
std::string key_prefix = "EOS"; libeosio::wif_codec_t key_codec;
#ifdef EOSIOKEYGEN_HAVE_THREADS #ifdef EOSIOKEYGEN_HAVE_THREADS
size_t option_num_threads; size_t option_num_threads;
@ -65,8 +65,9 @@ public:
int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& dict, int count) { int cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& dict, int count) {
eoskeygen::KeySearch ks; eoskeygen::KeySearch ks;
eoskeygen::CliKeySearchResult rs(dict, key_prefix); eoskeygen::CliKeySearchResult rs(dict, key_codec);
ks.setPrefix(key_codec.pub);
ks.setCallback(&rs); ks.setCallback(&rs);
for(auto it = words.begin(); it != words.end(); it++) { for(auto it = words.begin(); it != words.end(); it++) {
@ -122,6 +123,7 @@ int main(int argc, char **argv) {
std::vector<std::string> dict_list; std::vector<std::string> dict_list;
std::vector<std::string> lang_list; std::vector<std::string> lang_list;
std::string search_words; std::string search_words;
std::string key_format;
int search_count; int search_count;
size_t bench_count; size_t bench_count;
int rc = 0; int rc = 0;
@ -129,7 +131,7 @@ int main(int argc, char **argv) {
libeosio::ec_init(); libeosio::ec_init();
CLI::Option* version = cmd.add_flag("-v,--version", "Show version"); CLI::Option* version = cmd.add_flag("-v,--version", "Show version");
CLI::Option* fio = cmd.add_flag("--fio", "Generate keys from FIO network instead of EOSIO."); cmd.add_option("--format", key_format, "valid values: K1, fio, legacy")->default_val("K1");
// Search // Search
CLI::App* search_cmd = cmd.add_subcommand("search", CLI::App* search_cmd = cmd.add_subcommand("search",
@ -171,8 +173,15 @@ int main(int argc, char **argv) {
goto end; goto end;
} }
if (*fio) { if (key_format == "fio") {
key_prefix = "FIO"; key_codec = libeosio::wif_create_legacy_codec("FIO");
} else if (key_format == "legacy") {
key_codec = libeosio::WIF_CODEC_LEG;
} else if (key_format == "K1") {
key_codec = libeosio::WIF_CODEC_K1;
} else {
std::cerr << "invalid key format: " << key_format << std::endl;
goto end;
} }
if (search_cmd->parsed()) { if (search_cmd->parsed()) {
@ -229,7 +238,7 @@ int main(int argc, char **argv) {
else { else {
struct libeosio::ec_keypair pair; struct libeosio::ec_keypair pair;
libeosio::ec_generate_key(&pair); libeosio::ec_generate_key(&pair);
libeosio::wif_print_key(&pair, key_prefix); libeosio::wif_print_key(&pair, key_codec);
goto end; goto end;
} }

View file

@ -2,7 +2,7 @@
# Variables # Variables
# -------------------------------- # --------------------------------
set( LIBEOSIO_GIT_URL "https://github.com/eosswedenorg/libeosio.git" ) set( LIBEOSIO_GIT_URL "https://github.com/eosswedenorg/libeosio.git" )
set( LIBEOSIO_WANTED_VERSION v0.1.6 ) set( LIBEOSIO_WANTED_VERSION v0.1.7 )
# -------------------------------- # --------------------------------
# Macros # Macros

View file

@ -47,6 +47,8 @@ public :
public : public :
KeySearch(); KeySearch();
void setPrefix(const std::string& prefix);
// Add a word to search for. // Add a word to search for.
void addWord(const std::string& str); void addWord(const std::string& str);
@ -97,6 +99,10 @@ protected :
void _search_linear(); void _search_linear();
protected : protected :
// Public key prefix.
std::string m_prefix;
// List of words to search for. // List of words to search for.
strlist_t m_words; strlist_t m_words;

View file

@ -31,6 +31,7 @@
namespace eoskeygen { namespace eoskeygen {
KeySearch::KeySearch() : KeySearch::KeySearch() :
m_prefix ("EOS"),
m_max (0), m_max (0),
m_count (0), m_count (0),
#ifdef EOSIOKEYGEN_HAVE_THREADS #ifdef EOSIOKEYGEN_HAVE_THREADS
@ -40,6 +41,11 @@ KeySearch::KeySearch() :
{ {
} }
void KeySearch::setPrefix(const std::string& prefix)
{
m_prefix = prefix;
}
void KeySearch::addWord(const std::string& str) void KeySearch::addWord(const std::string& str)
{ {
std::string tmp = str; std::string tmp = str;
@ -107,14 +113,14 @@ void KeySearch::find(size_t num_results)
bool KeySearch::_contains_word(const struct libeosio::ec_keypair* key, struct result& result) { bool KeySearch::_contains_word(const struct libeosio::ec_keypair* key, struct result& result) {
// skip first 3 chars, as those are always "EOS" size_t prefix_len = m_prefix.length();
std::string pubstr = libeosio::wif_pub_encode(key->pub).substr(3); std::string pubstr = libeosio::wif_pub_encode(key->pub, m_prefix).substr(prefix_len);
strtolower(pubstr); strtolower(pubstr);
for(auto const& w: m_words) { for(auto const& w: m_words) {
size_t p = pubstr.find(w); size_t p = pubstr.find(w);
if (p != std::string::npos) { if (p != std::string::npos) {
result.pos = p + 3; result.pos = p + prefix_len;
result.len = w.length(); result.len = w.length();
return true; return true;
} }

View file

@ -92,14 +92,16 @@ m_btn_copy_both ("Copy keys")
void GenerateWindow::generate_key() void GenerateWindow::generate_key()
{ {
std::string pubstr; std::string pubstr, pvtstr;
struct libeosio::ec_keypair pair; struct libeosio::ec_keypair pair;
const libeosio::wif_codec_t& codec = Settings::getKeyCodec();
libeosio::ec_generate_key(&pair); libeosio::ec_generate_key(&pair);
pubstr = libeosio::wif_pub_encode(pair.pub, Settings::shouldGenerateFioKeys() ? "FIO" : "EOS"); pubstr = libeosio::wif_pub_encode(pair.pub, codec.pub);
pvtstr = libeosio::wif_priv_encode(pair.secret, codec.pvt);
m_pub.setText(QString::fromStdString(pubstr)); m_pub.setText(QString::fromStdString(pubstr));
m_priv.setText(QString::fromStdString(libeosio::wif_priv_encode(pair.secret))); m_priv.setText(QString::fromStdString(pvtstr));
} }
void GenerateWindow::copy_both_keys() void GenerateWindow::copy_both_keys()

View file

@ -25,6 +25,7 @@
#include <QMenuBar> #include <QMenuBar>
#include <QGridLayout> #include <QGridLayout>
#include <QStackedWidget> #include <QStackedWidget>
#include <libeosio/WIF.hpp>
#include "gui_text.h" #include "gui_text.h"
#include "Settings.hpp" #include "Settings.hpp"
#include "GenerateWindow.hpp" #include "GenerateWindow.hpp"
@ -32,8 +33,10 @@
#include "MainWindow.hpp" #include "MainWindow.hpp"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow (parent), QMainWindow (parent),
m_fio_action (nullptr) m_format_fio_action (nullptr),
m_format_legacy_action (nullptr),
m_format_k1_action (nullptr)
{ {
libeosio::ec_init(); libeosio::ec_init();
@ -51,12 +54,28 @@ m_fio_action (nullptr)
// Settings // Settings
m_fio_action = new QAction("FIO Keys", this); QActionGroup* formatGroup = new QActionGroup(this);
m_fio_action->setCheckable(true);
connect(m_fio_action, SIGNAL(triggered()), this, SLOT(fioKeysCheckboxChanged()));
QMenu *settings_menu = menuBar()->addMenu("Settings"); m_format_fio_action = new QAction("FIO", formatGroup);
settings_menu->addAction(m_fio_action); m_format_fio_action->setCheckable(true);
m_format_legacy_action = new QAction("Legacy", formatGroup);
m_format_legacy_action->setCheckable(true);
m_format_k1_action = new QAction("K1", formatGroup);
m_format_k1_action->setCheckable(true);
// Set k1 and trigger the changed action so we set the codec.
m_format_k1_action->setChecked(true);
formatK1CheckboxChanged();
connect(m_format_fio_action, SIGNAL(triggered()), this, SLOT(formatFioCheckboxChanged()));
connect(m_format_legacy_action, SIGNAL(triggered()), this, SLOT(formatLegacyCheckboxChanged()));
connect(m_format_k1_action, SIGNAL(triggered()), this, SLOT(formatK1CheckboxChanged()));
QMenu *settings = menuBar()->addMenu("Settings");
QMenu *format_menu = settings->addMenu("Key Format");
format_menu->addAction(m_format_k1_action);
format_menu->addAction(m_format_legacy_action);
format_menu->addAction(m_format_fio_action);
// About // About
menuBar()->addAction("About", this, SLOT(showAbout())); menuBar()->addAction("About", this, SLOT(showAbout()));
@ -84,7 +103,23 @@ void MainWindow::showAbout()
EOSIOKEYGEN_GUI_TEXT_ABOUT_BODY); EOSIOKEYGEN_GUI_TEXT_ABOUT_BODY);
} }
void MainWindow::fioKeysCheckboxChanged() void MainWindow::formatFioCheckboxChanged()
{ {
Settings::setGenerateFioKeys(m_fio_action ? m_fio_action->isChecked() : false); if (m_format_fio_action->isChecked()) {
Settings::setKeyCodec(libeosio::wif_create_legacy_codec("FIO"));
}
}
void MainWindow::formatLegacyCheckboxChanged()
{
if (m_format_legacy_action->isChecked()) {
Settings::setKeyCodec(libeosio::WIF_CODEC_LEG);
}
}
void MainWindow::formatK1CheckboxChanged()
{
if (m_format_k1_action->isChecked()) {
Settings::setKeyCodec(libeosio::WIF_CODEC_K1);
}
} }

View file

@ -47,13 +47,17 @@ private slots :
void showAbout(); void showAbout();
void fioKeysCheckboxChanged(); void formatFioCheckboxChanged();
void formatLegacyCheckboxChanged();
void formatK1CheckboxChanged();
private : private :
QStackedWidget* m_stacked; QStackedWidget* m_stacked;
QPointer<QAction> m_fio_action; QPointer<QAction> m_format_fio_action;
QPointer<QAction> m_format_legacy_action;
QPointer<QAction> m_format_k1_action;
}; };
#endif /* MAIN_WINDOW_H */ #endif /* MAIN_WINDOW_H */

View file

@ -150,14 +150,16 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct
{ {
int pos = (int) result.pos; int pos = (int) result.pos;
int len = (int) result.len; int len = (int) result.len;
QString pub = QString::fromStdString(libeosio::wif_pub_encode(key->pub, Settings::shouldGenerateFioKeys() ? "FIO" : "EOS")); libeosio::wif_codec_t codec = Settings::getKeyCodec();
QString pub = QString::fromStdString(libeosio::wif_pub_encode(key->pub, codec.pub));
int pub_prefix_len = (int) codec.pub.length();
QString mid = pub.mid(pos, len); QString mid = pub.mid(pos, len);
QString left = pub.left(pos); QString left = pub.left(pos);
QString right = pub.mid(pos + len, pub.size() - pos); QString right = pub.mid(pos + len, pub.size() - pos);
eoskeygen::Dictionary::search_result_t dict_res = m_dict.search(pub.toStdString()); eoskeygen::Dictionary::search_result_t dict_res = m_dict.search(pub.toStdString());
QString out = "Public: " + pub.left(3); QString out = "Public: " + pub.left(pub_prefix_len);
for(int i = 3; i < pub.length(); ) { for(int i = pub_prefix_len; i < pub.length(); ) {
if (i == pos) { if (i == pos) {
out += "<font color=red>" + pub.mid(pos, len) + "</font>"; out += "<font color=red>" + pub.mid(pos, len) + "</font>";
@ -178,7 +180,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct
out += pub[i++]; out += pub[i++];
} }
out += "<br/>Private: " + QString::fromStdString(libeosio::wif_priv_encode(key->secret)); out += "<br/>Private: " + QString::fromStdString(libeosio::wif_priv_encode(key->secret, codec.pvt));
// As this function could be called from a non-gui thread. we use signals. // As this function could be called from a non-gui thread. we use signals.
emit addOutput("<p>" + out + "</p>"); emit addOutput("<p>" + out + "</p>");
@ -253,6 +255,9 @@ void SearchWindow::langFileAdd()
void SearchWindow::searchStarted() void SearchWindow::searchStarted()
{ {
// Set prefix for search
m_ksearch.setPrefix(Settings::getKeyCodec().pub);
m_btn_exec.setText("Cancel"); m_btn_exec.setText("Cancel");
m_txt_search.setEnabled(false); m_txt_search.setEnabled(false);

View file

@ -24,16 +24,14 @@
#include "Settings.hpp" #include "Settings.hpp"
namespace priv { namespace priv {
bool fio_keys = false;
libeosio::wif_codec_t key_format = libeosio::WIF_CODEC_K1;
} // namespace priv } // namespace priv
bool Settings::shouldGenerateFioKeys() void Settings::setKeyCodec(const libeosio::wif_codec_t& format) {
{ priv::key_format = format;
return priv::fio_keys;
} }
void Settings::setGenerateFioKeys(bool value) const libeosio::wif_codec_t& Settings::getKeyCodec() {
{ return priv::key_format;
priv::fio_keys = value;
} }

View file

@ -24,11 +24,13 @@
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H
#include <libeosio/WIF.hpp>
namespace Settings namespace Settings
{ {
bool shouldGenerateFioKeys(); void setKeyCodec(const libeosio::wif_codec_t& format);
void setGenerateFioKeys(bool value); const libeosio::wif_codec_t& getKeyCodec();
}; };
#endif /* SEARCH_WINDOW_H */ #endif /* SEARCH_WINDOW_H */