Kagome
Polkadot Runtime Engine in C++17
kagome::crypto::CryptoStoreImpl Class Reference

#include <crypto_store_impl.hpp>

Inheritance diagram for kagome::crypto::CryptoStoreImpl:
Collaboration diagram for kagome::crypto::CryptoStoreImpl:

Public Member Functions

 CryptoStoreImpl (std::shared_ptr< EcdsaSuite > ecdsa_suite, std::shared_ptr< Ed25519Suite > ed_suite, std::shared_ptr< Sr25519Suite > sr_suite, std::shared_ptr< Bip39Provider > bip39_provider, std::shared_ptr< KeyFileStorage > key_fs)
 
outcome::result< EcdsaKeypairgenerateEcdsaKeypair (KeyTypeId key_type, std::string_view mnemonic_phrase) override
 generates ecdsa keypair and stores it in memory More...
 
outcome::result< Ed25519KeypairgenerateEd25519Keypair (KeyTypeId key_type, std::string_view mnemonic_phrase) override
 generates Ed25519 keypair and stores it in memory More...
 
outcome::result< Sr25519KeypairgenerateSr25519Keypair (KeyTypeId key_type, std::string_view mnemonic_phrase) override
 generates SR25519 keypair and stores it in memory More...
 
outcome::result< EcdsaKeypairgenerateEcdsaKeypair (KeyTypeId key_type, const EcdsaSeed &seed) override
 generates ecdsa keypair and stores it in memory More...
 
outcome::result< Ed25519KeypairgenerateEd25519Keypair (KeyTypeId key_type, const Ed25519Seed &seed) override
 generates Ed25519 keypair and stores it in memory More...
 
outcome::result< Sr25519KeypairgenerateSr25519Keypair (KeyTypeId key_type, const Sr25519Seed &seed) override
 generates SR25519 keypair and stores it in memory More...
 
outcome::result< EcdsaKeypairgenerateEcdsaKeypairOnDisk (KeyTypeId key_type) override
 generates ecdsa keypair and stores it on disk More...
 
outcome::result< Ed25519KeypairgenerateEd25519KeypairOnDisk (KeyTypeId key_type) override
 generates Ed25519 keypair and stores it on disk More...
 
outcome::result< Sr25519KeypairgenerateSr25519KeypairOnDisk (KeyTypeId key_type) override
 generates SR25519 keypair and stores it on disk More...
 
outcome::result< EcdsaKeypairfindEcdsaKeypair (KeyTypeId key_type, const EcdsaPublicKey &pk) const override
 searches for key pair More...
 
outcome::result< Ed25519KeypairfindEd25519Keypair (KeyTypeId key_type, const Ed25519PublicKey &pk) const override
 searches for key pair More...
 
outcome::result< Sr25519KeypairfindSr25519Keypair (KeyTypeId key_type, const Sr25519PublicKey &pk) const override
 searches for key pair More...
 
outcome::result< EcdsaKeysgetEcdsaPublicKeys (KeyTypeId key_type) const override
 searches for ecdsa keys of specified type More...
 
outcome::result< Ed25519KeysgetEd25519PublicKeys (KeyTypeId key_type) const override
 searches for Ed25519 keys of specified type More...
 
outcome::result< Sr25519KeysgetSr25519PublicKeys (KeyTypeId key_type) const override
 searches for SR25519 keys of specified type More...
 
std::optional< libp2p::crypto::KeyPair > getLibp2pKeypair () const override
 
outcome::result< libp2p::crypto::KeyPair > loadLibp2pKeypair (const Path &key_path) const override
 
- Public Member Functions inherited from kagome::crypto::CryptoStore
virtual ~CryptoStore ()=default
 

Private Member Functions

template<typename CryptoSuite >
outcome::result< std::vector< typename CryptoSuite::PublicKey > > getPublicKeys (KeyTypeId key_type, const KeyCache< CryptoSuite > &cache, const CryptoSuite &suite) const
 
template<typename CryptoSuite >
outcome::result< typename CryptoSuite::KeypairgenerateKeypair (std::string_view mnemonic_phrase, const CryptoSuite &suite)
 
