def check_pkh_known_by_signer(self, key_name, timeout=None):

        signer_url = self.signer_endpoint
        cmd = f"keys/{key_name}"
        url = os.path.join(signer_url, cmd)

        signer_exception = (
            f"Error querying the signer at url {signer_url}. \n"
            f'Please make sure you have started the signer using "./tezos-signer launch http signer", \n'
            f"imported the secret key of the payout address {key_name}, \n"
            f"and specified the URL of signer using the flag -E http://<signer_addr>:<port> (default {PRIVATE_SIGNER_URL})"
        )

        try:
            response = self._do_request(method="GET", url=url, timeout=timeout)
        except Exception as e:
            raise ClientException(f"Exception: {e}\n{signer_exception}")
        if response.status_code != HTTPStatus.OK:
            raise ClientException(f"{response.text}\n{signer_exception}")
        else:
            response = response.json()
            if "public_key" not in response:
                raise ClientException(
                    f"The secret key of the payout address {key_name} was not imported to the signer!\n"
                    f"{signer_exception}")
    def sign(self, bytes, key_name, verbose_override=None):
        result, response = self.send_request(" sign bytes 0x03{} for {}".format(bytes, key_name), verbose_override=verbose_override)

        if not result:
            raise ClientException("Error at signing: '{}'".format(response))

        for line in response.splitlines():
            if "Signature" in line:
                return line.replace("Signature:","").strip()

        raise ClientException("Signature not found in response '{}'. Signed with key '{}'".format(response, key_name))
    def get_addr_dict_by_pkh(self, pkh):
        if not self.address_dict:
            self.generate_address_dict()

        if pkh not in self.address_dict:
            raise ClientException("Address(PKH) {} is not imported to client. Import it first.".format(pkh))

        return self.address_dict[pkh]
    def get_known_addr_by_pkh(self, pkh):

        if self.addr_dict_by_pkh is None:
            self.addr_dict_by_pkh = self.__list_known_addresses_by_pkh()

        if pkh not in self.addr_dict_by_pkh:
            raise ClientException("Address(PKH) {} is not imported to client. Import it first.".format(pkh))

        return self.addr_dict_by_pkh[pkh]
    def get_known_contract_by_alias(self, alias):

        if self.contr_dict_by_alias is None:
            self.contr_dict_by_alias = self.__list_known_contracts_by_alias()

        if alias not in self.contr_dict_by_alias:
            raise ClientException("Alias {} is not imported to client. Import it first.".format(alias))

        return self.contr_dict_by_alias[alias]
예제 #6
0
    def sign(self, bytes, key_name, timeout=None):
        json_params = json.dumps('03' + bytes)
        signer_url = self.signer_endpoint
        cmd = f'keys/{key_name}'
        url = os.path.join(signer_url, cmd)
        response = self._do_request(method="POST",
                                    url=url,
                                    json_params=json_params,
                                    timeout=timeout)

        if response is None:
            ClientException(
                "Unknown Error at signing. Please consult the verbose logs!")
        if not (response.status_code == 200):
            raise ClientException("Error at signing: '{}'".format(
                response.text))
        else:
            response = response.json()
            return response['signature']
예제 #7
0
    def get_authorized_keys(self, timeout=None):

        signer_url = self.signer_endpoint
        cmd = 'authorized_keys'
        url = os.path.join(signer_url, cmd)

        signer_exception = f'Error querying the signer at url {signer_url}. \n' \
                           f'Please make sure to start the signer using "./tezos-signer launch http signer", \n' \
                           f'import the secret key of the payout address \n' \
                           f'and specify the url using the flag -E http://<signer_addr>:<port> (default http://127.0.0.1:6732)'

        try:
            response = self._do_request(method="GET", url=url, timeout=timeout)
        except Exception as e:
            raise ClientException(f'Exception: {e}\n{signer_exception}')
        if response.status_code != HTTPStatus.OK:
            raise ClientException(f'{response.text}\n{signer_exception}')
        else:
            response = response.json()
            return response
    def __list_known_contracts_by_alias(self):
        _, response = self.send_request(" list known contracts")

        dict = self.parse_list_known_contracts_response(response)

        for alias, pkh in dict.items():
            try:
                AddressValidator("known_contract").validate(pkh)
            except Exception as e:
                raise ClientException("Invalid response from client '{}'".format(response), e)

        return dict
