Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signable_bytes() and to_message_json() throw exceptions #14

Open
anomit opened this issue Oct 3, 2019 · 1 comment
Open

signable_bytes() and to_message_json() throw exceptions #14

anomit opened this issue Oct 3, 2019 · 1 comment

Comments

@anomit
Copy link

anomit commented Oct 3, 2019

Code in question:

from eip712_structs import EIP712Struct, Address, String, Uint


class Identity(EIP712Struct):
    userId = Uint(256)
    wallet = Address()


class Message(EIP712Struct):
    actionType = String()
    timestamp = Uint(256)
    authorizer = Identity


class EIP712Domain(EIP712Struct):
    name = String()
    version = String()
    chainId = Uint(256)
    verifyingContract = Address()


verifying_contract_domain = EIP712Domain(
    name='VerifierApp101',
    version='1',
    chainId=8995,
    verifyingContract='0x8c1eD7e19abAa9f23c476dA86Dc1577F1Ef401f5'
)

user_identification = Identity(userId=123, wallet='0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC')
msg = Message(actionType='Action7440', timestamp=1570112162, authorizer=Identity)

print(msg.to_message_json(verifying_contract_domain))
print(msg.signable_bytes(verifying_contract_domain))

msg.to_message_json(verifying_contract_domain) throws the following exception:

Traceback (most recent call last):
  File "submit_proof.py", line 32, in <module>
    print(msg.to_message_json(verifying_contract_domain))
  File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 188, in to_message_json
    return json.dumps(message, cls=BytesJSONEncoder)
  File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/types.py", line 244, in default
    return super(BytesJSONEncoder, self).default(o)
  File "/Users/anomit/.pyenv/versions/3.6.5/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'OrderedAttributesMeta' is not JSON serializable

msg.signable_bytes(verifying_contract_domain) throws:

Traceback (most recent call last):
  File "submit_proof.py", line 32, in <module>
    print(msg.signable_bytes(verifying_contract_domain))
  File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 200, in signable_bytes
    result = b'\x19\x01' + domain.hash_struct() + self.hash_struct()
  File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 132, in hash_struct
    return keccak(b''.join([self.type_hash(), self.encode_value()]))
  File "/Users/anomit/.pyenv/versions/ev-cli/lib/python3.6/site-packages/eip712_structs/struct.py", line 61, in encode_value
    encoded_values.append(sub_struct.hash_struct())
TypeError: hash_struct() missing 1 required positional argument: 'self'
@BoboTiG
Copy link

BoboTiG commented Jan 12, 2024

Actually, the issue relies in your code: you do not use the proper authorizer object. To fix it:

- msg = Message(actionType='Action7440', timestamp=1570112162, authorizer=Identity)
+ msg = Message(actionType='Action7440', timestamp=1570112162, authorizer=user_identification)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants