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

gui: implement support for K1 keys.

This commit is contained in:
Henrik Hautakoski 2023-04-04 19:06:55 +02:00
parent e18886e074
commit 9ed6e6ab80
6 changed files with 73 additions and 27 deletions

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"
@ -33,7 +34,9 @@
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 */