EIP712 { public String encodeData(String dataType, JSONObject data) throws Exception { JSONObject types = this.getTypes(); JSONArray dataTypeProperties = this.getDataType(dataType); List<Type> abiTypes = new ArrayList<>(); abiTypes.add(new ABITypeFactory().getType("bytes32", this.hashDataType(dataType))); for (int i = 0; i < dataTypeProperties.length(); i++) { JSONObject field = dataTypeProperties.getJSONObject(i); String fieldName = field.getString("name"); String fieldType = field.getString("type"); Object value = data.get(fieldName); if ("string".equals(fieldType) || "bytes".equals(fieldType)) { if (Numeric.containsHexPrefix((String)value)) { value = Numeric.toHexString(Hash.sha3(Numeric.hexStringToByteArray((String)value))); } else { value = Hash.sha3String(((String) value)); } fieldType = "bytes32"; } else if (null != getDataType(fieldType)) { value = Hash.sha3(this.encodeData(fieldType, (JSONObject) value)); fieldType = "bytes32"; } else if (fieldType.lastIndexOf(']') == fieldType.length() - 1) { throw new Exception("Arrays currently unimplemented in encodeData"); } abiTypes.add(new ABITypeFactory().getType(fieldType, value)); } return "0x" + FunctionEncoder.encodeConstructor(abiTypes); } EIP712(JSONObject txnObject); String encodeDataType(String dataType); String hashDataType(String dataType); String encodeData(String dataType, JSONObject data); String toEIP712TransactionHash(); static boolean validateData(JSONObject data);  }
@Test public void testEncodeData() { try { String encodeDataType = new EIP712(TypedDataInput).encodeData("Mail",TypedDataInput.optJSONObject("message")); assertEquals(EncodedData, encodeDataType); } catch (Exception e) { e.printStackTrace(); } }