Kagome
Polkadot Runtime Engine in C++17
crypto_store.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CRYPTO_STORE_HPP
7 #define KAGOME_CRYPTO_STORE_HPP
8 
9 #include <memory>
10 
11 #include <boost/filesystem.hpp>
12 #include <libp2p/crypto/key.hpp>
13 #include <optional>
14 
17 #include "crypto/ecdsa_types.hpp"
18 #include "crypto/ed25519_types.hpp"
20 #include "crypto/sr25519_types.hpp"
21 
22 namespace kagome::crypto {
23  class CryptoStore {
24  public:
25  // currently std::filesystem::path is missing required methods in macos SDK
26  // so we have to use boost's filesystem primitives
27  using Path = boost::filesystem::path;
28 
29  virtual ~CryptoStore() = default;
30 
31  using EcdsaKeys = std::vector<EcdsaPublicKey>;
32  using Ed25519Keys = std::vector<Ed25519PublicKey>;
33  using Sr25519Keys = std::vector<Sr25519PublicKey>;
34  using EcdsaKeypairs = std::vector<EcdsaKeypair>;
35  using Ed25519Keypairs = std::vector<Ed25519Keypair>;
36  using Sr25519Keypairs = std::vector<Sr25519Keypair>;
37 
44  virtual outcome::result<EcdsaKeypair> generateEcdsaKeypair(
45  KeyTypeId key_type, std::string_view mnemonic_phrase) = 0;
46 
53  virtual outcome::result<Ed25519Keypair> generateEd25519Keypair(
54  KeyTypeId key_type, std::string_view mnemonic_phrase) = 0;
55 
62  virtual outcome::result<Sr25519Keypair> generateSr25519Keypair(
63  KeyTypeId key_type, std::string_view mnemonic_phrase) = 0;
64 
71  virtual outcome::result<EcdsaKeypair> generateEcdsaKeypair(
72  KeyTypeId key_type, const EcdsaSeed &seed) = 0;
73 
80  virtual outcome::result<Ed25519Keypair> generateEd25519Keypair(
81  KeyTypeId key_type, const Ed25519Seed &seed) = 0;
82 
89  virtual outcome::result<Sr25519Keypair> generateSr25519Keypair(
90  KeyTypeId key_type, const Sr25519Seed &seed) = 0;
91 
97  virtual outcome::result<EcdsaKeypair> generateEcdsaKeypairOnDisk(
98  KeyTypeId key_type) = 0;
99 
105  virtual outcome::result<Ed25519Keypair> generateEd25519KeypairOnDisk(
106  KeyTypeId key_type) = 0;
107 
113  virtual outcome::result<Sr25519Keypair> generateSr25519KeypairOnDisk(
114  KeyTypeId key_type) = 0;
115 
122  virtual outcome::result<EcdsaKeypair> findEcdsaKeypair(
123  KeyTypeId key_type, const EcdsaPublicKey &pk) const = 0;
124 
131  virtual outcome::result<Ed25519Keypair> findEd25519Keypair(
132  KeyTypeId key_type, const Ed25519PublicKey &pk) const = 0;
133 
140  virtual outcome::result<Sr25519Keypair> findSr25519Keypair(
141  KeyTypeId key_type, const Sr25519PublicKey &pk) const = 0;
142 
148  virtual outcome::result<EcdsaKeys> getEcdsaPublicKeys(
149  KeyTypeId key_type) const = 0;
150 
156  virtual outcome::result<Ed25519Keys> getEd25519PublicKeys(
157  KeyTypeId key_type) const = 0;
158 
164  virtual outcome::result<Sr25519Keys> getSr25519PublicKeys(
165  KeyTypeId key_type) const = 0;
166 
170  virtual std::optional<libp2p::crypto::KeyPair> getLibp2pKeypair() const = 0;
171 
178  virtual outcome::result<libp2p::crypto::KeyPair> loadLibp2pKeypair(
179  const Path &key_path) const = 0;
180  };
181 } // namespace kagome::crypto
182 
183 #endif // KAGOME_CRYPTO_STORE_HPP
virtual outcome::result< EcdsaKeypair > generateEcdsaKeypairOnDisk(KeyTypeId key_type)=0
generates ecdsa keypair and stores it on disk
virtual std::optional< libp2p::crypto::KeyPair > getLibp2pKeypair() const =0
virtual outcome::result< EcdsaKeypair > generateEcdsaKeypair(KeyTypeId key_type, std::string_view mnemonic_phrase)=0
generates ecdsa keypair and stores it in memory
boost::filesystem::path Path
virtual outcome::result< Ed25519Keypair > findEd25519Keypair(KeyTypeId key_type, const Ed25519PublicKey &pk) const =0
searches for key pair
std::vector< Ed25519Keypair > Ed25519Keypairs
virtual outcome::result< Sr25519Keypair > findSr25519Keypair(KeyTypeId key_type, const Sr25519PublicKey &pk) const =0
searches for key pair
virtual outcome::result< Ed25519Keys > getEd25519PublicKeys(KeyTypeId key_type) const =0
searches for Ed25519 keys of specified type
uint32_t KeyTypeId
Key type identifier.
Definition: key_type.hpp:21
virtual outcome::result< Sr25519Keys > getSr25519PublicKeys(KeyTypeId key_type) const =0
searches for SR25519 keys of specified type
virtual outcome::result< EcdsaKeys > getEcdsaPublicKeys(KeyTypeId key_type) const =0
searches for ecdsa keys of specified type
virtual outcome::result< Ed25519Keypair > generateEd25519Keypair(KeyTypeId key_type, std::string_view mnemonic_phrase)=0
generates Ed25519 keypair and stores it in memory
virtual outcome::result< libp2p::crypto::KeyPair > loadLibp2pKeypair(const Path &key_path) const =0
virtual outcome::result< EcdsaKeypair > findEcdsaKeypair(KeyTypeId key_type, const EcdsaPublicKey &pk) const =0
searches for key pair
std::vector< Ed25519PublicKey > Ed25519Keys
virtual outcome::result< Sr25519Keypair > generateSr25519KeypairOnDisk(KeyTypeId key_type)=0
generates SR25519 keypair and stores it on disk
virtual outcome::result< Sr25519Keypair > generateSr25519Keypair(KeyTypeId key_type, std::string_view mnemonic_phrase)=0
generates SR25519 keypair and stores it in memory
std::vector< EcdsaPublicKey > EcdsaKeys
virtual ~CryptoStore()=default
std::vector< Sr25519Keypair > Sr25519Keypairs
std::vector< Sr25519PublicKey > Sr25519Keys
virtual outcome::result< Ed25519Keypair > generateEd25519KeypairOnDisk(KeyTypeId key_type)=0
generates Ed25519 keypair and stores it on disk
std::vector< EcdsaKeypair > EcdsaKeypairs