View Source DiodeClient.EIP712 (Diode Client v1.3.1)
EIP-712 implementation
Examples
# Example 1: Using separate arguments
iex> domain_data = %{
...> "name" => "Ether Mail",
...> "version" => "1",
...> "chainId" => 1,
...> "verifyingContract" => "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
...> "salt" => "decafbeef"
...> }
iex> message_types = %{
...> "Person" => [
...> %{"name" => "name", "type" => "string"},
...> %{"name" => "wallet", "type" => "address"}
...> ],
...> "Mail" => [
...> %{"name" => "from", "type" => "Person"},
...> %{"name" => "to", "type" => "Person"},
...> %{"name" => "contents", "type" => "string"}
...> ]
...> }
iex> message_data = %{
...> "from" => %{
...> "name" => "Cow",
...> "wallet" => "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
...> },
...> "to" => %{
...> "name" => "Bob",
...> "wallet" => "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
...> },
...> "contents" => "Hello, Bob!"
...> }
iex> hashed_message = DiodeClient.EIP712.hash_typed_data(%{
...> "types" => message_types,
...> "primaryType" => "Mail",
...> "domain" => domain_data,
...> "message" => message_data
...> })
iex> DiodeClient.Base16.encode(hashed_message)
"0xc5bb16ccc59ae9a3ad1cb8343d4e3351f057c994a97656e1aff8c134e56f7530"
# Example 2: Using a single full message
iex> full_message = %{
...> "types" => %{
...> "EIP712Domain" => [
...> %{"name" => "name", "type" => "string"},
...> %{"name" => "version", "type" => "string"},
...> %{"name" => "chainId", "type" => "uint256"},
...> %{"name" => "verifyingContract", "type" => "address"},
...> %{"name" => "salt", "type" => "bytes32"}
...> ],
...> "Person" => [
...> %{"name" => "name", "type" => "string"},
...> %{"name" => "wallet", "type" => "address"}
...> ],
...> "Mail" => [
...> %{"name" => "from", "type" => "Person"},
...> %{"name" => "to", "type" => "Person"},
...> %{"name" => "contents", "type" => "string"}
...> ]
...> },
...> "primaryType" => "Mail",
...> "domain" => %{
...> "name" => "Ether Mail",
...> "version" => "1",
...> "chainId" => 1,
...> "verifyingContract" => "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
...> "salt" => "decafbeef"
...> },
...> "message" => %{
...> "from" => %{
...> "name" => "Cow",
...> "wallet" => "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
...> },
...> "to" => %{
...> "name" => "Bob",
...> "wallet" => "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
...> },
...> "contents" => "Hello, Bob!"
...> }
...> }
iex> hashed_message = DiodeClient.EIP712.hash_typed_data(full_message)
iex> DiodeClient.Base16.encode(hashed_message)
"0xc5bb16ccc59ae9a3ad1cb8343d4e3351f057c994a97656e1aff8c134e56f7530"
.. _EIP-712: https://eips.ethereum.org/EIPS/eip-712