-
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.
- Loading branch information
Showing
10 changed files
with
97 additions
and
27 deletions.
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
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,3 @@ | ||
|
||
add_library(kagome_keys key.cpp) | ||
target_link_libraries(kagome_keys p2p::p2p) |
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,42 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "key/key.hpp" | ||
|
||
#include <libp2p/peer/peer_id.hpp> | ||
#include "crypto/key_store.hpp" | ||
#include "crypto/random_generator/boost_generator.hpp" | ||
|
||
namespace kagome::key { | ||
|
||
Key::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> Key::run() { | ||
auto random_generator = std::make_shared<crypto::BoostRandomGenerator>(); | ||
|
||
auto seed = kagome::crypto::Ed25519Seed::from( | ||
crypto::SecureCleanGuard{random_generator->randomBytes( | ||
kagome::crypto::Ed25519Seed::size())}) | ||
.value(); | ||
auto keypair = ed_crypto_provider_->generateKeypair(seed, {}).value(); | ||
auto libp2p_key = crypto::ed25519KeyToLibp2pKeypair(keypair); | ||
libp2p::crypto::ProtobufKey protobuf_key{ | ||
key_marshaller_->marshal(libp2p_key.publicKey).value()}; | ||
auto peer_id = libp2p::peer::PeerId::fromPublicKey(protobuf_key); | ||
std::cerr << peer_id.value().toBase58() << std::endl; | ||
std::cout << kagome::common::hex_lower(keypair.secret_key.unsafeBytes()) | ||
<< std::endl; | ||
|
||
return outcome::success(); | ||
} | ||
} // 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,29 @@ | ||
/** | ||
* Copyright Quadrivium LLC | ||
* All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <libp2p/crypto/key_marshaller.hpp> | ||
#include "crypto/ed25519_provider.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); | ||
|
||
outcome::result<void> run(); | ||
|
||
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 |
---|---|---|
|
@@ -42,5 +42,5 @@ add_library(kagome-key | |
) | ||
|
||
target_link_libraries(kagome-key | ||
ed25519_provider | ||
application_injector | ||
) |
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