EIP-712 domain separator — the standard EIP712Domain struct
(name, version, chainId, verifyingContract, salt). Each field is
optional; only the populated fields contribute to the encoded domain type.
Summary
Functions
Deserializes a domain from JSON or JavaScript encoding to a struct.
Builds the EIP-712 domain type based on a given domain.
Serializes a domain, such that it can be JSON-encoded or passed to JavaScript.
Serializes a domain's keys to be JSON-compatible. This is so that it can be used
as a value for hashStruct, per the EIP-712 spec to build a domain specifier.
Types
Functions
Deserializes a domain from JSON or JavaScript encoding to a struct.
Examples
iex> %{
...> "name" => "Ether Mail",
...> "version" => "1",
...> "chainId" => 1,
...> "verifyingContract" => "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
...> }
...> |> Cartouche.Typed.Domain.deserialize()
%Cartouche.Typed.Domain{
name: "Ether Mail",
version: "1",
chain_id: 1,
verifying_contract: ~h[CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
}
iex> %{
...> "name" => "Ether Mail",
...> "version" => "1"
...> }
...> |> Cartouche.Typed.Domain.deserialize()
%Cartouche.Typed.Domain{
name: "Ether Mail",
version: "1"
}
@spec domain_type(t()) :: %{required(String.t()) => Cartouche.Typed.Type.t()}
Builds the EIP-712 domain type based on a given domain.
Examples
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1",
...> chain_id: 1,
...> verifying_contract: ~h[CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
...> }
...> |> Cartouche.Typed.Domain.domain_type()
%{"EIP712Domain" => %Cartouche.Typed.Type{fields: [{"name", :string}, {"version", :string}, {"chainId", {:uint, 256}}, {"verifyingContract", :address}]}}
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1",
...> }
...> |> Cartouche.Typed.Domain.domain_type()
%{"EIP712Domain" => %Cartouche.Typed.Type{fields: [{"name", :string}, {"version", :string}]}}
Serializes a domain, such that it can be JSON-encoded or passed to JavaScript.
Examples
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1",
...> chain_id: 1,
...> verifying_contract: ~h[CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
...> }
...> |> Cartouche.Typed.Domain.serialize()
%{
"name" => "Ether Mail",
"version" => "1",
"chainId" => 1,
"verifyingContract" => "0xcccccccccccccccccccccccccccccccccccccccc",
}
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1"
...> }
...> |> Cartouche.Typed.Domain.serialize()
%{
"name" => "Ether Mail",
"version" => "1"
}
Serializes a domain's keys to be JSON-compatible. This is so that it can be used
as a value for hashStruct, per the EIP-712 spec to build a domain specifier.
Examples
iex> use Cartouche.Hex
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1",
...> chain_id: 1,
...> verifying_contract: ~h[CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
...> }
...> |> Cartouche.Typed.Domain.serialize_keys()
%{
"name" => "Ether Mail",
"version" => "1",
"chainId" => 1,
"verifyingContract" => ~h[CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
}
iex> use Cartouche.Hex
iex> %Cartouche.Typed.Domain{
...> name: "Ether Mail",
...> version: "1",
...> }
...> |> Cartouche.Typed.Domain.serialize_keys()
%{
"name" => "Ether Mail",
"version" => "1"
}