5namespace fc {
namespace crypto {
9 template<
typename KeyType>
27 template<
typename KeyType>
28 signature::storage_type
operator()(
const KeyType& key)
const
47 template<
typename KeyType>
50 using PublicKeyType =
typename KeyType::public_key_type;
51 return key.generate_shared_secret(std::template get<PublicKeyType>(
_pub_storage));
62 template<
typename Data>
65 const size_t size_of_data_to_hash =
sizeof(
typename Data::data_type) + 1;
66 const size_t size_of_hash_bytes = 4;
67 char data[size_of_data_to_hash + size_of_hash_bytes];
69 memcpy(&data[1], (
const char*)&secret.serialize(),
sizeof(
typename Data::data_type));
72 memcpy(data + size_of_data_to_hash, (
char*)&
digest, size_of_hash_bytes);
73 return to_base58(data,
sizeof(data), yield);
76 template<
typename Data>
81 auto key_bytes =
vector<char>(wif_bytes.begin() + 1, wif_bytes.end() - 4);
85 FC_ASSERT(memcmp( (
char*)&check, wif_bytes.data() + wif_bytes.size() - 4, 4 ) == 0 ||
86 memcmp( (
char*)&check2, wif_bytes.
data() + wif_bytes.size() - 4, 4 ) == 0 );
93 const auto pivot = base58str.find(
'_');
95 if (pivot == std::string::npos) {
97 using default_type = std::variant_alternative_t<0, private_key::storage_type>;
100 constexpr auto prefix = config::private_key_base_prefix;
101 const auto prefix_str = base58str.substr(0, pivot);
102 FC_ASSERT(prefix == prefix_str,
"Private Key has invalid prefix: ${str}", (
"str", base58str)(
"prefix_str", prefix_str));
104 auto data_str = base58str.substr(pivot + 1);
105 FC_ASSERT(!data_str.empty(),
"Private Key has no data: ${str}", (
"str", base58str));
106 return base58_str_parser<private_key::storage_type, config::private_key_prefix>::apply(data_str);
111 :_storage(priv_parse_base58(base58str))
116 auto which = _storage.index();
119 using default_type = std::variant_alternative_t<0, private_key::storage_type>;
120 return to_wif(std::template get<default_type>(_storage), yield);
124 return std::string(config::private_key_base_prefix) +
"_" + data_str;
std::string to_string(const fc::yield_function_t &yield=fc::yield_function_t()) const
std::variant< ecc::private_key_shim, r1::private_key_shim, em::private_key_shim > storage_type
public_key get_public_key() const
signature sign(const sha256 &digest, bool require_canonical=true) const
sha512 generate_shared_secret(const public_key &pub) const
std::variant< ecc::public_key_shim, r1::public_key_shim, webauthn::public_key, em::public_key_shim > storage_type
static sha256 hash(const char *d, uint32_t dlen)
const char * data() const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
string to_wif(const Data &secret, const fc::yield_function_t &yield)
std::ostream & operator<<(std::ostream &s, const private_key &k)
bool operator<(const private_key &p1, const private_key &p2)
Data from_wif(const string &wif_key)
bool operator==(const private_key &p1, const private_key &p2)
std::string to_base58(const char *d, size_t s, const fc::yield_function_t &yield)
fc::sha256 digest(const T &value)
std::vector< char > from_base58(const std::string &base58_str)
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
static bool apply(const T &a, const T &b)
generate_shared_secret_visitor(const public_key::storage_type &pub_storage)
const public_key::storage_type & _pub_storage
sha512 operator()(const KeyType &key) const
static bool apply(const T &a, const T &b)
public_key::storage_type operator()(const KeyType &key) const
signature::storage_type operator()(const KeyType &key) const
sign_visitor(const sha256 &digest, bool require_canonical)
memcpy((char *) pInfo->slotDescription, s, l)