13 switch (words_count) {
37 std::vector<uint8_t> res;
38 res.reserve(bytes_count);
39 auto it =
bits_.begin();
40 for (
size_t i = 0; i < bytes_count; ++i) {
42 for (
size_t j = 0; j < 8u; ++j) {
58 uint8_t checksum = 0u;
59 auto it =
bits_.rbegin();
61 checksum += (*it++ << i);
72 for (
size_t i = 0; i < value.size(); ++i) {
74 auto position = value.size() - i - 1;
75 uint8_t v = value.test(position) ? 1 : 0;
79 return outcome::success();
84 auto hash =
sha256(entropy);
89 size_t checksum_bits_count)
92 BOOST_ASSERT_MSG((bits_count - checksum_bits_count) % 32 == 0,
93 "invalid bits count");
94 BOOST_ASSERT_MSG(bits_count <= 264 && bits_count >= 132,
95 "unsupported bits count");
97 bits_.reserve(bits_count);
106 return "invalid or unsupported words count";
108 return "cannot get info from storage while it is still not complete";
110 return "cannot put more data into storage, it is full";
113 return "unknown Bip39EntropyError error";
outcome::result< uint8_t > getChecksum() const
checksum is a part of last byte
OUTCOME_CPP_DEFINE_CATEGORY(kagome::crypto::bip39, Bip39EntropyError, error)
static outcome::result< EntropyAccumulator > create(size_t words_count)
create class instance
outcome::result< std::vector< uint8_t > > getEntropy() const
outcome::result< uint8_t > calculateChecksum() const
calculates checksum of significant bits
std::vector< uint8_t > bits_
common::Hash256 sha256(std::string_view input)
outcome::result< void > append(const EntropyToken &value)
append a new entropy token
const size_t checksum_bits_count_
EntropyAccumulator(size_t bits_count, size_t checksum_bits_count)
const size_t total_bits_count_