static std::string decodeBase58Token (std::string const& s, int type, InverseArray const& inv) { auto result = decodeBase58(s, inv); if (result.empty()) return result; // Reject zero length tokens if (result.size() < 6) return {}; if (result[0] != type) return {}; std::array<char, 4> guard; checksum(guard.data(), result.data(), result.size() - 4); if (std::memcmp(guard.data(), result.data() + result.size() - 4, 4) != 0) return {}; result.resize(result.size() - 4); // Erase the type byte // VFALCO This might cause problems later result.erase(result.begin()); return result; }
bool bitcoinAsciiToAddress(const char *input,uint8_t output[25]) // convert an ASCII bitcoin address into binary. { bool ret = false; uint32_t len = decodeBase58(input,output,25,true); if ( len == 25 ) // the output must be *exactly* 25 bytes! { uint8_t checksum[32]; computeSHA256(output,21,checksum); computeSHA256(checksum,32,checksum); if ( output[21] == checksum[0] || output[22] == checksum[1] || output[23] == checksum[2] || output[24] == checksum[3] ) { ret = true; // the cheksum matches! } } return ret; }