Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class TypedData
- Object
- TypedData
EIP-712 typed structured data: the eth_signTypedData_v4 document permits, orders and
meta-transactions are signed as.
String jsonFromTheDapp = "{...}"; // the eth_signTypedData_v4 argument
byte[] privateKey = SecureRandom.bytes(32);
TypedData doc = TypedData.fromJson(jsonFromTheDapp);
byte[] signature = doc.sign(privateKey); // r || s || v
The document is the JSON a dapp sends: types, primaryType, domain and message.
When types omits EIP712Domain, it is derived from the domain fields present, as
wallets do.
Constructors
public TypedData(Map<String, List<String[]>> types, String primaryType, Map<String, Object> domain, Map<String, Object> message) | A document from its parts. |
Methods
public static TypedData fromJson(String json) | Reads the eth_signTypedData_v4 JSON document. |
public byte[] hash() | The 32-byte digest a wallet signs: keccak256(0x1901 || domainSeparator || hashStruct(message)). |
public byte[] domainSeparator() | hashStruct(EIP712Domain, domain). |
public byte[] messageHash() | The hashStruct of the message. |
public byte[] sign(byte[] privateKey) | Signs the document, answering r || s || v with v 27 or 28. |
public EvmAddress recover(byte[] signature65) | The address that signed the document. |
public String encodeType(String type) | The encodeType string of a struct, such as Mail(Person from,Person to,string contents)Person(string name,address wallet). |
public byte[] hashStruct(String type, Map<String, Object> value) | keccak256(typeHash || encodeData(value)) of a struct. |
Inherited methods
Constructor details
TypedData
public TypedData(Map<String, List<String[]>> types, String primaryType, Map<String, Object> domain, Map<String, Object> message)A document from its parts.
Parameters
typesMap<String, List<String[]>>- struct name to its members, each
{name, type}, in declaration order primaryTypeString- the struct
messageis an instance of domainMap<String, Object>- the
EIP712Domainvalues messageMap<String, Object>- the values of the primary struct
Method details
fromJson
public static TypedData fromJson(String json)Reads the
eth_signTypedData_v4 JSON document.Throws
IllegalArgumentException- for malformed JSON or a document missing a part
hash
public byte[] hash()The 32-byte digest a wallet signs:
keccak256(0x1901 || domainSeparator || hashStruct(message)).domainSeparator
public byte[] domainSeparator()hashStruct(EIP712Domain, domain).messageHash
public byte[] messageHash()The
hashStruct of the message.sign
public byte[] sign(byte[] privateKey)Signs the document, answering
r || s || v with v 27 or 28.recover
public EvmAddress recover(byte[] signature65)The address that signed the document.
encodeType
public String encodeType(String type)The
encodeType string of a struct, such as
Mail(Person from,Person to,string contents)Person(string name,address wallet).hashStruct
public byte[] hashStruct(String type, Map<String, Object> value)keccak256(typeHash || encodeData(value)) of a struct.