コード例 #1
0
    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
コード例 #2
0
    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)."
            )
コード例 #3
0
    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
コード例 #4
0
 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)
コード例 #5
0
ファイル: main.py プロジェクト: ymcareer/web3.py
    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)
コード例 #6
0
    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
コード例 #7
0
    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
コード例 #8
0
ファイル: main.py プロジェクト: ymcareer/web3.py
 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)
コード例 #9
0
ファイル: main.py プロジェクト: ymcareer/web3.py
 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)
コード例 #10
0
    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
コード例 #11
0
    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
コード例 #12
0
 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)
コード例 #13
0
    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
コード例 #14
0
    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
コード例 #15
0
 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)
コード例 #16
0
    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
コード例 #17
0
    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
コード例 #18
0
    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)
コード例 #19
0
    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
コード例 #20
0
 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}"
コード例 #21
0
    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
コード例 #22
0
 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)
コード例 #23
0
    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
コード例 #24
0
    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)."
            )
コード例 #25
0
    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
コード例 #26
0
    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
コード例 #27
0
    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
コード例 #28
0
 def namehash(name: str) -> HexBytes:
     return raw_name_to_hash(name)
コード例 #29
0
 def numberSubnodes(self, node_name="root"):
     node_hash = raw_name_to_hash(node_name)
     num = ENS.functions.numberSubnodes(node_hash).call()
     return num
コード例 #30
0
 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