EvmAddr.fromPublicKey constructor

EvmAddr.fromPublicKey(
  1. Uint8List publicKey
)

Derives from a 64- or 65-byte uncompressed secp256k1 public key. Takes last 20 bytes of keccak256 over the 64-byte x||y (no 0x04 prefix).

Implementation

factory EvmAddr.fromPublicKey(Uint8List publicKey) {
  Uint8List raw;
  if (publicKey.length == 65) {
    raw = publicKey.sublist(1);
  } else if (publicKey.length == 64) {
    raw = publicKey;
  } else {
    throw ArgumentError(
      'Public key must be 64 or 65 bytes (uncompressed), got ${publicKey.length}',
    );
  }
  final hash = keccak256(raw);
  return EvmAddr(hash.sublist(12));
}