ethAddress function
Implementation
String ethAddress(Uint8List pubk, {bool checksum = true}) {
Uint8List uncompressed;
if (pubk.length == 65) {
if (pubk[0] == 0x04) {
uncompressed = pubk.sublist(1);
} else {
throw ArgumentError("Invalid uncompressed public key");
}
} else if (pubk.length == 64) {
uncompressed = pubk;
} else {
throw ArgumentError("Invalid uncompressed public key");
}
final keccakHash = keccak256(uncompressed);
final keccakHex = HEX.encode(keccakHash);
final address = "0x${keccakHex.substring(keccakHex.length - 40)}";
if (checksum) {
return ethChecksum(address);
} else {
return address;
}
}