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 <format>
16#include <optional>
17#include <stdexcept>
18#include <string>
19#include <utility>
20
21namespace xrpl {
22
23std::pair<PublicKey, SecretKey>
24getNodeIdentity(Application& app, boost::program_options::variables_map const& cmdline)
25{
27
28 if (cmdline.contains("nodeid"))
29 {
30 seed = parseGenericSeed(cmdline["nodeid"].as<std::string>(), false);
31
32 if (!seed)
33 Throw<std::runtime_error>("Invalid 'nodeid' in command line");
34 }
35 else if (app.config().exists(Sections::kNodeSeed))
36 {
38
39 if (!seed)
40 {
42 std::format("Invalid [{}] in configuration file", Sections::kNodeSeed));
43 }
44 }
45
46 if (seed)
47 {
48 auto secretKey = generateSecretKey(KeyType::Secp256k1, *seed);
49 auto publicKey = derivePublicKey(KeyType::Secp256k1, secretKey);
50
51 return {publicKey, secretKey};
52 }
53
54 auto db = app.getWalletDB().checkoutDb();
55
56 if (cmdline.contains("newnodeid"))
58
59 return getNodeIdentity(*db);
60}
61
62} // 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:58
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
T format(T... args)
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:151
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:145
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
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:33