Ejemplo n.º 1
0
async def verify_credential(request):
    """
    Constructs a proof request for a credential stored in the
    application database, constructs a proof for that proof
    request, and then verifies it.

    returns:

    ```json
    {
        "verified": <verification successful boolean>,
        "proof": <proof json>,
        "proof_request": <proof_request json>,
    }
    ```
    """
    LOGGER.warn(">>> Verify credential")
    perf = _time_start("verify_credential")
    credential_id = request.match_info.get("id")

    if not credential_id:
        return web.json_response(
            {
                "success": False,
                "result": "Credential ID not provided"
            },
            status=400)

    def fetch_cred(credential_id):
        try:
            return CredentialModel.objects\
                .prefetch_related('claims')\
                .select_related('credential_type')\
                .select_related('credential_type__schema')\
                .get(id=credential_id)
        except CredentialModel.DoesNotExist:
            return None

    credential = await run_django(fetch_cred, credential_id)
    if not credential:
        LOGGER.warn("Credential not found: %s", credential_id)
        return web.json_response(
            {
                "success": False,
                "result": "Credential not found"
            }, status=404)

    proof_request = ProofRequest(name="the-org-book", version="1.0.0")
    proof_request.build_from_credential(credential)

    proof_manager = ProofManager(proof_request.dict, {credential.wallet_id})
    proof = await proof_manager.construct_proof_async()

    verified = await indy_client().verify_proof(
        indy_verifier_id(), VonxProofRequest(proof_request.dict),
        VonxConstructedProof(proof))
    verified = verified.verified == "true"
    LOGGER.warn("<<< Verify credential: %s", _time_end(perf))

    return web.json_response({
        "success": verified,
        "result": {
            "verified": verified,
            "proof": proof,
            "proof_request": proof_request.dict,
        },
    })
Ejemplo n.º 2
0
 async def verify():
     return await indy_client().verify_proof(
         indy_holder_id(), VonxProofRequest(proof_request.dict),
         VonxConstructedProof(proof))