Skip to content

Commit

Permalink
Simplify and unify "bls s2pk"
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Apr 5, 2019
1 parent 424ecbc commit 0f25d02
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,10 @@ UniValue bls_generate(const JSONRPCRequest& request)
void bls_sk2pk_help()
{
throw std::runtime_error(
"bls sk2pk <secret-key>\n"
"bls sk2pk \"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"
Expand All @@ -1188,19 +1190,11 @@ UniValue bls_sk2pk(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() != 2) {
bls_sk2pk_help();
}
std::string strBLSPrivKey;
strBLSPrivKey = request.params[1].get_str();

if (!IsHex(strBLSPrivKey)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Secret key must be a valid hex string of length 64");
}
auto b = ParseHex(strBLSPrivKey);
if (b.size() != 32) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Secret key must be 32 bytes long, not %d", (int)b.size()));
}

CBLSSecretKey sk;
sk.SetBuf((const uint8_t*)b.data(), b.size());
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()));
Expand Down

0 comments on commit 0f25d02

Please sign in to comment.