#pragma once #include #include #include #include namespace base58 { /** * @brief bitcoin alphabet */ extern const char digits[59]; extern const int8_t map[256]; bool isValid(const char *str, uint64_t str_size) noexcept; bool isValid(std::string_view str) noexcept; /** * @throw std::overflow_error if if there is an overflow */ uint64_t sizeEncoded(std::span data) noexcept; uint64_t sizeDecoded(std::string_view str) noexcept; /** * @return number of leading chars, which should be trimmed * @warning contain leading zeros, returns count of them */ uint64_t encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size) noexcept; std::string encode(std::span data) noexcept; /** * @return number of leading chars, which should be trimmed * @warning contain leading zeros, returns count of them */ uint64_t decode(const char *str, uint64_t str_size, uint8_t *data, uint64_t data_size) noexcept; std::vector decode(std::string_view str) noexcept; /** * @param data vector or span of data which you want to encode * @return encoded string + 4 first bytes of double sha256 */ std::string encodeCheck(std::span data) noexcept; /** * @param str string or string_view which you want to decode * @return decoded data without 4 first bytes of double sha256 * @throw std::logic_error checksum incorrect */ std::vector decodeCheck(std::string_view str); }