def has_matching_signatures(self) -> bool: """ Check that the signatures match the terms of trade. :return: True if the transaction has been signed by both parties """ # singable_message = LedgerApis.sign_message(self.sender_hash) result = ( self.sender_address in LedgerApis.recover_message( # pylint: disable=no-member identifier=self.ledger_id, message=self.sender_hash.encode("utf-8"), signature=self.sender_signature, )) # counterparty_signable_message = LedgerApis.sign_message(self.counterparty_hash) result = ( result and self.counterparty_address in LedgerApis.recover_message( # pylint: disable=no-member identifier=self.ledger_id, message=self.counterparty_hash.encode("utf-8"), signature=self.counterparty_signature, )) return result
def _valid_signature(self, expected_signer: str, signature: str, message_str: str, ledger_id: str) -> bool: """ Check if the signature and message match the expected signer. :param expected_signer: the signer :param signature: the signature :param message_str: the message :param ledger_id: the ledger id :return: bool indiciating validity """ try: result = expected_signer in LedgerApis.recover_message( ledger_id, message_str.encode("utf-8"), signature) except Exception as e: # pylint: disable=broad-except self.context.logger.warning(f"Signing exception: {e}") result = False return result