-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fixup/era_points
- Loading branch information
Showing
9 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <libp2p/crypto/key_marshaller.hpp> | ||
#include <libp2p/peer/peer_id.hpp> | ||
#include "crypto/ed25519_provider.hpp" | ||
#include "crypto/key_store.hpp" | ||
#include "crypto/random_generator/boost_generator.hpp" | ||
|
||
namespace kagome::key { | ||
|
||
class Key { | ||
public: | ||
Key(std::shared_ptr<crypto::Ed25519Provider> ed_crypto_provider, | ||
std::shared_ptr<libp2p::crypto::marshaller::KeyMarshaller> | ||
key_marshaller) | ||
: ed_crypto_provider_{std::move(ed_crypto_provider)}, | ||
key_marshaller_{std::move(key_marshaller)} { | ||
BOOST_ASSERT(ed_crypto_provider_ != nullptr); | ||
BOOST_ASSERT(key_marshaller_ != nullptr); | ||
} | ||
|
||
outcome::result<void> run() { | ||
auto random_generator = std::make_unique<crypto::BoostRandomGenerator>(); | ||
OUTCOME_TRY( | ||
seed, | ||
crypto::Ed25519Seed::from(crypto::SecureCleanGuard{ | ||
random_generator->randomBytes(crypto::Ed25519Seed::size())})); | ||
OUTCOME_TRY(keypair, ed_crypto_provider_->generateKeypair(seed, {})); | ||
const auto libp2p_key = crypto::ed25519KeyToLibp2pKeypair(keypair); | ||
const libp2p::crypto::ProtobufKey protobuf_key{ | ||
key_marshaller_->marshal(libp2p_key.publicKey).value()}; | ||
auto peer_id = libp2p::peer::PeerId::fromPublicKey(protobuf_key); | ||
if (not peer_id) { | ||
return peer_id.error(); | ||
} | ||
std::cerr << peer_id.value().toBase58() << "\n"; | ||
std::cout << kagome::common::hex_lower(keypair.secret_key.unsafeBytes()) | ||
<< "\n"; | ||
|
||
return outcome::success(); | ||
} | ||
|
||
private: | ||
std::shared_ptr<crypto::Ed25519Provider> ed_crypto_provider_; | ||
std::shared_ptr<libp2p::crypto::marshaller::KeyMarshaller> key_marshaller_; | ||
}; | ||
} // namespace kagome::key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#include "application/impl/app_configuration_impl.hpp" | ||
#include "injector/application_injector.hpp" | ||
#include "key.hpp" | ||
|
||
namespace kagome { | ||
int key_main(int argc, const char **argv) { | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) | ||
const std::string_view key_command = argv[0]; | ||
if (argc == 2) { | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) | ||
const std::string_view command = argv[1]; | ||
if (command == "--generate-node-key") { | ||
auto injector = std::make_unique<injector::KagomeNodeInjector>( | ||
std::make_shared<application::AppConfigurationImpl>()); | ||
auto key = injector->injectKey(); | ||
if (auto res = key->run(); not res) { | ||
std::cerr << "Error: " << res.error().message() << "\n"; | ||
return 2; | ||
} | ||
} else if (command == "--help") { | ||
std::cerr << "Usage: " << key_command << " --generate-node-key" | ||
<< "\nGenerates a node key and prints the peer ID to stderr " | ||
"and the secret key to stdout.\n"; | ||
} else { | ||
std::cerr << "Unknown command: " << command << "\n"; | ||
std::cerr << "Usage: " << key_command << " --generate-node-key\n"; | ||
return 3; | ||
} | ||
} else { | ||
std::cerr << "Usage: " << key_command << " --generate-node-key\n"; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
} // namespace kagome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters