Skip to content

Commit

Permalink
incorporate review comments to simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 committed Sep 12, 2023
1 parent 3501915 commit 1fae38e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion libraries/libfc/include/fc/crypto/bls_private_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace fc::crypto::blslib {

bls_public_key get_public_key() const;
bls_signature sign( const std::vector<uint8_t>& message ) const;
std::string get_pop_str() const;

// Returns proof of possession
bls_signature pop_proof() const;

static bls_private_key generate();

Expand Down
6 changes: 2 additions & 4 deletions libraries/libfc/src/crypto/bls_private_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 192> bytes = proof.toAffineBytesLE(raw);
return fc::crypto::blslib::serialize_base64<std::array<uint8_t, 192>>(bytes);
return bls_signature(proof);
}

bls_signature bls_private_key::sign( const std::vector<uint8_t>& message ) const
Expand Down
10 changes: 5 additions & 5 deletions programs/leap-util/actions/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/leap_util_bls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1fae38e

Please sign in to comment.