EIP-712: How to Verify Typed Data On Chain

Leon Do
Coinmonks

--

Implementing EIP-712: Typed structured data hashing and signing

Overview

The idea of EIP-712 is to standardize hashing and signing of typed structured data as instead to just byte strings. Below are the different ways of signing

Signing typed data allows the user to view human readable data before confirming instead of an arbitrary hexadecimal string.

Copy trading bots from the top traders. Try it for FREE.

Demo

https://leon-do.github.io/eip712-generator/

Signing

The message params are divided into:

Domain: The below values are hashed to prevent others dapp from using the same signature.

  • name: Name of the dapp
  • version: Version of the dapp
  • chainId: To prevent replay attacks
  • verifyingContract: Address of the contract that will verify the signature

Message: The typed data (JSON) to sign. In the above example, the data is { "myValue": 123 }

Primary Type: Represents the top-level type of the object

Types: Defines all of the types

Verifying

The smart contract function is divided into:

Defining types to match the signing (javascript) code.

Hashing the domain separator and the values.

Splitting the signature to r , s , v

ECRecover to verify the signature

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--