Skip to content

Commit 1616b95

Browse files
authored
Merge pull request #1918 from vae520283995/master
Update StructuredDataEncoder.java
2 parents 61b3285 + 151d6aa commit 1616b95

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

crypto/src/main/java/org/web3j/crypto/StructuredDataEncoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ private byte[] convertToEncodedItem(String baseType, Object data) {
260260
rawValue.length);
261261
}
262262
} else if (baseType.equals("string")) {
263-
hashBytes = ((String) data).getBytes();
263+
hashBytes = Numeric.hexStringToByteArray(sha3String((String) data));
264264
} else if (baseType.equals("bytes")) {
265-
hashBytes = Numeric.hexStringToByteArray((String) data);
265+
hashBytes = sha3(Numeric.hexStringToByteArray((String) data));
266266
} else {
267267
byte[] b = convertArgToBytes((String) data);
268268
BigInteger bi = new BigInteger(1, b);

crypto/src/test/java/org/web3j/crypto/StructuredDataTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ public void testValidStructureWithArrays() throws IOException {
308308
(HashMap<String, Object>) dataEncoder.jsonMessageObject.getMessage());
309309

310310
String expectedMessageStructHash =
311-
"0xc1c7d7b7dab9a65b30a6e951923b2d54536778329712e2239ed8a3f2f5f2329f";
311+
"0x14f510c172a64b76f1105338b2e0b09dccfa4aef922131716d58d7fd94e097e8";
312312

313313
assertEquals(expectedMessageStructHash, Numeric.toHexString(dataHash));
314314

315315
assertEquals(
316-
"0x935426a6009a3798ee87cd16ebeb9cea26b29d2d3762ac0951166d032f55d522",
316+
"0xa31e6ec120743db6e47cf44cd6b116cc4383ff4875cf823308938f8ba4566cc0",
317317
Numeric.toHexString(dataEncoder.hashStructuredData()));
318318
}
319319

crypto/src/test/resources/structured_data_json_files/ValidStructuredArrayData.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
-25
1919
],
2020
"ids": [
21-
1,
22-
2
21+
"23ee3e3",
22+
"3e2e23"
2323
]
2424
},
2525
"to": [
@@ -36,9 +36,9 @@
3636
-300
3737
],
3838
"ids": [
39-
0,
40-
3,
41-
7
39+
"2ed2d2",
40+
"21ew2e",
41+
"ewewe2"
4242
]
4343
}
4444
]
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"name": "ids",
95-
"type": "uint16[]"
95+
"type": "string[]"
9696
}
9797
]
9898
}

0 commit comments

Comments
 (0)