xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
admin
keygen
ValidationCreate.cpp
1
#include <xrpld/rpc/Context.h>
2
3
#include <xrpl/json/json_value.h>
4
#include <xrpl/protocol/ErrorCodes.h>
5
#include <xrpl/protocol/KeyType.h>
6
#include <xrpl/protocol/PublicKey.h>
7
#include <xrpl/protocol/RPCErr.h>
8
#include <xrpl/protocol/SecretKey.h>
9
#include <xrpl/protocol/Seed.h>
10
#include <xrpl/protocol/jss.h>
11
#include <xrpl/protocol/tokens.h>
12
13
#include <
optional
>
14
15
namespace
xrpl
{
16
17
static
std::optional<Seed>
18
validationSeed
(
json::Value
const
& params)
19
{
20
if
(!params.
isMember
(jss::secret))
21
return
randomSeed
();
22
23
return
parseGenericSeed
(params[jss::secret].asString());
24
}
25
26
// {
27
// secret: <string> // optional
28
// }
29
//
30
// This command requires Role::ADMIN access because it makes
31
// no sense to ask an untrusted server for this.
32
json::Value
33
doValidationCreate
(
rpc::JsonContext
& context)
34
{
35
json::Value
obj(
json::ValueType::Object
);
36
37
auto
seed =
validationSeed
(context.
params
);
38
39
if
(!seed)
40
return
rpcError
(
RpcBadSeed
);
41
42
auto
const
privateKey =
generateSecretKey
(
KeyType::Secp256k1
, *seed);
43
44
obj[jss::validation_public_key] =
45
toBase58
(
TokenType::NodePublic
,
derivePublicKey
(
KeyType::Secp256k1
, privateKey));
46
47
obj[jss::validation_private_key] =
toBase58
(
TokenType::NodePrivate
, privateKey);
48
49
obj[jss::validation_seed] =
toBase58
(*seed);
50
obj[jss::validation_key] =
seedAs1751
(*seed);
51
52
return
obj;
53
}
54
55
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::isMember
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition
json_value.cpp:1049
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::RpcBadSeed
@ RpcBadSeed
Definition
ErrorCodes.h:82
xrpl::derivePublicKey
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition
SecretKey.cpp:306
xrpl::doValidationCreate
json::Value doValidationCreate(rpc::JsonContext &context)
Definition
ValidationCreate.cpp:33
xrpl::randomSeed
Seed randomSeed()
Create a seed using secure random numbers.
Definition
Seed.cpp:48
xrpl::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition
AccountID.cpp:95
xrpl::generateSecretKey
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
Definition
SecretKey.cpp:284
xrpl::seedAs1751
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition
Seed.cpp:116
xrpl::rpcError
json::Value rpcError(ErrorCodeI iError)
Definition
RPCErr.cpp:13
xrpl::TokenType::NodePrivate
@ NodePrivate
Definition
tokens.h:22
xrpl::TokenType::NodePublic
@ NodePublic
Definition
tokens.h:21
xrpl::validationSeed
static std::optional< Seed > validationSeed(json::Value const ¶ms)
Definition
ValidationCreate.cpp:18
xrpl::parseGenericSeed
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition
Seed.cpp:79
optional
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::params
json::Value params
Definition
Context.h:51
Generated by
1.17.0