Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/nameguard-python/nameguard/nameguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def init_inspector():
return Inspector(config)


ens_contract_adresses = {
ens_contract_addresses = {
'0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85', # Base Registrar
'0xd4416b13d2b3a9abae7acd5d6c2bbdbe25686401', # Name Wrapper
}
Expand Down Expand Up @@ -512,7 +512,7 @@ async def fake_eth_name_check(self, network_name, contract_address, token_id) ->

token_type = res_json['id']['tokenMetadata']['tokenType']

if token_type not in ['ERC721', 'ERC1155'] and contract_address in ens_contract_adresses:
if token_type not in ['ERC721', 'ERC1155'] and contract_address in ens_contract_addresses:
return FakeEthNameCheckResult(
status=FakeEthNameCheckStatus.UNKNOWN_NFT, nameguard_report=None, investigated_fields=None
)
Expand Down Expand Up @@ -543,7 +543,7 @@ async def fake_eth_name_check(self, network_name, contract_address, token_id) ->
except KeyError:
pass

if contract_address in ens_contract_adresses:
if contract_address in ens_contract_addresses:
if ALCHEMY_UNKNOWN_NAME.match(title):
unknown_name = f"[{res_json['id']['tokenId'][2:]}].eth"
investigated_fields['title'] = unknown_name
Expand All @@ -555,7 +555,7 @@ async def fake_eth_name_check(self, network_name, contract_address, token_id) ->
async def _fake_eth_name_check(
self, network_name, contract_address, fields: dict[str, str]
) -> FakeEthNameCheckResult:
if contract_address in ens_contract_adresses:
if contract_address in ens_contract_addresses:
if 'title' not in fields:
raise MissingTitle()

Expand Down
26 changes: 12 additions & 14 deletions packages/nameguard-python/nameguard/our_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from ens.constants import ENS_EXTENDED_RESOLVER_INTERFACE_ID, EMPTY_SHA3_BYTES
from ens.ens import _resolver_supports_interface, ENS
from ens.exceptions import ENSValidationError
from ens.exceptions import ENSValidationError, ENSValueError
from ens.utils import address_to_reverse_domain, is_empty_name, is_none_or_zero_address, Web3

# from ens.utils import normalize_name
Expand All @@ -39,17 +39,17 @@
def label_to_hash(label: str) -> HexBytes:
# label = normalize_name(label)
if '.' in label:
raise ValueError(f"Cannot generate hash for label {label!r} with a '.'")
raise ENSValueError(f"Cannot generate hash for label {label!r} with a '.'")
return Web3().keccak(text=label)


def normal_name_to_hash(name: str) -> HexBytes:
"""
This method will not normalize the name. 'normal' name here means the name
should already be normalized before calling this method.
Hashes a pre-normalized name.
The normalization of the name is a prerequisite and is not handled by this function.

:param name: the name to hash - should already be normalized
:return: namehash the hash of the name
:param str name: A normalized name string to be hashed.
:return: namehash - the hash of the name
:rtype: HexBytes
"""
node = EMPTY_SHA3_BYTES
Expand All @@ -71,7 +71,7 @@ def raw_name_to_hash(name: str) -> HexBytes:
behind the scenes. For advanced usage, it is a helpful utility.

This normalizes the name with `nameprep
<https://github.com/ethereum/EIPs/blob/master/EIPS/eip-137.md#name-syntax>`_
<https://github.com/ethereum/EIPs/blob/master/EIPS/eip-137.md#name-syntax>`_ # blocklint: pragma # noqa: E501
before hashing.

:param str name: ENS name to hash
Expand All @@ -85,7 +85,7 @@ def raw_name_to_hash(name: str) -> HexBytes:


def ens_encode_name(name: str) -> bytes:
"""
r"""
Encode a name according to DNS standards specified in section 3.1
of RFC1035 with the following validations:

Expand Down Expand Up @@ -135,9 +135,7 @@ def name(self, address: ChecksumAddress) -> Optional[str]:

# To be absolutely certain of the name, via reverse resolution,
# the address must match in the forward resolution
result = name if to_checksum_address(address) == self.address(name) else None

return result
return name if to_checksum_address(address) == self.address(name) else None

def resolver(self, name: str) -> Optional['Contract']:
"""
Expand All @@ -154,7 +152,7 @@ def resolver(self, name: str) -> Optional['Contract']:
def namehash(name: str) -> HexBytes:
return raw_name_to_hash(name)

def _resolve(self, name: str, fn_name: str = 'addr') -> Optional[Union[ChecksumAddress, str]]:
def _resolve(self, name: str, fn_name: str = 'addr') -> Optional[Union[ChecksumAddress, str]]: # OK
# normal_name = normalize_name(name)
normal_name = name
resolver, current_name = self._get_resolver(normal_name, fn_name)
Expand All @@ -167,9 +165,9 @@ def _resolve(self, name: str, fn_name: str = 'addr') -> Optional[Union[ChecksumA
if _resolver_supports_interface(resolver, ENS_EXTENDED_RESOLVER_INTERFACE_ID):
contract_func_with_args = (fn_name, [node])

calldata = resolver.encodeABI(*contract_func_with_args)
calldata = resolver.encode_abi(*contract_func_with_args)
contract_call_result = resolver.caller.resolve(
ens_encode_name(normal_name), # TODO ens_encode_name
ens_encode_name(normal_name),
calldata,
)
result = self._decode_ensip10_resolve_data(contract_call_result, resolver, fn_name)
Expand Down
8 changes: 4 additions & 4 deletions packages/nameguard-python/nameguard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def labelhash_in_name(x: str) -> bool:


def hexbytes_to_int(hb: HexBytes) -> int:
return int(hb.hex(), base=16)
return int(hb.to_0x_hex(), base=16)


def int_to_hexstr(n: int, hex_len=64) -> str:
Expand Down Expand Up @@ -69,7 +69,7 @@ def int_to_hexstr(n: int, hex_len=64) -> str:


def labelhash_from_label(label: str) -> str:
return Web3().keccak(text=label).hex()
return Web3().keccak(text=label).to_0x_hex()


def namehash_from_name(name: str) -> str:
Expand All @@ -86,13 +86,13 @@ def namehash_from_name(name: str) -> str:
else:
labelhash = Web3().keccak(text=label)
node = Web3().keccak(node + labelhash)
return node.hex()
return node.to_0x_hex()


def namehash_from_labelhash(labelhash_hexstr: str, parent_name='eth') -> str:
parent_namehash_hexstr = namehash_from_name(parent_name)
node = Web3().keccak(HexBytes(parent_namehash_hexstr) + HexBytes(labelhash_hexstr))
return node.hex()
return node.to_0x_hex()


def validate_token_id(token_id: str) -> str:
Expand Down
Loading
Loading