rippled
Loading...
Searching...
No Matches
ValidationCreate.cpp
1#include <xrpld/rpc/Context.h>
2
3#include <xrpl/protocol/ErrorCodes.h>
4#include <xrpl/protocol/RPCErr.h>
5#include <xrpl/protocol/Seed.h>
6#include <xrpl/protocol/jss.h>
7
8namespace ripple {
9
12{
13 if (!params.isMember(jss::secret))
14 return randomSeed();
15
16 return parseGenericSeed(params[jss::secret].asString());
17}
18
19// {
20// secret: <string> // optional
21// }
22//
23// This command requires Role::ADMIN access because it makes
24// no sense to ask an untrusted server for this.
27{
29
30 auto seed = validationSeed(context.params);
31
32 if (!seed)
33 return rpcError(rpcBAD_SEED);
34
35 auto const private_key = generateSecretKey(KeyType::secp256k1, *seed);
36
37 obj[jss::validation_public_key] = toBase58(
40
41 obj[jss::validation_private_key] =
42 toBase58(TokenType::NodePrivate, private_key);
43
44 obj[jss::validation_seed] = toBase58(*seed);
45 obj[jss::validation_key] = seedAs1751(*seed);
46
47 return obj;
48}
49
50} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
bool isMember(char const *key) const
Return true if the object has a member named key.
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
Json::Value doValidationCreate(RPC::JsonContext &)
@ rpcBAD_SEED
Definition ErrorCodes.h:80
Seed randomSeed()
Create a seed using secure random numbers.
Definition Seed.cpp:47
static std::optional< Seed > validationSeed(Json::Value const &params)
Json::Value rpcError(int iError)
Definition RPCErr.cpp:12
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition Seed.cpp:116
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition Seed.cpp:78