Closed lost-theory closed 1 year ago
More info:
I used eth_account lib for structured_data encoding (your implementation looks the same). I got a result different from the result obtained when using the eth-sig-util (js library). To reproduce js result I add value = bytearray.fromhex(value.decode('utf-8').replace('0x', '')) before hashed_value = keccak(primitive=value)
in _encode_data method (eth_account._utils.structured_data.hashing.py) in case, when field["type"] == "bytes"
this case (rows 189:203 in hashing.py file)
elif field["type"] == "bytes":
if not isinstance(value, bytes):
raise TypeError(
"Value of {0} ({2}) in the struct {1} is of the type {3}, but expected "
"bytes value".format(
field["name"],
primary_type,
value,
type(value),
)
)
# Special case where the values need to be keccak hashed before they are encoded
value = bytearray.fromhex(value.decode('utf-8').replace('0x', ''))
hashed_value = keccak(primitive=value)
yield "bytes32", hashed_value
Got this question from a potential user:
From what I see the "v4" encoding is defined by Metamask here:
We don't have support for arrays at the moment. Here's how it's currently failing when trying to encode a
uint[]
field: