@defer.inlineCallbacks
    def _check_signature(self, event, auth_events):
        signed = event.content["third_party_invite"]["signed"]
        token = signed["token"]

        invite_event = auth_events.get(
            (EventTypes.ThirdPartyInvite, token,)
        )

        if not invite_event:
            raise AuthError(403, "Could not find invite")

        last_exception = None
        for public_key_object in self.hs.get_auth().get_public_keys(invite_event):
            try:
                for server, signature_block in signed["signatures"].items():
                    for key_name, encoded_signature in signature_block.items():
                        if not key_name.startswith("ed25519:"):
                            continue

                        public_key = public_key_object["public_key"]
                        verify_key = decode_verify_key_bytes(
                            key_name,
                            decode_base64(public_key)
                        )
                        verify_signed_json(signed, server, verify_key)
                        if "key_validity_url" in public_key_object:
                            yield self._check_key_revocation(
                                public_key,
                                public_key_object["key_validity_url"]
                            )
                        return
            except Exception as e:
                last_exception = e
        raise last_exception
Checks that the signature in the event is consistent with its invite.
dataset/ETHPy150Open matrix-org/synapse/synapse/handlers/federation.py/FederationHandler._check_signature