Add RPC for BLS secret to public key (#2841)
* Add RPC for BLS secret to public key * Simplify and unify "bls s2pk" * Reuse "generate" * Revert "Reuse "generate"" This reverts commit c12388c5b5d54f6b8221c1e086e916426bb331c4. * Rename sk2pk to fromsecret
This commit is contained in:
parent
2c72c075af
commit
0f0d8eaf48
@ -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(
|
||||
@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user