template<typename CryptoSuite >
outcome::result< typename CryptoSuite::KeypairgenerateKeypairOnDisk (KeyTypeId key_type, const std::shared_ptr< CryptoSuite > &suite, std::unordered_map< KeyTypeId, KeyCache< CryptoSuite >> &caches)
 
template<typename Suite >
KeyCache< Suite > & getCache (std::shared_ptr< Suite > suite, std::unordered_map< KeyTypeId, KeyCache< Suite >> &caches, KeyTypeId type) const
 

Private Attributes

std::unordered_map< KeyTypeId, KeyCache< EcdsaSuite > > ecdsa_caches_
 
std::unordered_map< KeyTypeId, KeyCache< Ed25519Suite > > ed_caches_
 
std::unordered_map< KeyTypeId, KeyCache< Sr25519Suite > > sr_caches_
 
std::shared_ptr< KeyFileStoragefile_storage_
 
std::shared_ptr< EcdsaSuiteecdsa_suite_
 
std::shared_ptr< Ed25519Suiteed_suite_
 
std::shared_ptr< Sr25519Suitesr_suite_
 
std::shared_ptr< Bip39Providerbip39_provider_
 
log::Logger logger_
 

Additional Inherited Members

- Public Types inherited from kagome::crypto::CryptoStore
using Path = boost::filesystem::path
 
using EcdsaKeys = std::vector< EcdsaPublicKey >
 
using Ed25519Keys = std::vector< Ed25519PublicKey >
 
using Sr25519Keys = std::vector< Sr25519PublicKey >
 
using EcdsaKeypairs = std::vector< EcdsaKeypair >
 
using Ed25519Keypairs = std::vector< Ed25519Keypair >
 
using Sr25519Keypairs = std::vector< Sr25519Keypair >
 

Detailed Description

TODO(Harrm) Add policies to emit a warning when found a keypair with incompatible type and algorithm (e. g. ed25519 BABE keypair, whereas BABE has to be sr25519 only) or when trying to generate more keypair than there should be (e. g. more than one libp2p keypair is a suspicious behaviour)

Definition at line 44 of file crypto_store_impl.hpp.

Constructor & Destructor Documentation

kagome::crypto::CryptoStoreImpl::CryptoStoreImpl ( std::shared_ptr< EcdsaSuite ecdsa_suite,
std::shared_ptr< Ed25519Suite ed_suite,
std::shared_ptr< Sr25519Suite sr_suite,
std::shared_ptr< Bip39Provider bip39_provider,
std::shared_ptr< KeyFileStorage key_fs 
)

Definition at line 39 of file crypto_store_impl.cpp.

Member Function Documentation

outcome::result< EcdsaKeypair > kagome::crypto::CryptoStoreImpl::findEcdsaKeypair ( KeyTypeId  key_type,
const EcdsaPublicKey &  pk 
) const
overridevirtual

searches for key pair

Parameters
key_typekey category
pkpublic key to look for
Returns
found key pair if exists

Implements kagome::crypto::CryptoStore.

Definition at line 121 of file crypto_store_impl.cpp.

outcome::result< Ed25519Keypair > kagome::crypto::CryptoStoreImpl::findEd25519Keypair ( KeyTypeId  key_type,
const Ed25519PublicKey &  pk 
) const
overridevirtual

searches for key pair

Parameters
key_typekey category
pkpublic key to look for
Returns
found key pair if exists

Implements kagome::crypto::CryptoStore.

Definition at line 142 of file crypto_store_impl.cpp.

outcome::result< Sr25519Keypair > kagome::crypto::CryptoStoreImpl::findSr25519Keypair ( KeyTypeId  key_type,
const Sr25519PublicKey &  pk 
) const
overridevirtual

searches for key pair

Parameters
key_typekey category
pkpublic key to look for
Returns
found key pair if exists

Implements kagome::crypto::CryptoStore.

Definition at line 157 of file crypto_store_impl.cpp.

outcome::result< EcdsaKeypair > kagome::crypto::CryptoStoreImpl::generateEcdsaKeypair ( KeyTypeId  key_type,
std::string_view  mnemonic_phrase 
)
overridevirtual

generates ecdsa keypair and stores it in memory

Parameters
key_typekey type identifier
mnemonic_phrasemnemonic phrase
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 58 of file crypto_store_impl.cpp.

