mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
Simplify and unify "bls s2pk"
This commit is contained in:
parent
424ecbc11c
commit
0f25d020b5
@ -1171,8 +1171,10 @@ UniValue bls_generate(const JSONRPCRequest& request)
|
|||||||
void bls_sk2pk_help()
|
void bls_sk2pk_help()
|
||||||
{
|
{
|
||||||
throw std::runtime_error(
|
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"
|
"\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"
|
"\nResult:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" \"secret\": \"xxxx\", (string) BLS secret key\n"
|
" \"secret\": \"xxxx\", (string) BLS secret key\n"
|
||||||
@ -1188,19 +1190,11 @@ UniValue bls_sk2pk(const JSONRPCRequest& request)
|
|||||||
if (request.fHelp || request.params.size() != 2) {
|
if (request.fHelp || request.params.size() != 2) {
|
||||||
bls_sk2pk_help();
|
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;
|
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);
|
UniValue ret(UniValue::VOBJ);
|
||||||
ret.push_back(Pair("secret", sk.ToString()));
|
ret.push_back(Pair("secret", sk.ToString()));
|
||||||
|
Loading…
Reference in New Issue
Block a user