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

cli: implement support for K1 keys (default, can be switched with --legacy flag)

This commit is contained in:
Henrik Hautakoski 2023-04-04 18:58:14 +02:00
parent cbe6902d03
commit e18886e074
3 changed files with 25 additions and 14 deletions

View file

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

View file

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

View file

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