I am using Python 2.7 and need to find keccak hash for solidity events. However I don't see a default lib for the same.
I installed sha3 but it doesn't seem to provide this functionality. Tried pysha3 with below code
import sha3
k = sha3.keccak_512()
k.update('age')
k.hexdigest()
But got the error
AttributeError: 'module' object has no attribute 'keccak_512'
sha3 doesn't have this module indeed
>>> dir(sha3)
['SHA3224', 'SHA3256', 'SHA3384', 'SHA3512', 'SHAKE128', 'SHAKE256', '_SHA3Base', '_SHAKEBase', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_sha3', 'binascii', 'copy', 'hashlib', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'shake128', 'shake256']
pycryptodome
pip install pycryptodomepysha3
pip install pysha3Please note:
python3the strings need to be passed in binaryk.update(b'age')kagain otherwise it will update the value on top of the existing one.If you have both
sha3andpysha3, it won't work, sinceimport sha3will default tosha3lib.Online handy tool