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
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> } ``` """ ok, result = await _check_signature(request) if not ok: return result LOGGER.warn(">>> Generate credential request") perf = _time_start("generate_credential_request") result = await vonx_views.generate_credential_request( request, indy_holder_id()) LOGGER.warn("<<< Generate credential request: %s", _time_end(perf)) return result
async def run(): cred_req = await indy_client().create_credential_request( indy_holder_id(), self.credential_offer, self.credential_def_id, ) return cred_req.data, cred_req.metadata
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
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
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
async def store(self) -> str: # Store credential in wallet stored = await indy_client().store_credential( indy_holder_id(), VonxCredential( self.credential.raw, self.credential_request_metadata, None, # revocation ID ), ) return stored.cred_id
async def store_credential(request): """ Stores a verifiable credential in 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> } ``` returns: created verified credential model """ ok, result = await _check_signature(request) if not ok: return result LOGGER.warn(">>> Store credential") perf_store = _time_start("store_credential") result = await vonx_views.store_credential(request, indy_holder_id()) LOGGER.warn("<<< Store credential (wallet): %s", _time_end(perf_store)) perf_proc = _time_start("process_credential") if result.get("stored"): def process(stored): credential = Credential(stored.cred.cred_data) credential_manager = CredentialManager( credential, stored.cred.cred_req_metadata) credential_manager.process(stored.cred_id) # run in a separate thread to avoid blocking the async loop try: await run_django(process, result["stored"]) except CredentialException as e: LOGGER.exception("Exception while processing credential") result = web.json_response({"success": False, "result": str(e)}) LOGGER.warn("<<< Store credential: %s", _time_end(perf_proc)) return result
async def construct_proof(request): """ Constructs a proof given a proof request ```json { "proof_request": <HL Indy proof request> } ``` returns: HL Indy proof data """ ok, result = await _check_signature(request) if not ok: return result LOGGER.warn(">>> Construct proof") perf = _time_start("construct_proof") result = await vonx_views.construct_proof(request, indy_holder_id()) LOGGER.warn("<<< Construct proof: %s", _time_end(perf)) return result
async def verify(): return await indy_client().verify_proof( indy_holder_id(), VonxProofRequest(proof_request.dict), VonxConstructedProof(proof))
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, )