6 #ifndef KAGOME_CORE_INJECTOR_GET_PEER_KEYPAIR_HPP 7 #define KAGOME_CORE_INJECTOR_GET_PEER_KEYPAIR_HPP 19 static auto initialized =
20 std::optional<std::shared_ptr<libp2p::crypto::KeyPair>>(std::nullopt);
23 return initialized.value();
29 log->info(
"Will use LibP2P keypair from config or 'node-key' CLI arg");
32 crypto::Ed25519Seed{app_config.
nodeKey().value()});
33 BOOST_ASSERT(provided_keypair.secret_key == app_config.
nodeKey().value());
35 auto key_pair = std::make_shared<libp2p::crypto::KeyPair>(
38 initialized.emplace(std::move(key_pair));
39 return initialized.value();
43 const auto &path = app_config.
nodeKeyFile().value();
45 "Will use LibP2P keypair from config or 'node-key-file' CLI arg");
47 if (key.has_error()) {
48 log->error(
"Unable to load user provided key from {}. Error: {}",
50 key.error().message());
54 std::make_shared<libp2p::crypto::KeyPair>(std::move(key.value()));
55 initialized.emplace(std::move(key_pair));
56 return initialized.value();
62 "Will use LibP2P keypair from config or args (loading from base " 68 std::make_shared<libp2p::crypto::KeyPair>(std::move(stored_keypair));
70 initialized.emplace(std::move(key_pair));
71 return initialized.value();
75 "Can not obtain a libp2p keypair from crypto storage. " 76 "A unique one will be generated");
83 if (res.has_error()) {
84 log->warn(
"Can't save libp2p keypair: {}", res.error());
87 generated_keypair = res.value();
94 auto key_pair = std::make_shared<libp2p::crypto::KeyPair>(
97 initialized.emplace(std::move(key_pair));
98 return initialized.value();
102 #endif // KAGOME_CORE_INJECTOR_GET_PEER_KEYPAIR_HPP void raise(T t)
throws outcome::result error as boost exception
virtual std::optional< libp2p::crypto::KeyPair > getLibp2pKeypair() const =0
const std::shared_ptr< libp2p::crypto::KeyPair > & get_peer_keypair(const application::AppConfiguration &app_config, const crypto::Ed25519Provider &crypto_provider, crypto::CryptoStore &crypto_store)
libp2p::crypto::KeyPair ed25519KeyToLibp2pKeypair(const Ed25519Keypair &kp)
virtual const std::optional< crypto::Ed25519PrivateKey > & nodeKey() const =0
virtual outcome::result< libp2p::crypto::KeyPair > loadLibp2pKeypair(const Path &key_path) const =0
virtual Ed25519KeypairAndSeed generateKeypair() const =0
virtual bool shouldSaveNodeKey() const =0
Logger createLogger(const std::string &tag)
virtual outcome::result< Ed25519Keypair > generateEd25519KeypairOnDisk(KeyTypeId key_type)=0
generates Ed25519 keypair and stores it on disk
virtual const std::optional< std::string > & nodeKeyFile() const =0