getChecksumAddress function
Implementation
String getChecksumAddress(String address) {
if (!isHexString(address, 20)) {
throw ArgumentError('invalid address');
}
address = address.toLowerCase();
var chars = address.substring(2).split('');
var expanded = Uint8List(40);
for (var i = 0; i < 40; i++) {
expanded[i] = chars[i].codeUnitAt(0);
}
var hashed = hexToBytes(HEX.encode(KeccakDigest(256).process(expanded)));
for (var i = 0; i < 40; i += 2) {
if ((hashed[i >> 1] >> 4) >= 8) {
chars[i] = chars[i].toUpperCase();
}
if ((hashed[i >> 1] & 0x0f) >= 8) {
chars[i + 1] = chars[i + 1].toUpperCase();
}
}
return '0x${chars.join('')}';
}