mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-16 03:34:56 +02:00
src/WIF.cpp: use wif/codec.hpp
This commit is contained in:
parent
053f91c74b
commit
ea411793a2
2 changed files with 11 additions and 22 deletions
|
|
@ -53,6 +53,8 @@ add_library( ${LIB_NAME} STATIC
|
|||
src/base58.cpp
|
||||
src/ec.cpp
|
||||
src/WIF.cpp
|
||||
src/wif/k1.cpp
|
||||
src/wif/legacy.cpp
|
||||
|
||||
src/openssl/hash.cpp
|
||||
)
|
||||
|
|
|
|||
31
src/WIF.cpp
31
src/WIF.cpp
|
|
@ -26,6 +26,7 @@
|
|||
#include <libeosio/base58.hpp>
|
||||
#include <libeosio/checksum.hpp>
|
||||
#include <libeosio/WIF.hpp>
|
||||
#include "wif/codec.hpp"
|
||||
|
||||
namespace libeosio {
|
||||
|
||||
|
|
@ -91,36 +92,33 @@ std::string wif_pub_encode(const ec_pubkey_t& pub, const std::string& prefix) {
|
|||
|
||||
checksum_t check;
|
||||
unsigned char buf[EC_PUBKEY_SIZE + CHECKSUM_SIZE];
|
||||
|
||||
memcpy(buf, pub.data(), pub.size());
|
||||
|
||||
internal::pub_encoder_t encoder;
|
||||
|
||||
if (prefix == WIF_PUB_K1) {
|
||||
check = _checksum_suffix(buf, EC_PUBKEY_SIZE, "K1");
|
||||
encoder = internal::pub_encoder_k1;
|
||||
}
|
||||
// Legacy
|
||||
else {
|
||||
check = checksum_ripemd160(pub.data(), pub.size());
|
||||
encoder = internal::pub_encoder_legacy;
|
||||
}
|
||||
|
||||
memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.size());
|
||||
encoder(pub, buf);
|
||||
|
||||
return prefix + base58_encode(buf, buf + sizeof(buf));
|
||||
}
|
||||
|
||||
bool wif_pub_decode(ec_pubkey_t& pub, const std::string& data) {
|
||||
|
||||
const char *suffix;
|
||||
internal::pub_decoder_t decoder = internal::pub_decoder_legacy;
|
||||
int offset;
|
||||
std::vector<unsigned char> buf;
|
||||
|
||||
// Check prefix
|
||||
if (data.substr(0, WIF_PUB_K1.size()) == WIF_PUB_K1) {
|
||||
suffix = "K1";
|
||||
offset = WIF_PUB_K1.size();
|
||||
decoder = internal::pub_decoder_k1;
|
||||
offset = WIF_PUB_K1.size();
|
||||
} else {
|
||||
// Legacy
|
||||
suffix = "";
|
||||
offset = 3;
|
||||
}
|
||||
|
||||
|
|
@ -132,18 +130,7 @@ bool wif_pub_decode(ec_pubkey_t& pub, const std::string& data) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (suffix[0] != '\0') {
|
||||
checksum_t check = _checksum_suffix(buf.data(), EC_PUBKEY_SIZE, suffix);
|
||||
if (memcmp(buf.data() + EC_PUBKEY_SIZE, check.data(), CHECKSUM_SIZE)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!checksum_validate<checksum_ripemd160>(buf.data(), buf.size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy data to output
|
||||
memcpy(pub.data(), buf.data(), pub.size());
|
||||
return true;
|
||||
return decoder(buf, pub);
|
||||
}
|
||||
|
||||
void wif_print_key(const struct ec_keypair *key, const std::string& prefix) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue