xrpld
Loading...
Searching...
No Matches
NodeIdentity.cpp
1#include <xrpld/app/main/NodeIdentity.h>
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/core/Config.h>
5
6#include <xrpl/basics/contract.h>
7#include <xrpl/config/Constants.h>
8#include <xrpl/protocol/KeyType.h>
9#include <xrpl/protocol/SecretKey.h>
10#include <xrpl/protocol/Seed.h>
11#include <xrpl/server/Wallet.h>
12
13#include <boost/program_options/variables_map.hpp>
14
15#include <optional>
16#include <stdexcept>
17#include <string>
18#include <utility>
19
20namespace xrpl {
21
22std::pair<PublicKey, SecretKey>
23getNodeIdentity(Application& app, boost::program_options::variables_map const& cmdline)
24{
26
27 if (cmdline.contains("nodeid"))
28 {
29 seed = parseGenericSeed(cmdline["nodeid"].as<std::string>(), false);
30
31 if (!seed)
32 Throw<std::runtime_error>("Invalid 'nodeid' in command line");
33 }
34 else if (app.config().exists(Sections::kNodeSeed))
35 {
37
38 if (!seed)
39 {
41 std::string("Invalid [") + Sections::kNodeSeed + "] in configuration file");
42 }
43 }
44
45 if (seed)
46 {
47 auto secretKey = generateSecretKey(KeyType::Secp256k1, *seed);
48 auto publicKey = derivePublicKey(KeyType::Secp256k1, secretKey);
49
50 return {publicKey, secretKey};
51 }
52
53 auto db = app.getWalletDB().checkoutDb();
54
55 if (cmdline.contains("newnodeid"))
57
58 return getNodeIdentity(*db);
59}
60
61} // namespace xrpl
virtual Config & config()=0
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:49
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
T front(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::pair< PublicKey, SecretKey > getNodeIdentity(soci::session &session)
Returns a stable public and private key for this node.
Definition Wallet.cpp:138
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:132
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition Seed.cpp:79
static constexpr auto kNodeSeed
Definition Constants.h:32