Adds a cryptography API.

This commit is contained in:
Michael Vandeberg 2016-01-06 11:02:20 -05:00
parent 51c10580fa
commit acfbad2cd4
2 changed files with 128 additions and 1 deletions

View file

@ -37,7 +37,7 @@
#include <fc/smart_ref_impl.hpp>
namespace graphene { namespace app {
login_api::login_api(application& a)
:_app(a)
{
@ -87,6 +87,10 @@ namespace graphene { namespace app {
{
_network_node_api = std::make_shared< network_node_api >( std::ref(_app) );
}
else if( api_name == "crypto_api" )
{
_crypto_api = std::make_shared< crypto_api >( std::ref(_app) );
}
return;
}
@ -196,6 +200,12 @@ namespace graphene { namespace app {
FC_ASSERT(_history_api);
return *_history_api;
}
fc::api<crypto_api> login_api::crypto() const
{
FC_ASSERT(_crypto_api);
return *_crypto_api;
}
vector<account_id_type> get_relevant_accounts( const object* obj )
{
@ -405,5 +415,67 @@ namespace graphene { namespace app {
}
return result;
} FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) }
blind_signature crypto_api::blind_sign( extended_private_key key, const blinded_hash& hash, int i ) const
{
return key.blind_sign( hash, i );
}
compact_signature crypto_api::unblind_signature( extended_private_key key,
const extended_public_key& bob,
const blind_signature& sig,
const fc::sha256& hash,
int i ) const
{
return key.unblind_signature( bob, sig, hash, i );
}
commitment_type crypto_api::blind( const blind_factor_type& blind, uint64_t value )
{
return fc::ecc::blind( blind, value );
}
blind_factor_type crypto_api::blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg )
{
return fc::ecc::blind_sum( blinds_in, non_neg );
}
bool crypto_api::verify_sum( const std::vector<commitment_type>& commits_in, const std::vector<commitment_type>& neg_commits_in, int64_t excess )
{
return fc::ecc::verify_sum( commits_in, neg_commits_in, excess );
}
bool crypto_api::verify_range( uint64_t& min_val, uint64_t& max_val, const commitment_type& commit, const std::vector<char>& proof )
{
return fc::ecc::verify_range( min_val, max_val, commit, proof );
}
std::vector<char> crypto_api::range_proof_sign( uint64_t min_value,
const commitment_type& commit,
const blind_factor_type& commit_blind,
const blind_factor_type& nonce,
int8_t base10_exp,
uint8_t min_bits,
uint64_t actual_value )
{
return fc::ecc::range_proof_sign( min_value, commit, commit_blind, nonce, base10_exp, min_bits, actual_value );
}
bool crypto_api::verify_range_proof_rewind( blind_factor_type& blind_out,
uint64_t& value_out,
string& message_out,
const blind_factor_type& nonce,
uint64_t& min_val,
uint64_t& max_val,
commitment_type commit,
const std::vector<char>& proof )
{
return fc::ecc::verify_range_proof_rewind( blind_out, value_out, message_out, nonce, min_val, max_val, commit, proof );
}
range_proof_info crypto_ap::range_get_info( const std::vector<char>& proof )
{
return fc::ecc::range_get_info( proof );
}
} } // graphene::app

View file

@ -30,6 +30,7 @@
#include <fc/api.hpp>
#include <fc/optional.hpp>
#include <fc/crypto/elliptic.hpp>
#include <fc/network/ip.hpp>
#include <boost/container/flat_set.hpp>
@ -42,6 +43,7 @@
namespace graphene { namespace app {
using namespace graphene::chain;
using namespace graphene::market_history;
using namespace fc::ecc;
using namespace std;
class application;
@ -173,6 +175,45 @@ namespace graphene { namespace app {
private:
application& _app;
};
class crypto_api
{
public:
blind_signature blind_sign( extended_private_key key, const blinded_hash& hash, int i ) const;
compact_signature unblind_signature( extended_private_key key,
const extended_public_key& bob,
const blind_signature& sig,
const fc::sha256& hash,
int i ) const;
commitment_type blind( const blind_factor_type& blind, uint64_t value );
blind_factor_type blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg );
bool verify_sum( const std::vector<commitment_type>& commits_in, const std::vector<commitment_type>& neg_commits_in, int64_t excess );
bool verify_range( uint64_t& min_val, uint64_t& max_val, const commitment_type& commit, const std::vector<char>& proof );
std::vector<char> range_proof_sign( uint64_t min_value,
const commitment_type& commit,
const blind_factor_type& commit_blind,
const blind_factor_type& nonce,
int8_t base10_exp,
uint8_t min_bits,
uint64_t actual_value );
bool verify_range_proof_rewind( blind_factor_type& blind_out,
uint64_t& value_out,
string& message_out,
const blind_factor_type& nonce,
uint64_t& min_val,
uint64_t& max_val,
commitment_type commit,
const std::vector<char>& proof );
range_proof_info range_get_info( const std::vector<char>& proof );
};
/**
* @brief The login_api class implements the bottom layer of the RPC API
@ -203,6 +244,8 @@ namespace graphene { namespace app {
fc::api<history_api> history()const;
/// @brief Retrieve the network node API
fc::api<network_node_api> network_node()const;
/// @brief Retrieve the cryptography API
fc::api<crypto_apI> crypto()const;
private:
/// @brief Called to enable an API, not reflected.
@ -213,6 +256,7 @@ namespace graphene { namespace app {
optional< fc::api<network_broadcast_api> > _network_broadcast_api;
optional< fc::api<network_node_api> > _network_node_api;
optional< fc::api<history_api> > _history_api;
optional< fc::api<crypto_api> _crypto_api;
};
}} // graphene::app
@ -239,10 +283,21 @@ FC_API(graphene::app::network_node_api,
(get_advanced_node_parameters)
(set_advanced_node_parameters)
)
FC_API(graphene::app::crypto_api,
(blind_sign)
(unblind_signature)
(blind)
(blind_sum)
(verify_sum)
(verify_range)
(range_proof_sign)
(verify_range_proof_rewind)
(range_get_info))
FC_API(graphene::app::login_api,
(login)
(network_broadcast)
(database)
(history)
(network_node)
(crypto)
)