pub trait Eip712 {
    type Error: Error + Send + Sync + Debug;

    // Required methods
    fn domain(&self) -> Result<EIP712Domain, Self::Error>;
    fn type_hash() -> Result<[u8; 32], Self::Error>;
    fn struct_hash(&self) -> Result<[u8; 32], Self::Error>;

    // Provided methods
    fn domain_separator(&self) -> Result<[u8; 32], Self::Error> { ... }
    fn encode_eip712(&self) -> Result<[u8; 32], Self::Error> { ... }
}
Expand description

Helper methods for computing the typed data hash used in eth_signTypedData.

The ethers-rs derive_eip712 crate provides a derive macro to implement the trait for a given struct. See documentation for derive_eip712 for more information and example usage.

For those who wish to manually implement this trait, see: https://eips.ethereum.org/EIPS/eip-712

Any rust struct implementing Eip712 must also have a corresponding struct in the verifying ethereum contract that matches its signature.

Required Associated Types§

source

type Error: Error + Send + Sync + Debug

User defined error type;

Required Methods§

source

fn domain(&self) -> Result<EIP712Domain, Self::Error>

Returns the current domain. The domain depends on the contract and unique domain for which the user is targeting. In the derive macro, these attributes are passed in as arguments to the macro. When manually deriving, the user will need to know the name of the domain, version of the contract, chain ID of where the contract lives and the address of the verifying contract.

source

fn type_hash() -> Result<[u8; 32], Self::Error>

This method is used for calculating the hash of the type signature of the struct. The field types of the struct must map to primitive ethereum types or custom types defined in the contract.

source

fn struct_hash(&self) -> Result<[u8; 32], Self::Error>

Hash of the struct, according to EIP-712 definition of hashStruct

Provided Methods§

source

fn domain_separator(&self) -> Result<[u8; 32], Self::Error>

Default implementation of the domain separator;

source

fn encode_eip712(&self) -> Result<[u8; 32], Self::Error>

When using the derive macro, this is the primary method used for computing the final EIP-712 encoded payload. This method relies on the aforementioned methods for computing the final encoded payload.

Object Safety§

This trait is not object safe.

Implementors§