mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-18 20:40:03 +02:00
WIF: add optional prefix parameter to wif_pub_encode() and wif_print_key(), defaults to "EOS"
This commit is contained in:
parent
19f6149e1e
commit
eab4aee8af
2 changed files with 6 additions and 6 deletions
|
|
@ -37,12 +37,12 @@ std::string wif_priv_encode(ec_privkey_t priv);
|
||||||
/**
|
/**
|
||||||
* Encode an EC public key to WIF String.
|
* 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.
|
* 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
|
} // namespace libeosio
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ std::string wif_priv_encode(ec_privkey_t priv) {
|
||||||
return base58_encode(buf, buf + sizeof(buf));
|
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());
|
checksum_t check = checksum_ripemd160(pub.data(), pub.size());
|
||||||
unsigned char buf[EC_PUBKEY_SIZE + CHECKSUM_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, pub.data(), pub.size());
|
||||||
memcpy(buf + EC_PUBKEY_SIZE, check.data(), check.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;
|
std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue