xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
app
main
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
21
namespace
xrpl
{
22
23
std::pair<PublicKey, SecretKey>
24
getNodeIdentity
(
Application
& app, boost::program_options::variables_map
const
& cmdline)
25
{
26
std::optional<Seed>
seed;
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
{
37
seed =
parseBase58<Seed>
(app.
config
().
section
(
Sections::kNodeSeed
).
lines
().
front
());
38
39
if
(!seed)
40
{
41
Throw<std::runtime_error>
(
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"
))
57
clearNodeIdentity
(*db);
58
59
return
getNodeIdentity
(*db);
60
}
61
62
}
// namespace xrpl
xrpl::Application
Definition
Application.h:94
xrpl::Application::config
virtual Config & config()=0
xrpl::BasicConfig::exists
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Definition
BasicConfig.cpp:115
xrpl::BasicConfig::section
Section & section(std::string const &name)
Returns the section with the given name.
Definition
BasicConfig.cpp:121
xrpl::DatabaseCon::checkoutDb
LockedSociSession checkoutDb()
Definition
DatabaseCon.h:177
xrpl::Section::lines
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition
BasicConfig.h:58
xrpl::ServiceRegistry::getWalletDB
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
std::format
T format(T... args)
std::vector::front
T front(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::derivePublicKey
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
Definition
SecretKey.cpp:306
xrpl::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition
AccountID.cpp:105
xrpl::getNodeIdentity
std::pair< PublicKey, SecretKey > getNodeIdentity(soci::session &session)
Returns a stable public and private key for this node.
Definition
Wallet.cpp:151
xrpl::generateSecretKey
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
Definition
SecretKey.cpp:284
xrpl::clearNodeIdentity
void clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
Definition
Wallet.cpp:145
xrpl::Throw
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition
contract.h:52
xrpl::parseGenericSeed
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition
Seed.cpp:79
optional
stdexcept
string
xrpl::Sections::kNodeSeed
static constexpr auto kNodeSeed
Definition
Constants.h:33
utility
Generated by
1.17.0