outcome::result< EcdsaKeypair > kagome::crypto::CryptoStoreImpl::generateEcdsaKeypair ( KeyTypeId  key_type,
const EcdsaSeed seed 
)
overridevirtual

generates ecdsa keypair and stores it in memory

Parameters
key_typekey type identifier
seedseed for generating keys
Returns
generated key pair

Implements kagome::crypto::CryptoStore.

Definition at line 82 of file crypto_store_impl.cpp.

outcome::result< EcdsaKeypair > kagome::crypto::CryptoStoreImpl::generateEcdsaKeypairOnDisk ( KeyTypeId  key_type)
overridevirtual

generates ecdsa keypair and stores it on disk

Parameters
key_typekey type identifier
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 106 of file crypto_store_impl.cpp.

outcome::result< Ed25519Keypair > kagome::crypto::CryptoStoreImpl::generateEd25519Keypair ( KeyTypeId  key_type,
std::string_view  mnemonic_phrase 
)
overridevirtual

generates Ed25519 keypair and stores it in memory

Parameters
key_typekey type identifier
mnemonic_phrasemnemonic phrase
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 66 of file crypto_store_impl.cpp.

outcome::result< Ed25519Keypair > kagome::crypto::CryptoStoreImpl::generateEd25519Keypair ( KeyTypeId  key_type,
const Ed25519Seed &  seed 
)
overridevirtual

generates Ed25519 keypair and stores it in memory

Parameters
key_typekey type identifier
seedseed for generating keys
Returns
generated key pair

Implements kagome::crypto::CryptoStore.

Definition at line 90 of file crypto_store_impl.cpp.

outcome::result< Ed25519Keypair > kagome::crypto::CryptoStoreImpl::generateEd25519KeypairOnDisk ( KeyTypeId  key_type)
overridevirtual

generates Ed25519 keypair and stores it on disk

Parameters
key_typekey type identifier
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 111 of file crypto_store_impl.cpp.

template<typename CryptoSuite >
outcome::result<typename CryptoSuite::Keypair> kagome::crypto::CryptoStoreImpl::generateKeypair ( std::string_view  mnemonic_phrase,
const CryptoSuite suite 
)
inlineprivate

Definition at line 155 of file crypto_store_impl.hpp.

template<typename CryptoSuite >
outcome::result<typename CryptoSuite::Keypair> kagome::crypto::CryptoStoreImpl::generateKeypairOnDisk ( KeyTypeId  key_type,
const std::shared_ptr< CryptoSuite > &  suite,
std::unordered_map< KeyTypeId, KeyCache< CryptoSuite >> &  caches 
)
inlineprivate

Definition at line 171 of file crypto_store_impl.hpp.

outcome::result< Sr25519Keypair > kagome::crypto::CryptoStoreImpl::generateSr25519Keypair ( KeyTypeId  key_type,
std::string_view  mnemonic_phrase 
)
overridevirtual

generates SR25519 keypair and stores it in memory

Parameters
key_typekey type identifier
mnemonic_phrasemnemonic phrase
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 74 of file crypto_store_impl.cpp.

outcome::result< Sr25519Keypair > kagome::crypto::CryptoStoreImpl::generateSr25519Keypair ( KeyTypeId  key_type,
const Sr25519Seed &  seed 
)
overridevirtual

generates SR25519 keypair and stores it in memory

Parameters
key_typekey type identifier
seedseed for generating keys
Returns
generated key

Implements kagome::crypto::CryptoStore.

Definition at line 98 of file crypto_store_impl.cpp.

outcome::result< Sr25519Keypair > kagome::crypto::CryptoStoreImpl::generateSr25519KeypairOnDisk ( KeyTypeId  key_type)
overridevirtual

generates SR25519 keypair and stores it on disk

Parameters
key_typekey type identifier
Returns
generated key pair or error

Implements kagome::crypto::CryptoStore.

Definition at line 116 of file crypto_store_impl.cpp.

template<typename Suite >
KeyCache<Suite>& kagome::crypto::CryptoStoreImpl::getCache ( std::shared_ptr< Suite >  suite,
std::unordered_map< KeyTypeId, KeyCache< Suite >> &  caches,
KeyTypeId  type 
) const
inlineprivate

