Skip to content

Commit 0f0d8ea

Browse files
nmarleyUdjinM6
authored andcommitted
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 c12388c. * Rename sk2pk to fromsecret
1 parent 2c72c07 commit 0f0d8ea

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/rpc/rpcevo.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,40 @@ UniValue bls_generate(const JSONRPCRequest& request)
11681168
return ret;
11691169
}
11701170

1171+
void bls_fromsecret_help()
1172+
{
1173+
throw std::runtime_error(
1174+
"bls fromsecret \"secret\"\n"
1175+
"\nParses a BLS secret key and returns the secret/public key pair.\n"
1176+
"\nArguments:\n"
1177+
"1. \"secret\" (string, required) The BLS secret key\n"
1178+
"\nResult:\n"
1179+
"{\n"
1180+
" \"secret\": \"xxxx\", (string) BLS secret key\n"
1181+
" \"public\": \"xxxx\", (string) BLS public key\n"
1182+
"}\n"
1183+
"\nExamples:\n"
1184+
+ HelpExampleCli("bls fromsecret", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
1185+
);
1186+
}
1187+
1188+
UniValue bls_fromsecret(const JSONRPCRequest& request)
1189+
{
1190+
if (request.fHelp || request.params.size() != 2) {
1191+
bls_fromsecret_help();
1192+
}
1193+
1194+
CBLSSecretKey sk;
1195+
if (!sk.SetHexStr(request.params[1].get_str())) {
1196+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Secret key must be a valid hex string of length %d", sk.SerSize*2));
1197+
}
1198+
1199+
UniValue ret(UniValue::VOBJ);
1200+
ret.push_back(Pair("secret", sk.ToString()));
1201+
ret.push_back(Pair("public", sk.GetPublicKey().ToString()));
1202+
return ret;
1203+
}
1204+
11711205
[[ noreturn ]] void bls_help()
11721206
{
11731207
throw std::runtime_error(
@@ -1178,6 +1212,7 @@ UniValue bls_generate(const JSONRPCRequest& request)
11781212
"1. \"command\" (string, required) The command to execute\n"
11791213
"\nAvailable commands:\n"
11801214
" generate - Create a BLS secret/public key pair\n"
1215+
" fromsecret - Parse a BLS secret key and return the secret/public key pair\n"
11811216
);
11821217
}
11831218

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

11951230
if (command == "generate") {
11961231
return bls_generate(request);
1232+
} else if (command == "fromsecret") {
1233+
return bls_fromsecret(request);
11971234
} else {
11981235
bls_help();
11991236
}

0 commit comments

Comments
 (0)