checkBase58 function
Check base58 address with checksum, such as btc.
Implementation
bool checkBase58(String address, {int length = 25}) {
Uint8List decoded = base58.decode(address);
if (decoded.length != length) {
return false;
}
Uint8List data = decoded.sublist(0, decoded.length - 4);
Uint8List checksum = decoded.sublist(decoded.length - 4);
Uint8List midData = Uint8List.fromList(sha256.convert(data).bytes);
Uint8List calculatedChecksum =
Uint8List.fromList(sha256.convert(midData).bytes.sublist(0, 4));
for (int i = 0; i < 4; i++) {
if (checksum[i] != calculatedChecksum[i]) {
return false;
}
}
return true;
}