Skip to content

Commit

Permalink
Add RPC for BLS secret to public key (#2841)
Browse files Browse the repository at this point in the history
* Add RPC for BLS secret to public key

* Simplify and unify "bls s2pk"

* Reuse "generate"

* Revert "Reuse "generate""

This reverts commit c12388c.

* Rename sk2pk to fromsecret
  • Loading branch information
nmarley authored and UdjinM6 committed Apr 8, 2019
1 parent 2c72c07 commit 0f0d8ea
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,40 @@ UniValue bls_generate(const JSONRPCRequest& request)
return ret;
}

void bls_fromsecret_help()
{
throw std::runtime_error(
"bls fromsecret \"secret\"\n"
"\nParses a BLS secret key and returns the secret/public key pair.\n"
"\nArguments:\n"
"1. \"secret\" (string, required) The BLS secret key\n"
"\nResult:\n"
"{\n"
" \"secret\": \"xxxx\", (string) BLS secret key\n"
" \"public\": \"xxxx\", (string) BLS public key\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("bls fromsecret", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
);
}

UniValue bls_fromsecret(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2) {
bls_fromsecret_help();
}

CBLSSecretKey sk;
if (!sk.SetHexStr(request.params[1].get_str())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Secret key must be a valid hex string of length %d", sk.SerSize*2));
}

UniValue ret(UniValue::VOBJ);
ret.push_back(Pair("secret", sk.ToString()));
ret.push_back(Pair("public", sk.GetPublicKey().ToString()));
return ret;
}

[[ noreturn ]] void bls_help()
{
throw std::runtime_error(
Expand All @@ -1178,6 +1212,7 @@ UniValue bls_generate(const JSONRPCRequest& request)
"1. \"command\" (string, required) The command to execute\n"
"\nAvailable commands:\n"
" generate - Create a BLS secret/public key pair\n"
" fromsecret - Parse a BLS secret key and return the secret/public key pair\n"
);
}

Expand All @@ -1194,6 +1229,8 @@ UniValue _bls(const JSONRPCRequest& request)

if (command == "generate") {
return bls_generate(request);
} else if (command == "fromsecret") {
return bls_fromsecret(request);
} else {
bls_help();
}
Expand Down

0 comments on commit 0f0d8ea

Please sign in to comment.