Kagome
Polkadot Runtime Engine in C++17
entropy_accumulator.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CRYPTO_BIP39_ENTROPY_HPP
7 #define KAGOME_CRYPTO_BIP39_ENTROPY_HPP
8 
9 #include <boost/assert.hpp>
10 #include "outcome/outcome.hpp"
11 
12 #include <bitset>
13 #include <vector>
14 
15 namespace kagome::crypto::bip39 {
16 
17  enum class Bip39EntropyError {
21  };
22 
23  struct EntropyToken : public std::bitset<11> {
24  using Parent = std::bitset<11>;
25  using Parent::bitset;
26  };
27 
32  public:
37  static outcome::result<EntropyAccumulator> create(size_t words_count);
38 
44  outcome::result<void> append(const EntropyToken &value);
45 
49  outcome::result<std::vector<uint8_t>> getEntropy() const;
50 
55  outcome::result<uint8_t> getChecksum() const;
56 
61  outcome::result<uint8_t> calculateChecksum() const;
62 
63  private:
68  EntropyAccumulator(size_t bits_count, size_t checksum_bits_count);
69 
70  std::vector<uint8_t> bits_;
71  const size_t total_bits_count_;
72  const size_t checksum_bits_count_;
73  };
74 } // namespace kagome::crypto::bip39
75 
77 
78 #endif // KAGOME_CRYPTO_BIP39_ENTROPY_HPP
OUTCOME_HPP_DECLARE_ERROR(kagome::crypto::bip39, Bip39EntropyError)
static common::Buffer calculateChecksum(gsl::span< uint8_t, kSs58Length-kSs58ChecksumLength > ss58_address, const crypto::Hasher &hasher)
Definition: ss58_codec.cpp:27