import type { Address } from 'abitype' import { type GetAddressErrorType, getAddress } from '../address/getAddress.js' import { type IsAddressEqualErrorType, isAddressEqual, } from '../address/isAddressEqual.js' import type { ErrorType } from '../errors/utils.js' import type { Hex } from '../types/data.js' import type { Signatureish } from '../types/signature.js' import { type RecoverAddressErrorType, recoverAddress, } from './recoverAddress.js' export type VerifyHashParameters = { /** The address that signed the original message. */ address: Address /** The hash to be verified. */ hash: Hex /** The signature that was generated by signing the message with the address's private key. */ signature: Signatureish } export type VerifyHashReturnType = boolean export type VerifyHashErrorType = | IsAddressEqualErrorType | GetAddressErrorType | RecoverAddressErrorType | ErrorType /** * Verify that a message was signed by the provided address. * * Note: Only supports Externally Owned Accounts. Does not support Contract Accounts. * It is highly recommended to use `publicClient.verifyHash` instead to ensure * wallet interoperability. * * - Docs {@link https://viem.sh/docs/utilities/verifyHash} * * @param parameters - {@link VerifyHashParameters} * @returns Whether or not the signature is valid. {@link VerifyHashReturnType} */ export function verifyHash({ address, hash, signature, }: VerifyHashParameters): VerifyHashReturnType { return isAddressEqual( getAddress(address), recoverAddress({ hash, signature }), ) }