diff --git a/src/rpc/rpcevo.cpp b/src/rpc/rpcevo.cpp index 2f1ab5e7f..29f5e0e73 100644 --- a/src/rpc/rpcevo.cpp +++ b/src/rpc/rpcevo.cpp @@ -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(); }