ApeWorX / eip712

Message classes for typed structured data hashing and signing in Ethereum
Apache License 2.0
42 stars 19 forks source link

Interoperability with eth-account's SignableMessage #1

Closed lost-theory closed 1 year ago

lost-theory commented 3 years ago

From the TODO here:

https://github.com/ApeWorX/eip712/blob/0832ca92a29b2cae97dab78437d4ac491c140f15/eip712/messages.py#L70

We would like our new EIP712Message class to be interoperable with eth-account's SignableMessage:

https://github.com/ethereum/eth-account/blob/34fd5907d35e85b22212ecfff125e3f4cbb8c2ec/eth_account/messages.py#L39

We could either try to make the new class a subclass of SignableMessage (not just duck typing with the same attributes, but something that would make mypy typecheck it correctly), or add a method like as_signable_message() to build an instance of that class.

While we're making this change, we could add an as_abi_tuple() method that will return a tuple usable in contract calls, e.g.:

class Permit(EIP712Message):
    ...

permit = Permit(...)
signature = account.sign_message(permit.as_signable_message())

tx = contract.permit(*permit.as_abi_tuple(), signature, ...)
lost-theory commented 3 years ago

More discussion here:

https://github.com/ethereum/eth-account/pull/111/files/bba43179c80462ff9922e58229f037f60e3c7f0e#r598135621