[BW]: [NIP] Added public_key::to_base58 text conversion to simplify contact display_name generation at bts side.

This commit is contained in:
vogel76 2014-03-03 11:30:23 +01:00
parent ecba7c5076
commit 163be8a6d0
2 changed files with 20 additions and 1 deletions

View file

@ -57,6 +57,10 @@ namespace fc {
{
return a.serialize() != b.serialize();
}
/// Allows to convert current public key object into base58 number.
std::string to_base58() const;
private:
friend class private_key;
fc::fwd<detail::public_key_impl,8> my;

View file

@ -1,8 +1,12 @@
#include <fc/crypto/elliptic.hpp>
#include <fc/crypto/base58.hpp>
#include <fc/crypto/openssl.hpp>
#include <fc/fwd_impl.hpp>
#include <fc/exception/exception.hpp>
#include <fc/log/logger.hpp>
#include <fc/crypto/openssl.hpp>
#include <assert.h>
namespace fc { namespace ecc {
@ -257,6 +261,17 @@ namespace fc { namespace ecc {
} FC_RETHROW_EXCEPTIONS( debug, "digest: ${digest}", ("digest",digest) );
}
std::string public_key::to_base58() const
{
public_key_data key = serialize();
uint32_t check = uint32_t(city_hash64(key.data, sizeof(key)));
assert(key.size() + sizeof(check) == 37);
array<char, 37> data;
memcpy(data.data, key.begin(), key.size());
memcpy(data.begin() + key.size(), (const char*)&check, sizeof(check));
return fc::to_base58(data.begin(), data.size());
}
private_key::private_key()
{}