import { createPublicClient, http, verifyTypedData } from 'viem';
import { mainnet } from 'viem/chains';
const publicClient = createPublicClient({ chain: mainnet, transport: http() });
const domain = {
  name: 'Example DApp',
  version: '1',
  chainId: 1,
  verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
} as const;
const types = {
  Mail: [
    { name: 'from', type: 'address' },
    { name: 'to', type: 'address' },
    { name: 'contents', type: 'string' },
  ],
} as const;
type VerifyTypedDataInput = {
  address: `0x${string}`; // expected signer address (EOA or contract)
  message: { from: `0x${string}`; to: `0x${string}`; contents: string };
  signature: `0x${string}`;
};
export async function verifyEip712({ address, message, signature }: VerifyTypedDataInput) {
  return verifyTypedData(publicClient, {
    address,
    domain,
    types,
    primaryType: 'Mail',
    message,
    signature,
  });
}