From eab4aee8af40432df0dec559d3d4fd91997addcc Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 6 May 2021 15:09:36 +0200 Subject: [PATCH] WIF: add optional prefix parameter to wif_pub_encode() and wif_print_key(), defaults to "EOS" --- include/libeosio/WIF.hpp | 4 ++-- src/WIF.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/libeosio/WIF.hpp b/include/libeosio/WIF.hpp index 553481b..1667283 100644 --- a/include/libeosio/WIF.hpp +++ b/include/libeosio/WIF.hpp @@ -37,12 +37,12 @@ std::string wif_priv_encode(ec_privkey_t priv); /** * Encode an EC public key to WIF String. */ -std::string wif_pub_encode(ec_pubkey_t pub); +std::string wif_pub_encode(ec_pubkey_t pub, const std::string& prefix = "EOS"); /** * Prints an EC keypair in WIF format to standard out. */ -void wif_print_key(const struct ec_keypair *key); +void wif_print_key(const struct ec_keypair *key, const std::string& prefix = "EOS"); } // namespace libeosio diff --git a/src/WIF.cpp b/src/WIF.cpp index b07bcd3..fbbf2a7 100644 --- a/src/WIF.cpp +++ b/src/WIF.cpp @@ -46,7 +46,7 @@ std::string wif_priv_encode(ec_privkey_t priv) { return base58_encode(buf, buf + sizeof(buf)); } -std::string wif_pub_encode(ec_pubkey_t pub) { +std::string wif_pub_encode(ec_pubkey_t pub, const std::string& prefix) { checksum_t check = checksum_ripemd160(pub.data(), pub.size()); unsigned char buf[EC_PUBKEY_SIZE + CHECKSUM_SIZE]; @@ -54,12 +54,12 @@ std::string wif_pub_encode(ec_pubkey_t pub) { memcpy(buf, pub.data(), pub.size()); memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size()); - return "EOS" + base58_encode(buf, buf + sizeof(buf)); + return prefix.substr(0, 3) + base58_encode(buf, buf + sizeof(buf)); } -void wif_print_key(const struct ec_keypair *key) { +void wif_print_key(const struct ec_keypair *key, const std::string& prefix) { - std::cout << "Public: " << wif_pub_encode(key->pub) << std::endl; + std::cout << "Public: " << wif_pub_encode(key->pub, prefix) << std::endl; std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl; }