예제 #9
0
    def sign(self, bytes, key_name):
        response = self.send_request(" sign bytes 0x03{} for {}".format(
            bytes, key_name))

        response = clear_terminal_chars(response)

        for line in response.splitlines():
            if "Signature" in line:
                return line.strip("Signature:").strip()

        raise ClientException(
            "Signature not found in response '{}'. Signed with {}".format(
                response.replace('\n'), 'key_name'))
    def get_authorized_keys(self, timeout=None):

        signer_url = self.signer_endpoint
        cmd = "authorized_keys"
        url = os.path.join(signer_url, cmd)

        signer_exception = (
            f"Error querying the signer at url {signer_url}. \n"
            f'Please make sure to start the signer using "./tezos-signer launch http signer", \n'
            f"import the secret key of the payout address \n"
            f"and specify the url using the flag -E http://<signer_addr>:<port> (default {PRIVATE_SIGNER_URL})"
        )

        try:
            response = self._do_request(method="GET", url=url, timeout=timeout)
        except Exception as e:
            raise ClientException(f"Exception: {e}\n{signer_exception}")
        if response.status_code != HTTPStatus.OK:
            raise ClientException(f"{response.text}\n{signer_exception}")
        else:
            response = response.json()
            return response
예제 #11
0
    def __list_known_addresses_by_pkh(self):

        _, response = self.send_request("list known addresses")

        dict = self.parse_list_known_addresses_response(response)

        for pkh, dict_alias_sk in dict.items():
            try:
                AddressValidator("known_address").validate(pkh)
            except Exception as e:
                raise ClientException(
                    "Invalid response from client '{}'".format(response), e)

        return dict
예제 #12
0
    def check_pkh_known_by_signer(self, key_name, timeout=None):

        signer_url = self.signer_endpoint
        cmd = f'keys/{key_name}'
        url = os.path.join(signer_url, cmd)

        signer_exception = f'Error querying the signer at url {signer_url}. \n' \
                           f'Please make sure you have started the signer using "./tezos-signer launch http signer", \n' \
                           f'imported the secret key of the payout address {key_name}, \n' \
                           f'and specified the URL of signer using the flag -E http://<signer_addr>:<port> (default http://127.0.0.1:6732)'

        try:
            response = self._do_request(method="GET", url=url, timeout=timeout)
        except Exception as e:
            raise ClientException(f'Exception: {e}\n{signer_exception}')
        if response.status_code != HTTPStatus.OK:
            raise ClientException(f'{response.text}\n{signer_exception}')
        else:
            response = response.json()
            if 'public_key' not in response:
                raise ClientException(
                    f'The secret key of the payout address {key_name} was not imported to the signer!\n'
                    f'{signer_exception}')
    def sign(self, bytes, key_name, timeout=None):
        json_params = json.dumps("03" + bytes)
        signer_url = self.signer_endpoint
        cmd = f"keys/{key_name}"
        url = os.path.join(signer_url, cmd)
        headers = {"content-type": "application/json"}
        response = self._do_request(
            method="POST",
            url=url,
            json_params=json_params,
            headers=headers,
            timeout=timeout,
        )

        if response is None:
            raise ClientException(
                "Unknown Error at signing. Please consult the verbose logs!")
        if response.status_code != HTTPStatus.OK:
            raise ClientException(
                "Error at signing. Make sure tezos-signer is up and running 'tezos-signer launch http signer': '{}'"
                .format(response.text))
        else:
            response = response.json()
            return response["signature"]
    def get_manager_for_contract(self, pkh):

        if pkh.startswith('dn'):
            return pkh

        if pkh in self.managers:
            return self.managers[pkh]

        _, response = self.send_request(" get manager for " + pkh)

        manager = self.parse_get_manager_for_contract_response(response)

        try:
            AddressValidator("manager").validate(manager)
        except Exception as e:
            raise ClientException("Invalid response from client '{}'".format(response), e)
        self.managers[pkh] = manager

        return manager