From 171db63de40e8916541066f612361d4af9fbc118 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 25 Mar 2023 18:14:51 +0100 Subject: [PATCH] include/libeosio/WIF.hpp: Adding WIF_SIG_K1 constant. --- include/libeosio/WIF.hpp | 2 +- src/WIF.cpp | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/libeosio/WIF.hpp b/include/libeosio/WIF.hpp index 07f2a94..040c392 100644 --- a/include/libeosio/WIF.hpp +++ b/include/libeosio/WIF.hpp @@ -36,7 +36,7 @@ const std::string WIF_PUB_LEG = "EOS"; const std::string WIF_PUB_K1 = "PUB_K1_"; const std::string WIF_PVT_LEG = ""; const std::string WIF_PVT_K1 = "PVT_K1_"; - +const std::string WIF_SIG_K1 = "SIG_K1_"; /** * Encode an EC private key to WIF String. diff --git a/src/WIF.cpp b/src/WIF.cpp index 0ace329..aa07c3b 100644 --- a/src/WIF.cpp +++ b/src/WIF.cpp @@ -139,16 +139,12 @@ bool wif_sig_decode(ec_signature_t& sig, const std::string& data) { checksum_t checksum; std::vector buf; - if (data.substr(0, 7) != "SIG_K1_") { + if (data.substr(0, WIF_SIG_K1.length()) != WIF_SIG_K1) { // Invalid prefix return false; } - if (!base58_decode(data.c_str() + 7, buf)) { - return false; - } - - if (buf.size() != EC_SIGNATURE_SIZE + CHECKSUM_SIZE) { + if (!base58_decode(data.c_str() + WIF_SIG_K1.length(), buf)) { return false; } @@ -173,7 +169,7 @@ std::string wif_sig_encode(const ec_signature_t& sig) { memcpy(buf, sig.data(), sig.size()); memcpy(buf + EC_SIGNATURE_SIZE, check.data(), check.size()); - return "SIG_K1_" + base58_encode(buf, buf + sizeof(buf)); + return WIF_SIG_K1_" + base58_encode(buf, buf + sizeof(buf)); } } // namespace libeosio