Class TypedData
java.lang.Object
com.codename1.crypto.evm.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]hashStruct(EIP712Domain, domain).encodeType(String type) TheencodeTypestring of a struct, such asMail(Person from,Person to,string contents)Person(string name,address wallet).static TypedDataReads theeth_signTypedData_v4JSON document.byte[]hash()The 32-byte digest a wallet signs:keccak256(0x1901 || domainSeparator || hashStruct(message)).byte[]hashStruct(String type, Map<String, Object> value) keccak256(typeHash || encodeData(value))of a struct.byte[]ThehashStructof the message.recover(byte[] signature65) The address that signed the document.byte[]sign(byte[] privateKey) Signs the document, answeringr || s || vwithv27 or 28.
-
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
-
types: struct name to its members, each{name, type}, in declaration order -
primaryType: the structmessageis an instance of -
domain: theEIP712Domainvalues -
message: the values of the primary struct
-
-
-
Method Details
-
fromJson
-
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()ThehashStructof the message. -
sign
public byte[] sign(byte[] privateKey) Signs the document, answeringr || s || vwithv27 or 28. -
recover
The address that signed the document. -
encodeType
-
hashStruct
-