mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-16 03:44:56 +02:00
Merge branch 'k1' into develop
This commit is contained in:
commit
3d5b163e9f
12 changed files with 114 additions and 45 deletions
|
|
@ -38,22 +38,23 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos
|
|||
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_prefix (prefix)
|
||||
m_codec (codec)
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
int pub_prefix_len = (int) m_codec.pub.length();
|
||||
|
||||
std::cout << "----" << std::endl;
|
||||
std::cout << "Found: " << pub.substr(result.pos, result.len) << std::endl;
|
||||
|
||||
std::cout << "Public: " << m_prefix.substr(0, 3);
|
||||
for(size_t i = 3; i < pub.length(); ) {
|
||||
std::cout << "Public: " << m_codec.pub;
|
||||
for(size_t i = pub_prefix_len; i < pub.length(); ) {
|
||||
|
||||
if (i == result.pos) {
|
||||
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
|
||||
<< "Private: " << libeosio::wif_priv_encode(key->secret) << std::endl;
|
||||
<< "Private: " << libeosio::wif_priv_encode(key->secret, m_codec.pvt) << std::endl;
|
||||
}
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <libeosio/ec.hpp>
|
||||
#include <libeosio/WIF.hpp>
|
||||
#include <eoskeygen/core/string.hpp>
|
||||
#include <eoskeygen/key_search.hpp>
|
||||
#include <eoskeygen/key_search_result.hpp>
|
||||
|
|
@ -37,7 +38,7 @@ class Dictionary;
|
|||
class CliKeySearchResult : public IKeySearchResult
|
||||
{
|
||||
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);
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ protected :
|
|||
|
||||
const Dictionary& m_dict;
|
||||
|
||||
std::string m_prefix;
|
||||
libeosio::wif_codec_t m_codec;
|
||||
};
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
// Command line options.
|
||||
bool option_l33t = false;
|
||||
std::string key_prefix = "EOS";
|
||||
libeosio::wif_codec_t key_codec;
|
||||
|
||||
#ifdef EOSIOKEYGEN_HAVE_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) {
|
||||
|
||||
eoskeygen::KeySearch ks;
|
||||
eoskeygen::CliKeySearchResult rs(dict, key_prefix);
|
||||
eoskeygen::CliKeySearchResult rs(dict, key_codec);
|
||||
|
||||
ks.setPrefix(key_codec.pub);
|
||||
ks.setCallback(&rs);
|
||||
|
||||
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> lang_list;
|
||||
std::string search_words;
|
||||
std::string key_format;
|
||||
int search_count;
|
||||
size_t bench_count;
|
||||
int rc = 0;
|
||||
|
|
@ -129,7 +131,7 @@ int main(int argc, char **argv) {
|
|||
libeosio::ec_init();
|
||||
|
||||
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
|
||||
CLI::App* search_cmd = cmd.add_subcommand("search",
|
||||
|
|
@ -171,8 +173,15 @@ int main(int argc, char **argv) {
|
|||
goto end;
|
||||
}
|
||||
|
||||
if (*fio) {
|
||||
key_prefix = "FIO";
|
||||
if (key_format == "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()) {
|
||||
|
|
@ -229,7 +238,7 @@ int main(int argc, char **argv) {
|
|||
else {
|
||||
struct libeosio::ec_keypair pair;
|
||||
libeosio::ec_generate_key(&pair);
|
||||
libeosio::wif_print_key(&pair, key_prefix);
|
||||
libeosio::wif_print_key(&pair, key_codec);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# Variables
|
||||
# --------------------------------
|
||||
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
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ public :
|
|||
public :
|
||||
KeySearch();
|
||||
|
||||
void setPrefix(const std::string& prefix);
|
||||
|
||||
// Add a word to search for.
|
||||
void addWord(const std::string& str);
|
||||
|
||||
|
|
@ -97,6 +99,10 @@ protected :
|
|||
void _search_linear();
|
||||
|
||||
protected :
|
||||
|
||||
// Public key prefix.
|
||||
std::string m_prefix;
|
||||
|
||||
// List of words to search for.
|
||||
strlist_t m_words;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
namespace eoskeygen {
|
||||
|
||||
KeySearch::KeySearch() :
|
||||
m_prefix ("EOS"),
|
||||
m_max (0),
|
||||
m_count (0),
|
||||
#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)
|
||||
{
|
||||
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) {
|
||||
|
||||
// skip first 3 chars, as those are always "EOS"
|
||||
std::string pubstr = libeosio::wif_pub_encode(key->pub).substr(3);
|
||||
size_t prefix_len = m_prefix.length();
|
||||
std::string pubstr = libeosio::wif_pub_encode(key->pub, m_prefix).substr(prefix_len);
|
||||
strtolower(pubstr);
|
||||
|
||||
for(auto const& w: m_words) {
|
||||
size_t p = pubstr.find(w);
|
||||
if (p != std::string::npos) {
|
||||
result.pos = p + 3;
|
||||
result.pos = p + prefix_len;
|
||||
result.len = w.length();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,14 +92,16 @@ m_btn_copy_both ("Copy keys")
|
|||
|
||||
void GenerateWindow::generate_key()
|
||||
{
|
||||
std::string pubstr;
|
||||
std::string pubstr, pvtstr;
|
||||
struct libeosio::ec_keypair pair;
|
||||
const libeosio::wif_codec_t& codec = Settings::getKeyCodec();
|
||||
|
||||
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_priv.setText(QString::fromStdString(libeosio::wif_priv_encode(pair.secret)));
|
||||
m_priv.setText(QString::fromStdString(pvtstr));
|
||||
}
|
||||
|
||||
void GenerateWindow::copy_both_keys()
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <QMenuBar>
|
||||
#include <QGridLayout>
|
||||
#include <QStackedWidget>
|
||||
#include <libeosio/WIF.hpp>
|
||||
#include "gui_text.h"
|
||||
#include "Settings.hpp"
|
||||
#include "GenerateWindow.hpp"
|
||||
|
|
@ -33,7 +34,9 @@
|
|||
|
||||
MainWindow::MainWindow(QWidget *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();
|
||||
|
||||
|
|
@ -51,12 +54,28 @@ m_fio_action (nullptr)
|
|||
|
||||
// Settings
|
||||
|
||||
m_fio_action = new QAction("FIO Keys", this);
|
||||
m_fio_action->setCheckable(true);
|
||||
connect(m_fio_action, SIGNAL(triggered()), this, SLOT(fioKeysCheckboxChanged()));
|
||||
QActionGroup* formatGroup = new QActionGroup(this);
|
||||
|
||||
QMenu *settings_menu = menuBar()->addMenu("Settings");
|
||||
settings_menu->addAction(m_fio_action);
|
||||
m_format_fio_action = new QAction("FIO", formatGroup);
|
||||
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
|
||||
menuBar()->addAction("About", this, SLOT(showAbout()));
|
||||
|
|
@ -84,7 +103,23 @@ void MainWindow::showAbout()
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,17 @@ private slots :
|
|||
|
||||
void showAbout();
|
||||
|
||||
void fioKeysCheckboxChanged();
|
||||
void formatFioCheckboxChanged();
|
||||
void formatLegacyCheckboxChanged();
|
||||
void formatK1CheckboxChanged();
|
||||
|
||||
private :
|
||||
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -150,14 +150,16 @@ 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, 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 left = pub.left(pos);
|
||||
QString right = pub.mid(pos + len, pub.size() - pos);
|
||||
eoskeygen::Dictionary::search_result_t dict_res = m_dict.search(pub.toStdString());
|
||||
|
||||
QString out = "Public: " + pub.left(3);
|
||||
for(int i = 3; i < pub.length(); ) {
|
||||
QString out = "Public: " + pub.left(pub_prefix_len);
|
||||
for(int i = pub_prefix_len; i < pub.length(); ) {
|
||||
|
||||
if (i == pos) {
|
||||
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 += "<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.
|
||||
emit addOutput("<p>" + out + "</p>");
|
||||
|
|
@ -253,6 +255,9 @@ void SearchWindow::langFileAdd()
|
|||
|
||||
void SearchWindow::searchStarted()
|
||||
{
|
||||
// Set prefix for search
|
||||
m_ksearch.setPrefix(Settings::getKeyCodec().pub);
|
||||
|
||||
m_btn_exec.setText("Cancel");
|
||||
|
||||
m_txt_search.setEnabled(false);
|
||||
|
|
|
|||
|
|
@ -24,16 +24,14 @@
|
|||
#include "Settings.hpp"
|
||||
|
||||
namespace priv {
|
||||
bool fio_keys = false;
|
||||
|
||||
libeosio::wif_codec_t key_format = libeosio::WIF_CODEC_K1;
|
||||
} // namespace priv
|
||||
|
||||
bool Settings::shouldGenerateFioKeys()
|
||||
{
|
||||
return priv::fio_keys;
|
||||
void Settings::setKeyCodec(const libeosio::wif_codec_t& format) {
|
||||
priv::key_format = format;
|
||||
}
|
||||
|
||||
void Settings::setGenerateFioKeys(bool value)
|
||||
{
|
||||
priv::fio_keys = value;
|
||||
const libeosio::wif_codec_t& Settings::getKeyCodec() {
|
||||
return priv::key_format;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,13 @@
|
|||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <libeosio/WIF.hpp>
|
||||
|
||||
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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue