19 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
21 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
22 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
23 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7,
24 8, -1, -1, -1, -1, -1, -1, -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18,
25 19, 20, 21, -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1,
26 -1, -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, 47, 48,
27 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
28 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
29 -1, -1, -1, -1, -1, -1, -1, -1, -1, -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,
37 bool DecodeBase58(
const char *psz, std::vector<uint8_t> &vch,
int max_ret_len) {
47 if (zeroes > max_ret_len) {
54 int size = strlen(psz) * 733 / 1000 + 1;
55 std::vector<uint8_t> b256(size);
59 "mapBase58.size() should be 256");
60 while (*psz && !
IsSpace(*psz)) {
68 for (std::vector<uint8_t>::reverse_iterator it = b256.rbegin();
69 (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) {
76 if (length + zeroes > max_ret_len) {
89 std::vector<uint8_t>::iterator it = b256.begin() + (size - length);
92 vch.reserve(zeroes + (b256.end() - it));
93 vch.assign(zeroes, 0x00);
94 while (it != b256.end()) {
95 vch.push_back(*(it++));
104 while (pbegin != pend && *pbegin == 0) {
110 int size = (pend - pbegin) * 138 / 100 + 1;
111 std::vector<uint8_t> b58(size);
113 while (pbegin != pend) {
117 for (std::vector<uint8_t>::reverse_iterator it = b58.rbegin();
118 (carry != 0 || i < length) && (it != b58.rend()); it++, i++) {
119 carry += 256 * (*it);
129 std::vector<uint8_t>::iterator it = b58.begin() + (size - length);
130 while (it != b58.end() && *it == 0) {
135 str.reserve(zeroes + (b58.end() - it));
136 str.assign(zeroes,
'1');
137 while (it != b58.end()) {
144 return EncodeBase58(vch.data(), vch.data() + vch.size());
147 bool DecodeBase58(
const std::string &str, std::vector<uint8_t> &vchRet,
157 std::vector<uint8_t> vch(vchIn);
159 vch.insert(vch.end(), (uint8_t *)&hash, (uint8_t *)&hash + 4);
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)) {
174 uint256 hash =
Hash(vchRet.begin(), vchRet.end() - 4);
175 if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
179 vchRet.resize(vchRet.size() - 4);
NODISCARD bool ValidAsCString(const std::string &str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
bool DecodeBase58Check(const char *psz, std::vector< uint8_t > &vchRet, int max_ret_len)
Decode a base58-encoded string (psz) that includes a checksum into a byte vector (vchRet), return true if decoding is successful.
bool DecodeBase58(const char *psz, std::vector< uint8_t > &vch, int max_ret_len)
Decode a base58-encoded string (psz) into a byte vector (vchRet).
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
static const char * pszBase58
All alphanumeric characters except for "0", "I", "O", and "l".
std::string EncodeBase58(const uint8_t *pbegin, const uint8_t *pend)
Why base-58 instead of standard base-64 encoding?
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
static const int8_t mapBase58[256]
std::string EncodeBase58Check(const std::vector< uint8_t > &vchIn)
Encode a byte vector into a base58-encoded string, including checksum.