rippled
Loading...
Searching...
No Matches
ValidationCreate.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/rpc/Context.h>
21
22#include <xrpl/protocol/ErrorCodes.h>
23#include <xrpl/protocol/RPCErr.h>
24#include <xrpl/protocol/Seed.h>
25#include <xrpl/protocol/jss.h>
26
27namespace ripple {
28
31{
32 if (!params.isMember(jss::secret))
33 return randomSeed();
34
35 return parseGenericSeed(params[jss::secret].asString());
36}
37
38// {
39// secret: <string> // optional
40// }
41//
42// This command requires Role::ADMIN access because it makes
43// no sense to ask an untrusted server for this.
46{
48
49 auto seed = validationSeed(context.params);
50
51 if (!seed)
52 return rpcError(rpcBAD_SEED);
53
54 auto const private_key = generateSecretKey(KeyType::secp256k1, *seed);
55
56 obj[jss::validation_public_key] = toBase58(
59
60 obj[jss::validation_private_key] =
61 toBase58(TokenType::NodePrivate, private_key);
62
63 obj[jss::validation_seed] = toBase58(*seed);
64 obj[jss::validation_key] = seedAs1751(*seed);
65
66 return obj;
67}
68
69} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:962
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:46
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:114
Json::Value doValidationCreate(RPC::JsonContext &)
@ rpcBAD_SEED
Definition: ErrorCodes.h:99
Seed randomSeed()
Create a seed using secure random numbers.
Definition: Seed.cpp:66
static std::optional< Seed > validationSeed(Json::Value const &params)
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:31
std::string seedAs1751(Seed const &seed)
Encode a Seed in RFC1751 format.
Definition: Seed.cpp:135
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition: SecretKey.cpp:331
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
Definition: SecretKey.cpp:309
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition: Seed.cpp:97
Json::Value params
Definition: Context.h:63