diff --git a/libraries/libfc/include/fc/crypto/bls_private_key.hpp b/libraries/libfc/include/fc/crypto/bls_private_key.hpp index 98799b42c5..c3cd2004ac 100644 --- a/libraries/libfc/include/fc/crypto/bls_private_key.hpp +++ b/libraries/libfc/include/fc/crypto/bls_private_key.hpp @@ -28,7 +28,9 @@ namespace fc::crypto::blslib { bls_public_key get_public_key() const; bls_signature sign( const std::vector& message ) const; - std::string get_pop_str() const; + + // Returns proof of possession + bls_signature pop_proof() const; static bls_private_key generate(); diff --git a/libraries/libfc/src/crypto/bls_private_key.cpp b/libraries/libfc/src/crypto/bls_private_key.cpp index 27db3c9baf..3fc4092967 100644 --- a/libraries/libfc/src/crypto/bls_private_key.cpp +++ b/libraries/libfc/src/crypto/bls_private_key.cpp @@ -13,12 +13,10 @@ namespace fc::crypto::blslib { return bls_public_key(pk); } - std::string bls_private_key::get_pop_str() const + bls_signature bls_private_key::pop_proof() const { bls12_381::g2 proof = bls12_381::pop_prove(_sk); - constexpr bool raw = true; - std::array bytes = proof.toAffineBytesLE(raw); - return fc::crypto::blslib::serialize_base64>(bytes); + return bls_signature(proof); } bls_signature bls_private_key::sign( const std::vector& message ) const diff --git a/programs/leap-util/actions/bls.cpp b/programs/leap-util/actions/bls.cpp index abff8fe624..4d43894aed 100644 --- a/programs/leap-util/actions/bls.cpp +++ b/programs/leap-util/actions/bls.cpp @@ -54,13 +54,13 @@ int bls_actions::create_key() { const bls_private_key private_key = bls_private_key::generate(); const bls_public_key public_key = private_key.get_public_key(); - // generate pop - const std::string pop_str = private_key.get_pop_str(); + // generate proof of possession + const bls_signature pop = private_key.pop_proof(); // prepare output std::string out_str = "Private key: " + private_key.to_string({}) + "\n"; out_str += "Public key: " + public_key.to_string({}) + "\n"; - out_str += "Proof of Possession: " + pop_str + "\n"; + out_str += "Proof of Possession: " + pop.to_string({}) + "\n"; if (opt->print_console) { std::cout << out_str; } else { @@ -106,9 +106,9 @@ int bls_actions::create_pop() { // create private key object using input private key string const bls_private_key private_key = bls_private_key(private_key_str); const bls_public_key public_key = private_key.get_public_key(); - std::string pop_str = private_key.get_pop_str(); + const bls_signature pop = private_key.pop_proof(); - std::cout << "Proof of Possession: " << pop_str << "\n"; + std::cout << "Proof of Possession: " << pop.to_string({})<< "\n"; std::cout << "Public key: " << public_key.to_string({}) << "\n"; return 0; diff --git a/tests/leap_util_bls_test.py b/tests/leap_util_bls_test.py index 6c07cb7787..fb7c77037f 100755 --- a/tests/leap_util_bls_test.py +++ b/tests/leap_util_bls_test.py @@ -100,12 +100,13 @@ def check_create_key_results(rslts): # check each output has valid value assert "PVT_BLS_" in results["Private key"] assert "PUB_BLS_" in results["Public key"] + assert "SIG_BLS_" in results["Proof of Possession"] def get_results(rslts): # sample output looks like # Private key: PVT_BLS_kRhJJ2MsM+/CddO... # Public key: PUB_BLS_lbUE8922wUfX0Iy5... - # Proof of Possession: 3jwkVUUYahHgsnmnEA... + # Proof of Possession: SIG_BLS_3jwkVUUYahHgsnmnEA... pattern = r'(\w+[^:]*): ([^\n]+)' matched= re.findall(pattern, rslts)