Skip to content

.to_message() fails on Arrays #16

Open

Description

@jvinet

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'

Activity

  1. numpde commented on Jun 22, 2022

    @numpde

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

  2. gqoew commented on Jun 28, 2022

    @gqoew

    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'

  3. PierreMkt commented on Jul 14, 2022

    @PierreMkt

    Same error. Any workaround found ?

  4. jvinet commented on Jul 20, 2022

    @jvinet
    Author

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

    Perhaps it can work for you, too.

  5. josh-davis-vicinft commented on Dec 22, 2022

    @josh-davis-vicinft

    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.

  6. hao0707 commented on Feb 15, 2023

    @hao0707

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

  7. BoboTiG commented on Oct 18, 2024

    @BoboTiG

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions