mirror of https://github.com/nucypher/nucypher.git
Remove the use of eip712_structs for processing eip712 message - use eth_account.message.encode_structured_data instead.
This removes reliance on eip712_structs and therefore pysha3.pull/3221/head
parent
d9bfd1e86a
commit
7b15f9cd41
1
Pipfile
1
Pipfile
|
@ -27,7 +27,6 @@ aiohttp = "==3.8.2"
|
||||||
flask = "*"
|
flask = "*"
|
||||||
requests = "*"
|
requests = "*"
|
||||||
# Third-Party Ethereum
|
# Third-Party Ethereum
|
||||||
eip712-structs = "*"
|
|
||||||
eth-tester = "*" # providers.py still uses this
|
eth-tester = "*" # providers.py still uses this
|
||||||
py-evm = "*"
|
py-evm = "*"
|
||||||
web3 = ">=6.0.0"
|
web3 = ">=6.0.0"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from eip712_structs import Bytes, EIP712Struct, String, Uint
|
import eth_account.messages
|
||||||
from eth_account.account import Account
|
from eth_account.account import Account
|
||||||
from eth_account.messages import HexBytes, SignableMessage
|
from eth_account.messages import HexBytes
|
||||||
from eth_typing import ChecksumAddress
|
from eth_typing import ChecksumAddress
|
||||||
from eth_utils import to_checksum_address
|
from eth_utils import to_checksum_address
|
||||||
|
|
||||||
|
@ -17,15 +17,6 @@ USER_ADDRESS_CONTEXT = ":userAddress"
|
||||||
|
|
||||||
_CONTEXT_PREFIX = ":"
|
_CONTEXT_PREFIX = ":"
|
||||||
|
|
||||||
_EIP712_VERSION_BYTE = b"\x01"
|
|
||||||
|
|
||||||
|
|
||||||
class UserAddress(EIP712Struct):
|
|
||||||
address = String()
|
|
||||||
blockNumber = Uint()
|
|
||||||
blockHash = Bytes(32)
|
|
||||||
signatureText = String()
|
|
||||||
|
|
||||||
|
|
||||||
def _recover_user_address(**context) -> ChecksumAddress:
|
def _recover_user_address(**context) -> ChecksumAddress:
|
||||||
# Expected format:
|
# Expected format:
|
||||||
|
@ -44,11 +35,17 @@ def _recover_user_address(**context) -> ChecksumAddress:
|
||||||
signature = user_address_info["signature"]
|
signature = user_address_info["signature"]
|
||||||
user_address = to_checksum_address(user_address_info["address"])
|
user_address = to_checksum_address(user_address_info["address"])
|
||||||
eip712_message = user_address_info["typedData"]
|
eip712_message = user_address_info["typedData"]
|
||||||
message, domain = UserAddress.from_message(eip712_message)
|
|
||||||
signable_message = SignableMessage(
|
# convert hex data for byte fields - bytes are expected by underlying library
|
||||||
HexBytes(_EIP712_VERSION_BYTE),
|
# 1. salt
|
||||||
header=domain.hash_struct(),
|
salt = eip712_message["domain"]["salt"]
|
||||||
body=message.hash_struct(),
|
eip712_message["domain"]["salt"] = HexBytes(salt)
|
||||||
|
# 2. blockHash
|
||||||
|
blockHash = eip712_message["message"]["blockHash"]
|
||||||
|
eip712_message["message"]["blockHash"] = HexBytes(blockHash)
|
||||||
|
|
||||||
|
signable_message = eth_account.messages.encode_structured_data(
|
||||||
|
primitive=eip712_message
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# data could not be processed
|
# data could not be processed
|
||||||
|
|
Loading…
Reference in New Issue