diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index dfc43420..20e3a058 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -37,7 +37,7 @@ #include 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 login_api::crypto() const + { + FC_ASSERT(_crypto_api); + return *_crypto_api; + } vector 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& blinds_in, uint32_t non_neg ) + { + return fc::ecc::blind_sum( blinds_in, non_neg ); + } + + bool crypto_api::verify_sum( const std::vector& commits_in, const std::vector& 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& proof ) + { + return fc::ecc::verify_range( min_val, max_val, commit, proof ); + } + + std::vector 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& 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& proof ) + { + return fc::ecc::range_get_info( proof ); + } } } // graphene::app diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 30d0d048..a897f99a 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -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& blinds_in, uint32_t non_neg ); + + bool verify_sum( const std::vector& commits_in, const std::vector& neg_commits_in, int64_t excess ); + + bool verify_range( uint64_t& min_val, uint64_t& max_val, const commitment_type& commit, const std::vector& proof ); + + std::vector 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& proof ); + + range_proof_info range_get_info( const std::vector& 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()const; /// @brief Retrieve the network node API fc::api network_node()const; + /// @brief Retrieve the cryptography API + fc::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; optional< fc::api > _network_node_api; optional< fc::api > _history_api; + optional< fc::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) )