rippled
Loading...
Searching...
No Matches
NodeIdentity.cpp
1#include <xrpld/app/main/Application.h>
2#include <xrpld/app/main/NodeIdentity.h>
3#include <xrpld/app/rdb/Wallet.h>
4#include <xrpld/core/Config.h>
5#include <xrpld/core/ConfigSections.h>
6
7namespace ripple {
8
11 Application& app,
12 boost::program_options::variables_map const& cmdline)
13{
15
16 if (cmdline.count("nodeid"))
17 {
18 seed = parseGenericSeed(cmdline["nodeid"].as<std::string>(), false);
19
20 if (!seed)
21 Throw<std::runtime_error>("Invalid 'nodeid' in command line");
22 }
23 else if (app.config().exists(SECTION_NODE_SEED))
24 {
25 seed = parseBase58<Seed>(
26 app.config().section(SECTION_NODE_SEED).lines().front());
27
28 if (!seed)
29 Throw<std::runtime_error>("Invalid [" SECTION_NODE_SEED
30 "] in configuration file");
31 }
32
33 if (seed)
34 {
35 auto secretKey = generateSecretKey(KeyType::secp256k1, *seed);
36 auto publicKey = derivePublicKey(KeyType::secp256k1, secretKey);
37
38 return {publicKey, secretKey};
39 }
40
41 auto db = app.getWalletDB().checkoutDb();
42
43 if (cmdline.count("newnodeid") != 0)
45
46 return getNodeIdentity(*db);
47}
48
49} // namespace ripple
virtual Config & config()=0
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
LockedSociSession checkoutDb()
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition BasicConfig.h:51
T front(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::pair< PublicKey, SecretKey > getNodeIdentity(Application &app, boost::program_options::variables_map const &cmdline)
The cryptographic credentials identifying this server instance.
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.
void clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
Definition Wallet.cpp:108
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition Seed.cpp:78