mirror of https://github.com/nucypher/nucypher.git
Merge pull request #3221 from derekpierre/bye-bye-712structs
Remove `eip712_structs` dependencypull/3234/head
commit
e39a1ab888
1
Pipfile
1
Pipfile
|
@ -27,7 +27,6 @@ aiohttp = "==3.8.2"
|
|||
flask = "*"
|
||||
requests = "*"
|
||||
# Third-Party Ethereum
|
||||
eip712-structs = "*"
|
||||
eth-tester = "*" # providers.py still uses this
|
||||
py-evm = "*"
|
||||
web3 = ">=6.0.0"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
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.messages import HexBytes, SignableMessage
|
||||
from eth_account.messages import HexBytes
|
||||
from eth_typing import ChecksumAddress
|
||||
from eth_utils import to_checksum_address
|
||||
|
||||
|
@ -17,15 +17,6 @@ USER_ADDRESS_CONTEXT = ":userAddress"
|
|||
|
||||
_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:
|
||||
# Expected format:
|
||||
|
@ -44,11 +35,17 @@ def _recover_user_address(**context) -> ChecksumAddress:
|
|||
signature = user_address_info["signature"]
|
||||
user_address = to_checksum_address(user_address_info["address"])
|
||||
eip712_message = user_address_info["typedData"]
|
||||
message, domain = UserAddress.from_message(eip712_message)
|
||||
signable_message = SignableMessage(
|
||||
HexBytes(_EIP712_VERSION_BYTE),
|
||||
header=domain.hash_struct(),
|
||||
body=message.hash_struct(),
|
||||
|
||||
# convert hex data for byte fields - bytes are expected by underlying library
|
||||
# 1. salt
|
||||
salt = eip712_message["domain"]["salt"]
|
||||
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:
|
||||
# data could not be processed
|
||||
|
|
|
@ -133,7 +133,9 @@ def subscription_manager_get_policy_zeroized_policy_struct_condition(
|
|||
@pytest.fixture
|
||||
def subscription_manager_is_active_policy_condition(testerchain, test_registry):
|
||||
subscription_manager = ContractAgency.get_agent(
|
||||
SubscriptionManagerAgent, registry=test_registry
|
||||
SubscriptionManagerAgent,
|
||||
registry=test_registry,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
condition = ContractCondition(
|
||||
contract_address=subscription_manager.contract.address,
|
||||
|
|
|
@ -25,7 +25,11 @@ from nucypher.policy.conditions.exceptions import (
|
|||
RPCExecutionFailed,
|
||||
)
|
||||
from nucypher.policy.conditions.lingo import ConditionLingo, ReturnValueTest
|
||||
from tests.constants import TEST_POLYGON_PROVIDER_URI, TESTERCHAIN_CHAIN_ID
|
||||
from tests.constants import (
|
||||
TEST_ETH_PROVIDER_URI,
|
||||
TEST_POLYGON_PROVIDER_URI,
|
||||
TESTERCHAIN_CHAIN_ID,
|
||||
)
|
||||
from tests.utils.policy import make_message_kits
|
||||
|
||||
|
||||
|
@ -97,7 +101,6 @@ def test_user_address_context_variable_verification(testerchain, valid_user_addr
|
|||
_recover_user_address(**invalid_signature_context)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="TODO")
|
||||
@mock.patch(
|
||||
"nucypher.policy.conditions.evm.get_context_value",
|
||||
side_effect=_dont_validate_user_address,
|
||||
|
@ -269,7 +272,6 @@ def test_erc721_evm_condition_balanceof_evaluation(
|
|||
assert not condition_result
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="execution reverted: Invalid timestamps")
|
||||
def test_subscription_manager_is_active_policy_condition_evaluation(
|
||||
testerchain,
|
||||
enacted_policy,
|
||||
|
@ -295,7 +297,6 @@ def test_subscription_manager_is_active_policy_condition_evaluation(
|
|||
assert not condition_result
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="execution reverted: Invalid timestamps")
|
||||
def test_subscription_manager_get_policy_policy_struct_condition_evaluation(
|
||||
testerchain,
|
||||
enacted_policy,
|
||||
|
@ -326,7 +327,6 @@ def test_subscription_manager_get_policy_policy_struct_condition_evaluation(
|
|||
assert condition_result is True # zeroized policy was indeed returned
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="invalid timestamps")
|
||||
def test_subscription_manager_get_policy_policy_struct_condition_key_tuple_evaluation(
|
||||
testerchain,
|
||||
test_registry,
|
||||
|
@ -344,7 +344,9 @@ def test_subscription_manager_get_policy_policy_struct_condition_key_tuple_evalu
|
|||
":hrac": bytes(enacted_policy.hrac),
|
||||
} # user-defined context vars
|
||||
subscription_manager = ContractAgency.get_agent(
|
||||
SubscriptionManagerAgent, registry=test_registry
|
||||
SubscriptionManagerAgent,
|
||||
registry=test_registry,
|
||||
provider_uri=TEST_ETH_PROVIDER_URI,
|
||||
)
|
||||
|
||||
# test "sponsor" key (owner is the same as sponsor for this policy)
|
||||
|
|
Loading…
Reference in New Issue