Skip to content

Commit

Permalink
feat: even simpler last time maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 30, 2023
1 parent 1dd92bc commit d960c93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions eip712/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def signable_message(self) -> SignableMessage:
)


def eip712_encode(typed_data: Dict[str, Any]) -> List[bytes]:
def encode(typed_data: Dict[str, Any]) -> List[bytes]:
encoded_domain = encode_data("EIP712Domain", typed_data["types"], typed_data["domain"])
parts = [bytes.fromhex("1901"), keccak(encoded_domain)]

Expand All @@ -162,7 +162,7 @@ def eip712_encode(typed_data: Dict[str, Any]) -> List[bytes]:
return parts


def eip712_encode_hash(typed_data) -> str:
encoded_data = eip712_encode(typed_data)
def calculate_hash(typed_data) -> str:
encoded_data = encode(typed_data)
value = keccak(b"".join(encoded_data))
return add_0x_prefix(cast(HexStr, value.hex()))
4 changes: 2 additions & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from eth_account._utils.structured_data.hashing import hash_message

from eip712.common import SAFE_VERSIONS, create_safe_tx_def
from eip712.messages import eip712_encode_hash
from eip712.messages import calculate_hash

MAINNET_MSIG_ADDRESS = "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52"
GOERLI_MSIG_ADDRESS = "0x3c59eC3912A6A0c8690ec548D87FB55C3Ba62aBa"
Expand Down Expand Up @@ -47,6 +47,6 @@ def test_gnosis_goerli_safe_tx():
value=convert("1 ETH", int),
)

actual = eip712_encode_hash(msg)
actual = calculate_hash(msg)
expected = "0xbbb1cbed7c3679b5d5764df26af8fab1b15f3a15c084db9082dffb3624ca74ee"
assert actual == expected

0 comments on commit d960c93

Please sign in to comment.