Kagome
Polkadot Runtime Engine in C++17
key_file_storage.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CRYPTO_KEY_FILE_STORAGE_HPP
7 #define KAGOME_CRYPTO_KEY_FILE_STORAGE_HPP
8 
9 #include <vector>
10 
11 #include <boost/filesystem.hpp>
12 #include <optional>
13 
14 #include "common/buffer.hpp"
16 #include "log/logger.hpp"
17 
18 namespace kagome::crypto {
19 
24  public:
25  enum class Error {
34  };
35 
37  using Path = boost::filesystem::path;
38 
45  static outcome::result<std::unique_ptr<KeyFileStorage>> createAt(
46  Path keystore_path);
47 
51  outcome::result<std::vector<Buffer>> collectPublicKeys(
52  KeyTypeId type) const;
53 
58  outcome::result<std::optional<Buffer>> searchForSeed(
59  KeyTypeId type, gsl::span<const uint8_t> public_key_bytes) const;
60 
65  outcome::result<void> saveKeyPair(KeyTypeId type,
66  gsl::span<const uint8_t> public_key,
67  gsl::span<const uint8_t> seed) const;
68 
76  outcome::result<std::string> loadFileContent(const Path &file_path) const;
77 
85  outcome::result<void> saveKeyHexAtPath(gsl::span<const uint8_t> private_key,
86  const Path &path) const;
87 
88  private:
89  explicit KeyFileStorage(Path keystore_path);
90 
91  outcome::result<void> initialize();
92 
93  outcome::result<std::pair<KeyTypeId, Buffer>> parseKeyFileName(
94  std::string_view file_name) const;
95 
96  Path composeKeyPath(KeyTypeId key_type,
97  gsl::span<const uint8_t> public_key) const;
98 
101  };
102 
103 } // namespace kagome::crypto
104 
106 
107 #endif // KAGOME_CRYPTO_KEY_FILE_STORAGE_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
outcome::result< void > initialize()
outcome::result< std::pair< KeyTypeId, Buffer > > parseKeyFileName(std::string_view file_name) const
outcome::result< std::vector< Buffer > > collectPublicKeys(KeyTypeId type) const
outcome::result< void > saveKeyPair(KeyTypeId type, gsl::span< const uint8_t > public_key, gsl::span< const uint8_t > seed) const
uint32_t KeyTypeId
Key type identifier.
Definition: key_type.hpp:21
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
Definition: buffer.hpp:244
OUTCOME_HPP_DECLARE_ERROR(kagome::crypto, KeyFileStorage::Error)
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
outcome::result< std::string > loadFileContent(const Path &file_path) const
outcome::result< void > saveKeyHexAtPath(gsl::span< const uint8_t > private_key, const Path &path) const
Path composeKeyPath(KeyTypeId key_type, gsl::span< const uint8_t > public_key) const
static outcome::result< std::unique_ptr< KeyFileStorage > > createAt(Path keystore_path)
outcome::result< std::optional< Buffer > > searchForSeed(KeyTypeId type, gsl::span< const uint8_t > public_key_bytes) const
boost::filesystem::path Path
KeyFileStorage(Path keystore_path)