The documentation says that sha3
calculates the hash of the tightly packed arguments. Numbers seem to be converted to ASCII chars.
Consider using sha3(values)
in Solidity with the type int8[3] values
, and the Javascript array let values = [-1, 0, 1];
, how can I calculate the web3.sha3(...)
hash in Javascript to get the same result as in Solidity?
What I tried so far:
web3.sha3(values.map((x) => String.fromCharCode(x)).join(''))
Also, why are these two different:
> sha3([int8(-1), int8(0), int8(1)])
0x485d3017777c5ed1be9073116ba54b48f208c386ab83497d9c3a015a8382849e
> sha3(int8(-1), int8(0), int8(1))
0x8404dcb0a81bbb8eccbf96f10e1874b12380080d2143c02c8e44db200aaff384
I found this issue on Github, which doesn't seem to handle my case of negative numbers. Maybe I should convert to uint in Javascript?