Definition at line 182 of file crypto_store_impl.hpp.

outcome::result< CryptoStoreImpl::EcdsaKeys > kagome::crypto::CryptoStoreImpl::getEcdsaPublicKeys ( KeyTypeId  key_type) const
overridevirtual

searches for ecdsa keys of specified type

Parameters
key_typekey type identifier to look for
Returns
vector of found public keys

Implements kagome::crypto::CryptoStore.

Definition at line 173 of file crypto_store_impl.cpp.

outcome::result< CryptoStoreImpl::Ed25519Keys > kagome::crypto::CryptoStoreImpl::getEd25519PublicKeys ( KeyTypeId  key_type) const
overridevirtual

searches for Ed25519 keys of specified type

Parameters
key_typekey type identifier to look for
Returns
vector of found public keys

Implements kagome::crypto::CryptoStore.

Definition at line 180 of file crypto_store_impl.cpp.

std::optional< libp2p::crypto::KeyPair > kagome::crypto::CryptoStoreImpl::getLibp2pKeypair ( ) const
overridevirtual
Returns
current LibP2P keypair

Implements kagome::crypto::CryptoStore.

Definition at line 191 of file crypto_store_impl.cpp.

template<typename CryptoSuite >
outcome::result<std::vector<typename CryptoSuite::PublicKey> > kagome::crypto::CryptoStoreImpl::getPublicKeys ( KeyTypeId  key_type,
const KeyCache< CryptoSuite > &  cache,
const CryptoSuite suite 
) const
inlineprivate

Definition at line 104 of file crypto_store_impl.hpp.

outcome::result< CryptoStoreImpl::Sr25519Keys > kagome::crypto::CryptoStoreImpl::getSr25519PublicKeys ( KeyTypeId  key_type) const
overridevirtual

searches for SR25519 keys of specified type

Parameters
key_typekey type identifier to look for
Returns
vector of found public keys

Implements kagome::crypto::CryptoStore.

Definition at line 186 of file crypto_store_impl.cpp.

outcome::result< libp2p::crypto::KeyPair > kagome::crypto::CryptoStoreImpl::loadLibp2pKeypair ( const Path key_path) const
overridevirtual

Acquires the key from user-provided path or generates and saves the key under the path. Used when –node-key-file flag gets processed.

Parameters
path- path the key file (raw bytes or hex-encoded)
Returns
LibP2P keypair

Implements kagome::crypto::CryptoStore.

Definition at line 204 of file crypto_store_impl.cpp.

Member Data Documentation

std::shared_ptr<Bip39Provider> kagome::crypto::CryptoStoreImpl::bip39_provider_
private

Definition at line 202 of file crypto_store_impl.hpp.

std::unordered_map<KeyTypeId, KeyCache<EcdsaSuite> > kagome::crypto::CryptoStoreImpl::ecdsa_caches_
mutableprivate

Definition at line 195 of file crypto_store_impl.hpp.

std::shared_ptr<EcdsaSuite> kagome::crypto::CryptoStoreImpl::ecdsa_suite_
private

Definition at line 199 of file crypto_store_impl.hpp.

std::unordered_map<KeyTypeId, KeyCache<Ed25519Suite> > kagome::crypto::CryptoStoreImpl::ed_caches_
mutableprivate

Definition at line 196 of file crypto_store_impl.hpp.

std::shared_ptr<Ed25519Suite> kagome::crypto::CryptoStoreImpl::ed_suite_
private

Definition at line 200 of file crypto_store_impl.hpp.

std::shared_ptr<KeyFileStorage> kagome::crypto::CryptoStoreImpl::file_storage_
private

Definition at line 198 of file crypto_store_impl.hpp.

log::Logger kagome::crypto::CryptoStoreImpl::logger_
private

Definition at line 203 of file crypto_store_impl.hpp.

std::unordered_map<KeyTypeId, KeyCache<Sr25519Suite> > kagome::crypto::CryptoStoreImpl::sr_caches_
mutableprivate

Definition at line 197 of file crypto_store_impl.hpp.

std::shared_ptr<Sr25519Suite> kagome::crypto::CryptoStoreImpl::sr_suite_
private

Definition at line 201 of file crypto_store_impl.hpp.


The documentation for this class was generated from the following files: