rai::pub_key function from library

This commit is contained in:
SergiySW 2018-08-03 18:11:51 +03:00
commit 16bb25aeee
3 changed files with 11 additions and 8 deletions

View file

@ -422,6 +422,13 @@ void rai::deterministic_key (rai::uint256_union const & seed_a, uint32_t index_a
blake2b_final (&hash, prv_a.bytes.data (), prv_a.bytes.size ());
}
rai::public_key rai::pub_key (rai::private_key const & privatekey_a)
{
rai::uint256_union result;
ed25519_publickey (privatekey_a.bytes.data (), result.bytes.data ());
return result;
}
bool rai::validate_message (rai::public_key const & public_key, rai::uint256_union const & message, rai::uint512_union const & signature)
{
auto result (0 != ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), public_key.bytes.data (), signature.bytes.data ()));

View file

@ -121,6 +121,7 @@ using signature = uint512_union;
rai::uint512_union sign_message (rai::raw_key const &, rai::public_key const &, rai::uint256_union const &);
bool validate_message (rai::public_key const &, rai::uint256_union const &, rai::uint512_union const &);
void deterministic_key (rai::uint256_union const &, uint32_t, rai::uint256_union &);
rai::public_key pub_key (rai::private_key const &);
}
namespace std

View file

@ -5,8 +5,6 @@
#include <rai/lib/interface.h>
#include <rai/node/node.hpp>
#include <ed25519-donna/ed25519.h>
#ifdef RAIBLOCKS_SECURE_RPC
#include <rai/node/rpc_secure.hpp>
#endif
@ -1141,8 +1139,7 @@ void rai::rpc_handler::block_create ()
}
if (prv.data != 0)
{
rai::uint256_union pub;
ed25519_publickey (prv.data.bytes.data (), pub.bytes.data ());
rai::uint256_union pub (rai::pub_key (prv.data));
// Fetching account balance & previous for send blocks (if aren't given directly)
if (!previous_text.is_initialized () && !balance_text.is_initialized ())
{
@ -1438,8 +1435,7 @@ void rai::rpc_handler::deterministic_key ()
uint32_t index (std::stoul (index_text));
rai::uint256_union prv;
rai::deterministic_key (seed.data, index, prv);
rai::uint256_union pub;
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
rai::uint256_union pub (rai::pub_key (prv));
response_l.put ("private", prv.to_string ());
response_l.put ("public", pub.to_string ());
response_l.put ("account", pub.to_account ());
@ -1733,8 +1729,7 @@ void rai::rpc_handler::key_expand ()
rai::uint256_union prv;
if (!prv.decode_hex (key_text))
{
rai::uint256_union pub;
ed25519_publickey (prv.bytes.data (), pub.bytes.data ());
rai::uint256_union pub (rai::pub_key (prv));
response_l.put ("private", prv.to_string ());
response_l.put ("public", pub.to_string ());
response_l.put ("account", pub.to_account ());