diff --git a/cli/src/cli_key_search_result.cpp b/cli/src/cli_key_search_result.cpp index fa3d009..d0cc9fd 100644 --- a/cli/src/cli_key_search_result.cpp +++ b/cli/src/cli_key_search_result.cpp @@ -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 diff --git a/cli/src/cli_key_search_result.hpp b/cli/src/cli_key_search_result.hpp index a81a877..254ee8f 100644 --- a/cli/src/cli_key_search_result.hpp +++ b/cli/src/cli_key_search_result.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/cli/src/main.cpp b/cli/src/main.cpp index 74a7aa0..ddb8dc6 100644 --- a/cli/src/main.cpp +++ b/cli/src/main.cpp @@ -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 dict_list; std::vector 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; }