Skip to content

Commit 0f25d02

Browse files
committed
Simplify and unify "bls s2pk"
1 parent 424ecbc commit 0f25d02

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/rpc/rpcevo.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,10 @@ UniValue bls_generate(const JSONRPCRequest& request)
11711171
void bls_sk2pk_help()
11721172
{
11731173
throw std::runtime_error(
1174-
"bls sk2pk <secret-key>\n"
1174+
"bls sk2pk \"secret\"\n"
11751175
"\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"
11761178
"\nResult:\n"
11771179
"{\n"
11781180
" \"secret\": \"xxxx\", (string) BLS secret key\n"
@@ -1188,19 +1190,11 @@ UniValue bls_sk2pk(const JSONRPCRequest& request)
11881190
if (request.fHelp || request.params.size() != 2) {
11891191
bls_sk2pk_help();
11901192
}
1191-
std::string strBLSPrivKey;
1192-
strBLSPrivKey = request.params[1].get_str();
1193-
1194-
if (!IsHex(strBLSPrivKey)) {
1195-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Secret key must be a valid hex string of length 64");
1196-
}
1197-
auto b = ParseHex(strBLSPrivKey);
1198-
if (b.size() != 32) {
1199-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Secret key must be 32 bytes long, not %d", (int)b.size()));
1200-
}
12011193

12021194
CBLSSecretKey sk;
1203-
sk.SetBuf((const uint8_t*)b.data(), b.size());
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+
}
12041198

12051199
UniValue ret(UniValue::VOBJ);
12061200
ret.push_back(Pair("secret", sk.ToString()));

0 commit comments

Comments
 (0)