def setAlaDIDPublicEntity(self, node_name, label, DID, name, DIDDocument, active, new_owner_address, caller_key): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) # Calculate the hash of the DID DIDHash = b.Web3.keccak(text=DID) success, tx_receipt, tx_hash = b.send_signed_tx( PublicResolver.functions.setAlaDIDPublicEntity( node_hash, label_hash, DIDHash, name, DIDDocument, active, new_owner_address, ), caller_key) return success, tx_receipt, tx_hash
def get_text(self, name: str, key: str) -> str: """ Get the value of a text record by key from an ENS name. :param str name: ENS name to look up :param str key: ENS name's text record key :return: ENS name's text record value :rtype: str :raises UnsupportedFunction: If the resolver does not support the "0x59d1d43c" interface id :raises ResolverNotFound: If no resolver is found for the provided name """ node = raw_name_to_hash(name) normal_name = normalize_name(name) r = self.resolver(normal_name) if r: if _resolver_supports_interface(r, GET_TEXT_INTERFACE_ID): return r.caller.text(node, key) else: raise UnsupportedFunction( f"Resolver for name {name} does not support `text` function." ) else: raise ResolverNotFound( f"No resolver found for name `{name}`. It is likely the name contains an " "unsupported top level domain (tld)." )
def setCredential(self, node_name="root", key=None, credentialHash=None, participants=[], caller_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) participantsHash = [] for i in range(5): if i < len(participants): participantsHash.append(self.hash(participants[i])) else: participantsHash.append(bytes(32)) success, tx_receipt, tx_hash = b.send_signed_tx( PublicResolver.functions.setCredential( node_hash, key, credentialHash, participantsHash[0], participantsHash[1], participantsHash[2], participantsHash[3], participantsHash[4], ), caller_key) return success, tx_receipt, tx_hash
def _set_resolver(self, name, resolver_addr=None, transact={}): if not resolver_addr: resolver_addr = self.address('resolver.eth') namehash = raw_name_to_hash(name) if self.ens.resolver(namehash) != resolver_addr: self.ens.setResolver(namehash, resolver_addr, transact=transact) return self._resolverContract(address=resolver_addr)
def setup_address(self, name, address=default, transact={}): """ Set up the name to point to the supplied address. The sender of the transaction must own the name, or its parent name. Example: If the caller owns ``parentname.eth`` with no subdomains and calls this method with ``sub.parentname.eth``, then ``sub`` will be created as part of this call. :param str name: ENS name to set up :param str address: name will point to this address, in checksum format. If ``None``, erase the record. If not specified, name will point to the owner's address. :param dict transact: the transaction configuration, like in :meth:`~web3.eth.Eth.sendTransaction` :raises InvalidName: if ``name`` has invalid syntax :raises UnauthorizedError: if ``'from'`` in `transact` does not own `name` """ owner = self.setup_owner(name, transact=transact) self._assert_control(owner, name) if is_none_or_zero_address(address): address = None elif address is default: address = owner elif is_binary_address(address): address = to_checksum_address(address) elif not is_checksum_address(address): raise ValueError("You must supply the address in checksum format") if self.address(name) == address: return None if address is None: address = EMPTY_ADDR_HEX transact['from'] = owner resolver = self._set_resolver(name, transact=transact) return resolver.functions.setAddr(raw_name_to_hash(name), address).transact(transact)
def owner(self, node_name="root"): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) owner = ENS.functions.owner(node_hash).call() return owner
def resolver(self, node_name="root"): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) Resolver_address = ENS.functions.resolver(node_hash).call() return Resolver_address
def _claim_ownership(self, owner, unowned, owned, old_owner=None, transact={}): transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner( raw_name_to_hash(owned), label_to_hash(label), owner ).transact(transact) owned = "%s.%s" % (label, owned)
def _set_resolver(self, name, resolver_addr=None, transact={}): if is_none_or_zero_address(resolver_addr): resolver_addr = self.address('resolver.eth') namehash = raw_name_to_hash(name) if self.ens.caller.resolver(namehash) != resolver_addr: self.ens.functions.setResolver( namehash, resolver_addr ).transact(transact) return self._resolverContract(address=resolver_addr)
def credential(self, node_name=None, key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) credentialHash, numParticipants = PublicResolver.functions.credential( node_hash, key).call() return credentialHash, numParticipants
def credentialParticipant(self, node_name=None, key=None, index=0): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) DIDhash, signed = PublicResolver.functions.credentialParticipant( node_hash, key, index).call() return DIDhash, signed
def _set_resolver(self, name: str, resolver_addr: ChecksumAddress = None, transact: "TxParams" = {}) -> 'Contract': if is_none_or_zero_address(resolver_addr): resolver_addr = self.address('resolver.eth') namehash = raw_name_to_hash(name) if self.ens.caller.resolver(namehash) != resolver_addr: self.ens.functions.setResolver(namehash, resolver_addr).transact(transact) return self._resolverContract(address=resolver_addr)
def AlaTSP(self, node_name="root", node_hash=None): if node_hash is None: if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) URI, org, active = PublicResolver.functions.AlaTSP(node_hash).call() return URI, org, active
def name(self, node_name="root", node_hash=None): if node_hash is None: if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) name = PublicResolver.functions.name(node_hash).call() return name
def _claim_ownership(self, owner: ChecksumAddress, unowned: Sequence[str], owned: str, old_owner: ChecksumAddress = None, transact: "TxParams" = {}) -> None: transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner(raw_name_to_hash(owned), label_to_hash(label), owner).transact(transact) owned = "%s.%s" % (label, owned)
def AlaTSPService(self, node_name="root", node_hash=None, index=0): if node_hash is None: if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) X509SKI, serviceName, X509Certificate, active = PublicResolver.functions.AlaTSPService( node_hash, index).call() return X509SKI, serviceName, X509Certificate, active
def AlaTSPNumberServices(self, node_name="root", node_hash=None): if node_hash is None: if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) numServices = PublicResolver.functions.AlaTSPNumberServices( node_hash).call() return numServices
def owner(self, name: str) -> ChecksumAddress: """ Get the owner of a name. Note that this may be different from the deed holder in the '.eth' registrar. Learn more about the difference between deed and name ownership in the ENS `Managing Ownership docs <http://docs.ens.domains/en/latest/userguide.html#managing-ownership>`_ :param str name: ENS name to look up :return: owner address :rtype: str """ node = raw_name_to_hash(name) return self.ens.caller.owner(node)
def setResolver(self, node_name="root", resolver_address=None, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) contract_fun = ENS.functions.setResolver(node_hash, resolver_address) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def _claim_ownership(self, owner: ChecksumAddress, unowned: Sequence[str], owned: str, old_owner: Optional[ChecksumAddress] = None, transact: Optional["TxParams"] = None) -> None: if not transact: transact = {} transact = deepcopy(transact) transact['from'] = old_owner or owner for label in reversed(unowned): self.ens.functions.setSubnodeOwner(raw_name_to_hash(owned), label_to_hash(label), owner).transact(transact) owned = f"{label}.{owned}"
def setName(self, node_name="root", name_to_resolve="root", current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) contract_fun = PublicResolver.functions.setName( node_hash, name_to_resolve) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def _set_resolver( self, name: str, resolver_addr: Optional[ChecksumAddress] = None, transact: Optional["TxParams"] = None ) -> Union['Contract', 'AsyncContract']: if not transact: transact = {} transact = deepcopy(transact) if is_none_or_zero_address(resolver_addr): resolver_addr = self.address('resolver.eth') namehash = raw_name_to_hash(name) if self.ens.caller.resolver(namehash) != resolver_addr: self.ens.functions.setResolver( namehash, resolver_addr ).transact(transact) return self._resolver_contract(address=resolver_addr)
def confirmCredential(self, node_name=None, key=None, participantDID=None, caller_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) participantHash = self.hash(participantDID) success, tx_receipt, tx_hash = b.send_signed_tx( PublicResolver.functions.confirmCredential(node_hash, key, participantHash), caller_key) return success, tx_receipt, tx_hash
def set_text( self, name: str, key: str, value: str, transact: "TxParams" = None ) -> HexBytes: """ Set the value of a text record of an ENS name. :param str name: ENS name :param str key: Name of the attribute to set :param str value: Value to set the attribute to :param dict transact: The transaction configuration, like in :meth:`~web3.eth.Eth.send_transaction` :return: Transaction hash :rtype: HexBytes :raises UnsupportedFunction: If the resolver does not support the "0x59d1d43c" interface id :raises ResolverNotFound: If no resolver is found for the provided name """ if not transact: transact = {} owner = self.owner(name) node = raw_name_to_hash(name) normal_name = normalize_name(name) transaction_dict = merge({'from': owner}, transact) r = self.resolver(normal_name) if r: if _resolver_supports_interface(r, GET_TEXT_INTERFACE_ID): return r.functions.setText(node, key, value).transact(transaction_dict) else: raise UnsupportedFunction( f"Resolver for name `{name}` does not support `text` function" ) else: raise ResolverNotFound( f"No resolver found for name `{name}`. It is likely the name contains an " "unsupported top level domain (tld)." )
def setAlaTSP(self, node_name, label, URI, org, active, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) contract_fun = PublicResolver.functions.setAlaTSP( node_hash, label_hash, URI, org, active) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def addAlaTSPService(self, node_name, label, X509SKI, serviceName, X509Certificate, active, current_owner_key=None): if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) label_hash = label_to_hash(label) contract_fun = PublicResolver.functions.addAlaTSPService( node_hash, label_hash, X509SKI, serviceName, X509Certificate, active) success, tx_receipt, tx_hash = b.send_signed_tx( contract_fun, current_owner_key) return success, tx_receipt, tx_hash
def AlaDIDPublicEntity(self, node_name="root", node_hash=None): if node_hash is None: if node_name == "root": node_hash = b.to_32byte_hex(0) else: node_hash = raw_name_to_hash(node_name) DIDHash, name, DIDDocument, active = PublicResolver.functions.AlaDIDPublicEntity( node_hash).call() if DIDDocument == "": return None, None, None, None # Verify integrity: the DIDHash should equal the hash of the DID inside the DIDDocument diddoc = json.loads(DIDDocument) DID = diddoc["id"] did_hash = b.Web3.keccak(text=DID) if did_hash == DIDHash: return DID, name, DIDDocument, active else: return None, None, None, None
def namehash(name: str) -> HexBytes: return raw_name_to_hash(name)
def numberSubnodes(self, node_name="root"): node_hash = raw_name_to_hash(node_name) num = ENS.functions.numberSubnodes(node_hash).call() return num
def subnode(self, node_name="root", index=0): node_hash = raw_name_to_hash(node_name) subnode = ENS.functions.subnode(node_hash, int(index)).call() return subnode