py-eip712-structs icon indicating copy to clipboard operation
py-eip712-structs copied to clipboard

.to_message() fails on Arrays

Open jvinet opened this issue 3 years ago • 7 comments

Test code:

import os
from eip712_structs import Bytes, Array, EIP712Struct, make_domain

class TestStruct(EIP712Struct):
    byte_array = Array(Bytes(32), 4)

byte_array = [os.urandom(32) for _ in range(4)]

domain = make_domain(name='hello')
s = TestStruct(byte_array=byte_array)
print(s.to_message(domain))

This code will raise:

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print(s.to_message(domain))
  File "site-packages/eip712_structs/struct.py", line 165, in to_message
    structs = {domain, self}
  File "site-packages/eip712_structs/struct.py", line 315, in __hash__
    value_hashes = [hash(k) ^ hash(v) for k, v in self.values.items()]
  File "site-packages/eip712_structs/struct.py", line 315, in <listcomp>
    value_hashes = [hash(k) ^ hash(v) for k, v in self.values.items()]
TypeError: unhashable type: 'list'

jvinet avatar Jun 10 '22 15:06 jvinet

Same problem here. How about changing to structs = [domain, self] in that line?

numpde avatar Jun 22 '22 10:06 numpde

I have the same error when I used .to_message() on Arrays

and when I use .signable_bytes(domain) I get:

AttributeError: 'bytes' object has no attribute 'version'

gqoew avatar Jun 28 '22 09:06 gqoew

Same error. Any workaround found ?

PierreMkt avatar Jul 14 '22 09:07 PierreMkt

This project appears to be dormant. I used a custom solution instead: https://github.com/jvinet/eip712

Perhaps it can work for you, too.

jvinet avatar Jul 20 '22 17:07 jvinet

This is fixed in my branch at https://github.com/ViciNFT/py-eip712-structs. The answer posted by @numpde is part of the solution, and there were a few other changes required.

josh-davis-vicinft avatar Dec 22 '22 19:12 josh-davis-vicinft

Array should pass variables of type tuple.Like this: byte_array = tuple([os.urandom(32) for _ in range(4)])

hao0707 avatar Feb 15 '23 07:02 hao0707

FTR it's fixed on my fork (available on PyPI): https://github.com/BoboTiG/py-eip712-structs-ng

BoboTiG avatar Oct 18 '24 08:10 BoboTiG