import type { Address } from 'abitype' import type { ErrorType } from '../errors/utils.js' import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js' import type { Hex } from '../types/data.js' export type PublicKeyToAddressErrorType = Keccak256ErrorType | ErrorType /** * @description Converts an ECDSA public key to an address. * * @param publicKey The public key to convert. * * @returns The address. */ export function publicKeyToAddress(publicKey: Hex): Address { const address = keccak256(`0x${publicKey.substring(4)}`).substring(26) return `0x${address}` }