From 163be8a6d0d4cb73fd2e45a7ec34db756d6a46f7 Mon Sep 17 00:00:00 2001 From: vogel76 Date: Mon, 3 Mar 2014 11:30:23 +0100 Subject: [PATCH] [BW]: [NIP] Added public_key::to_base58 text conversion to simplify contact display_name generation at bts side. --- include/fc/crypto/elliptic.hpp | 4 ++++ src/crypto/elliptic.cpp | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/fc/crypto/elliptic.hpp b/include/fc/crypto/elliptic.hpp index d507051..ac411a0 100644 --- a/include/fc/crypto/elliptic.hpp +++ b/include/fc/crypto/elliptic.hpp @@ -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 my; diff --git a/src/crypto/elliptic.cpp b/src/crypto/elliptic.cpp index 9654096..dda84f2 100644 --- a/src/crypto/elliptic.cpp +++ b/src/crypto/elliptic.cpp @@ -1,8 +1,12 @@ #include + +#include +#include + #include #include #include -#include + #include 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 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() {}