Пример #1
0
    async def handle(self, context: RequestContext, responder: BaseResponder):
        debug_handler(self._logger.debug, context, CredentialIssue)

        try:
            exchange: CredentialExchangeRecord = (
                await
                CredentialExchangeRecord.retrieve_by_connection_and_thread(
                    context, responder.connection_id,
                    context.message._thread_id))
        except StorageNotFoundError:
            raise HandlerException(
                "Couldn't retrieve ExchangeRecord for this CredentialIssue"
                "as a result, credential issue was not handled")
        except StorageError as err:
            raise HandlerException(err.roll_up)

        if exchange.role != exchange.ROLE_HOLDER:
            raise HandlerException(reason="Invalid exchange role")
        if exchange.state != exchange.STATE_REQUEST_SENT:
            raise HandlerException(reason="Invalid exchange state")

        credential_message = context.message
        requested_credential = exchange.credential_request
        issued_credential = json.loads(credential_message.credential,
                                       object_pairs_hook=OrderedDict)

        for key in requested_credential.get("credential_values"):
            if issued_credential.get("credentialSubject").get(
                    key) != requested_credential.get("credential_values").get(
                        key):
                raise HandlerException(
                    f"Requested Credential VALUES differ from Issued Credential"
                    f"RequestedCredential: {requested_credential}"
                    f"IssuedCredential: {issued_credential}")

        holder: BaseHolder = await context.inject(BaseHolder)
        try:
            credential_id = await holder.store_credential(
                credential_definition={},
                credential_data=issued_credential,
                credential_request_metadata={},
            )
        except HolderError as err:
            raise HandlerException("Error on store_credential async!",
                                   err.roll_up)

        exchange.state = exchange.STATE_CREDENTIAL_RECEIVED
        exchange.credential_id = credential_id
        await exchange.save(context)

        self._logger.info("Stored Credential ID %s", credential_id)
        await responder.send_webhook(
            "issue-credential/credential-received",
            {
                "credential_id": credential_id,
                "connection_id": responder.connection_id
            },
        )
Пример #2
0
    async def handle(self, context: RequestContext, responder: BaseResponder):
        debug_handler(self._logger.info, context, PresentProof)
        exchange: THCFPresentationExchange = await retrieve_exchange_by_thread(
            context,
            responder.connection_id,
            context.message._thread_id,
            HandlerException,
        )

        if exchange.role != exchange.ROLE_VERIFIER:
            raise HandlerException(reason="Invalid exchange role")
        if exchange.state != exchange.STATE_REQUEST_SENT:
            raise HandlerException(reason="Invalid exchange state")

        if context.message.decision:
            verifier: BaseVerifier = await context.inject(BaseVerifier)

            presentation = json.loads(context.message.credential_presentation,
                                      object_pairs_hook=OrderedDict)

            is_verified = await verifier.verify_presentation(
                presentation_request=exchange.presentation_request,
                presentation=presentation,
                schemas={},
                credential_definitions={},
                rev_reg_defs={},
                rev_reg_entries={},
            )

            if not is_verified:
                raise HandlerException(
                    f"Verifier couldn't verify the presentation {is_verified}")

            await exchange.presentation_pds_set(context, presentation)
            exchange.verified = True
            exchange.prover_public_did = context.message.prover_public_did
            exchange.state = exchange.STATE_PRESENTATION_RECEIVED
        else:
            exchange.state = exchange.STATE_PRESENTATION_DENIED

        await exchange.save(context, reason="PresentationExchange updated")
        await responder.send_webhook(
            "present_proof",
            {
                "type": "present_proof",
                "exchange_record_id": exchange._id,
                "connection_id": responder.connection_id,
            },
        )
    async def handle(self, context: RequestContext, responder: BaseResponder):
        debug_handler(self._logger.info, context, AcknowledgeProof)

        exchange: THCFPresentationExchange = await retrieve_exchange_by_thread(
            context,
            responder.connection_id,
            context.message._thread_id,
            HandlerException,
        )

        if exchange.role != exchange.ROLE_PROVER:
            raise HandlerException(reason="Invalid exchange role")
        if exchange.state != exchange.STATE_PRESENTATION_SENT:
            raise HandlerException(reason="Invalid exchange state")

        holder: BaseHolder = await context.inject(BaseHolder)
        credential_data = json.loads(context.message.credential,
                                     object_pairs_hook=OrderedDict)

        try:
            ack_credential_dri = await holder.store_credential(
                credential_definition={},
                credential_data=credential_data,
                credential_request_metadata={},
            )
        except HolderError as err:
            raise HandlerException("Error on store_credential async!",
                                   err.roll_up)

        exchange.acknowledgment_credential_dri = ack_credential_dri
        await pds_link_dri(context, exchange.presentation_dri,
                           exchange.acknowledgment_credential_dri)
        exchange.state = exchange.STATE_ACKNOWLEDGED
        await exchange.save(context)

        await responder.send_webhook(
            "present_proof",
            {
                "type": "acknowledge_proof",
                "exchange_record_id": exchange._id,
                "connection_id": responder.connection_id,
                "acknowledgment_credential_dri": ack_credential_dri,
            },
        )
Пример #4
0
    async def handle(self, context: RequestContext, responder: BaseResponder):
        debug_handler(self._logger.debug, context, CredentialRequest)
        message: CredentialRequest = context.message
        credential = context.message.credential

        exchange_record: CredentialExchangeRecord = CredentialExchangeRecord(
            connection_id=responder.connection_id,
            initiator=CredentialExchangeRecord.INITIATOR_EXTERNAL,
            role=CredentialExchangeRecord.ROLE_ISSUER,
            state=CredentialExchangeRecord.STATE_REQUEST_RECEIVED,
            thread_id=message._thread_id,
            credential_request=credential,
            their_public_did=context.message.did,
        )

        credential_exchange_id = await exchange_record.save(context)
        await responder.send_webhook(
            CredentialExchangeRecord.webhook_topic,
            {
                "credential_exchange_id": credential_exchange_id,
                "connection_id": responder.connection_id,
            },
        )
Пример #5
0
    async def handle(self, context: RequestContext, responder: BaseResponder):
        debug_handler(self._logger.info, context, RequestProof)
        message: RequestProof = context.message
        exchange_record = THCFPresentationExchange(
            connection_id=responder.connection_id,
            thread_id=message._thread_id,
            initiator=THCFPresentationExchange.INITIATOR_EXTERNAL,
            role=THCFPresentationExchange.ROLE_PROVER,
            state=THCFPresentationExchange.STATE_REQUEST_RECEIVED,
            presentation_request=message.presentation_request,
            requester_usage_policy=message.usage_policy,
        )
        record_id = await exchange_record.save(context)
        self._logger.info("credential_exchange_record_id = %s", record_id)

        await responder.send_webhook(
            "present_proof",
            {
                "type": "request_proof",
                "exchange_record_id": record_id,
                "connection_id": responder.connection_id,
            },
        )