<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _verify_service_agreement_signature(self, did, agreement_id, service_definition_id, consumer_address, signature, ddo=None):
 """ Verify service agreement signature. Verify that the given signature is truly signed by the `consumer_address` and represents this did's service agreement.. :param did: DID, str :param agreement_id: id of the agreement, hex str :param service_definition_id: identifier of the service inside the asset DDO, str :param consumer_address: ethereum account address of consumer, hex str :param signature: Signature, str :param ddo: DDO instance :return: True if signature is legitimate, False otherwise :raises: ValueError if service is not found in the ddo :raises: AssertionError if conditions keys do not match the on-chain conditions keys """

        if not ddo:
            ddo = self._asset_resolver.resolve(did)

        service_agreement = ServiceAgreement.from_ddo(service_definition_id, ddo)
        agreement_hash = service_agreement.get_service_agreement_hash(
            agreement_id, ddo.asset_id, consumer_address,
            Web3Provider.get_web3().toChecksumAddress(ddo.proof['creator']), self._keeper)

        prefixed_hash = prepare_prefixed_hash(agreement_hash)
        recovered_address = Web3Provider.get_web3().eth.account.recoverHash(
            prefixed_hash, signature=signature
        )
        is_valid = (recovered_address == consumer_address)
        if not is_valid:
            logger.warning(f'Agreement signature failed: agreement hash is {agreement_hash.hex()}')

        return is_valid