Exemplo n.º 1
0
async def construct_proof(request):
    """
    Constructs a proof given a proof request

    ```json
    {
        "proof_request": <HL Indy proof request>
    }
    ```

    returns: HL Indy proof data
    """

    LOGGER.warn(">>> Construct proof")
    perf = _time_start("construct_proof")

    try:
        await _check_signature(request)
        response = await vonx_views.construct_proof(request, indy_holder_id())
    except IndyRequestError as e:
        response = e.response

    LOGGER.warn("<<< Construct proof: %s", _time_end(perf))

    return response
Exemplo n.º 2
0
    async def construct_proof_async(self):
        proof = await indy_client().construct_proof(
            indy_holder_id(),
            self.proof_request,
            None,  # wql filters
            self.credential_ids,
        )

        return proof.proof
Exemplo n.º 3
0
async def store_credential(request):
    """
    Stores one or more verifiable credentials in the wallet.

    The data in the credential is parsed and stored in the database
    for search/display purposes based on the issuer's processor config.
    The data is then made available through a REST API as well as a
    search API.

    Example request payload:

    ```json
    {
        "credential_data": <credential data>,
        "credential_request_metadata": <credential request metadata>
    }
    ```

    Input may also be in the form of an array of credential data:

    ```json
    [
        {
            "credential_data": <credential data>,
            "credential_request_metadata": <credential request metadata>
        },
        {
            "credential_data": <credential data>,
            "credential_request_metadata": <credential request metadata>
        }
    ]
    ```

    Returns: the wallet ID of the stored credential or credentials
    """

    LOGGER.warn(">>> Store credential")
    perf = _time_start("store_credential")

    try:
        await _check_signature(request)
        issuer_did = get_request_did(request)
        client = _indy_client()
        params = await get_request_json(request)
        processor = request.app["credqueue"]  # CredentialProcessorQueue
        stored, ret = await perform_store_credential(client, indy_holder_id(),
                                                     params, processor,
                                                     issuer_did)
        response = web.json_response(ret)
        response["stored"] = stored
    except IndyRequestError as e:
        response = e.response

    LOGGER.warn("<<< Store credential: %s", _time_end(perf))

    return response
Exemplo n.º 4
0
def get_key_finder(use_cache: bool = True) -> KeyFinderBase:
    global INDY_KEYFINDER, DJANGO_KEYFINDER, KEY_CACHE
    if use_cache and KEY_CACHE:
        return KEY_CACHE
    if not INDY_KEYFINDER:
        # may raise RuntimeError on indy_client() if Indy service has not been started
        INDY_KEYFINDER = IndyKeyFinder(_indy_client(), indy_holder_id())
        DJANGO_KEYFINDER = DjangoKeyFinder(INDY_KEYFINDER)
        KEY_CACHE = KeyCache(DJANGO_KEYFINDER)
    return INDY_KEYFINDER
Exemplo n.º 5
0
async def generate_credential_request(request):
    """
    Processes a credential definition and responds with a credential request
    which can then be used to submit a credential.

    Example request payload:

    ```json
    {
        'credential_offer': <credential offer json>,
        'credential_definition': <credential definition json>
    }
    ```

    returns:

    ```
    {
        "credential_request": <credential request json>,
        "credential_request_metadata": <credential request metadata json>
    }
    ```
    """

    LOGGER.warn(">>> Generate credential request")
    perf = _time_start("generate_credential_request")

    try:
        await _check_signature(request)
        response = await vonx_views.generate_credential_request(
            request, indy_holder_id())
    except IndyRequestError as e:
        response = e.response

    LOGGER.warn("<<< Generate credential request: %s", _time_end(perf))

    return response
Exemplo n.º 6
0
 async def verify():
     return await indy_client().verify_proof(
         indy_holder_id(), VonxProofRequest(proof_request.dict),
         VonxConstructedProof(proof))
Exemplo n.º 7
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")
    headers = {'Access-Control-Allow-Origin': '*'}

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

    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,
            headers=headers,
        )

    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})
    try:
        proof = await proof_manager.construct_proof_async()
        verified = await _indy_client().verify_proof(
            indy_holder_id(), VonxProofRequest(proof_request.dict),
            VonxConstructedProof(proof))
    except IndyError as e:
        LOGGER.exception("Credential verification error:")
        return web.json_response(
            {
                "success": False,
                "result": "Credential verification error: {}".format(str(e))
            },
            headers=headers,
        )
    except:
        LOGGER.exception("Credential verification error:")
        return web.json_response(
            {
                "success": False,
                "result": "Not available"
            },
            status=403,
            headers=headers,
        )

    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,
            },
        },
        headers=headers,
    )