publicKeyToAddress function
Constructs the core blockchain address associated with the given public key by taking the lower 160 bits of the key's sha3 hash.
Implementation
Uint8List publicKeyToAddress(Uint8List publicKey, int networkId) {
_validateLength(publicKey, _publicKeyLength, 'publicKey');
final hash = sha3_256(publicKey);
final networkBytes = hexToBytes(getNetworkIdPrefix(networkId));
final purgedHash = <int>[];
for (var i = 12; i < hash.length; i++) {
purgedHash.add(hash[i]);
}
final checksum = calculateCheckSum(
Uint8List.fromList(purgedHash),
networkBytes,
);
final concatenated =
BytesBuilder()
..add(networkBytes)
..add(hexToBytes(checksum))
..add(purgedHash);
return concatenated.toBytes();
}