21 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
23 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
24 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
25 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,
26 8, -1, -1, -1, -1, -1, -1, -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18,
27 19, 20, 21, -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1,
28 -1, -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, 47, 48,
29 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
30 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
31 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
32 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
33 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
34 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
35 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36 -1, -1, -1, -1, -1, -1, -1, -1, -1,
39[[nodiscard]]
static bool
40DecodeBase58(
const char *psz, std::vector<uint8_t> &vch,
int max_ret_len) {
50 if (zeroes > max_ret_len) {
57 int size = strlen(psz) * 733 / 1000 + 1;
58 std::vector<uint8_t> b256(size);
61 static_assert(std::size(
mapBase58) == 256,
62 "mapBase58.size() should be 256");
63 while (*psz && !
IsSpace(*psz)) {
71 for (std::vector<uint8_t>::reverse_iterator it = b256.rbegin();
72 (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
79 if (length + zeroes > max_ret_len) {
92 std::vector<uint8_t>::iterator it = b256.begin() + (size - length);
95 vch.reserve(zeroes + (b256.end() - it));
96 vch.assign(zeroes, 0x00);
97 while (it != b256.end()) {
98 vch.push_back(*(it++));
107 while (input.
size() > 0 && input[0] == 0) {
113 int size = input.
size() * 138 / 100 + 1;
114 std::vector<uint8_t> b58(size);
116 while (input.
size() > 0) {
117 int carry = input[0];
120 for (std::vector<uint8_t>::reverse_iterator it = b58.rbegin();
121 (carry != 0 || i < length) && (it != b58.rend()); it++, i++) {
122 carry += 256 * (*it);
132 std::vector<uint8_t>::iterator it = b58.
begin() + (size - length);
133 while (it != b58.end() && *it == 0) {
138 str.reserve(zeroes + (b58.end() - it));
139 str.assign(zeroes,
'1');
140 while (it != b58.end()) {
156 std::vector<uint8_t> vch(input.
begin(), input.
end());
158 vch.insert(vch.end(), (uint8_t *)&hash, (uint8_t *)&hash + 4);
163 std::vector<uint8_t> &vchRet,
166 max_ret_len > std::numeric_limits<int>::max() - 4
167 ? std::numeric_limits<int>::max()
168 : max_ret_len + 4) ||
169 (vchRet.size() < 4)) {
175 if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
179 vchRet.resize(vchRet.size() - 4);
std::string EncodeBase58(Span< const uint8_t > input)
Why base-58 instead of standard base-64 encoding?
std::string EncodeBase58Check(Span< const uint8_t > input)
Encode a byte span into a base58-encoded string, including checksum.
static bool DecodeBase58(const char *psz, std::vector< uint8_t > &vch, int max_ret_len)
static bool DecodeBase58Check(const char *psz, std::vector< uint8_t > &vchRet, int max_ret_len)
static const char * pszBase58
All alphanumeric characters except for "0", "I", "O", and "l".
static const int8_t mapBase58[256]
constexpr std::size_t size() const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
constexpr C * begin() const noexcept
constexpr C * end() const noexcept
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
bool ContainsNoNUL(std::string_view str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.