pubKeytoChecksumETHAddress function

String pubKeytoChecksumETHAddress(
  1. Uint8List seed
)

Implementation

String pubKeytoChecksumETHAddress(Uint8List seed) {
  final publicKey = derivePublicKeyETH(seed);
  final pubKeyWithoutPrefix = keccak256(publicKey.sublist(1));

  final address = '0x${pubKeyWithoutPrefix.sublist(12).toHex}';

  final addressWithoutPrefix = address.replaceFirst('0x', '').toLowerCase();

  // Compute the keccak-256 hash of the address
  final hash = keccak256(utf8.encode(addressWithoutPrefix));
  final hashHex = hex.encode(hash);

  // Apply the checksum
  final checksummedAddress = StringBuffer('0x');
  for (int i = 0; i < addressWithoutPrefix.length; i++) {
    if (int.parse(hashHex[i], radix: 16) > 7) {
      checksummedAddress.write(addressWithoutPrefix[i].toUpperCase());
    } else {
      checksummedAddress.write(addressWithoutPrefix[i].toLowerCase());
    }
  }

  return checksummedAddress.toString();
}