verifyTypedData
Verifies a typed data signature
Verifies a typed data signature
Verify that typed data was signed by the provided address.
Supports verification of:
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"An example showing how to verify an EIP-712 typed data signature against a given address.
import ( "context" "log" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public" "github.com/ChefBingbong/viem-go/utils/signature" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = publicClient.Close() }()
typedData := signature.TypedDataDefinition{ Domain: signature.TypedDataDomain{ Name: "Ether Mail", Version: "1", ChainId: big.NewInt(1), VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", }, Types: map[string][]signature.TypedDataField{ "Person": { {Name: "name", Type: "string"}, {Name: "wallet", Type: "address"}, }, "Mail": { {Name: "from", Type: "Person"}, {Name: "to", Type: "Person"}, {Name: "contents", Type: "string"}, }, }, PrimaryType: "Mail", Message: map[string]any{ "from": map[string]any{ "name": "Cow", "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", }, "to": map[string]any{ "name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", }, "contents": "Hello, Bob!", },}
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})if err != nil { log.Fatal(err)}log.Printf("Valid: %v", valid)bool
Whether the signed typed data is valid for the given address.
Configuration options accepted by this action.
common.AddressThe Ethereum address that signed the original typed data.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})signature.TypedDataDefinitionThe full EIP-712 typed data definition, including domain, types, primary type, and message.
import ( "math/big" "github.com/ChefBingbong/viem-go/utils/signature")
typedData := signature.TypedDataDefinition{ Domain: signature.TypedDataDomain{ Name: "Ether Mail", Version: "1", ChainId: big.NewInt(1), VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", }, Types: map[string][]signature.TypedDataField{ "Person": { {Name: "name", Type: "string"}, {Name: "wallet", Type: "address"}, }, "Mail": { {Name: "from", Type: "Person"}, {Name: "to", Type: "Person"}, {Name: "contents", Type: "string"}, }, }, PrimaryType: "Mail", Message: map[string]any{ "from": map[string]any{ "name": "Cow", "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", }, "to": map[string]any{ "name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", }, "contents": "Hello, Bob!", },}
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})any (accepts string, []byte, or *signature.Signature)The signature of the typed data.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})*uint64Only used when verifying typed data that was signed by a Smart Contract Account. The block number to check if the contract was already deployed.
blockNum := uint64(42069)valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...", BlockNumber: &blockNum,})BlockTag"latest"Only used when verifying typed data that was signed by a Smart Contract Account. The block tag to check if the contract was already deployed.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...", BlockTag: public.BlockTagSafe,})*common.AddressThe ERC-4337 Account Factory address for counterfactual verification. Used with FactoryData for undeployed smart accounts.
factoryAddr := common.HexToAddress("0x...")valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", Factory: &factoryAddr, FactoryData: factoryCalldata,})[]byteThe calldata to deploy the account via Factory. Used with Factory for undeployed smart accounts.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", Factory: &factoryAddr, FactoryData: factoryCalldata,})*common.AddressThe address of a deployed ERC-6492 signature verifier contract. If provided, uses this contract instead of deployless verification.
verifierAddr := common.HexToAddress("0x...")valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", ERC6492VerifierAddress: &verifierAddr,})Underlying JSON-RPC method used by this action.
Uses eth_call to verify signatures onchain via ERC-1271 or ERC-6492.