def test_create_presentation_from_json(self): presentation_json = { "request_presentations~attach": [{ "@id": "libindy-request-presentation-0", "data": { "base64": "eyJuYW1lIjogIkJhc2ljIFByb29mIiwgInZlcnNpb24iOiAiMS4wIiwgInJlcXVlc3RlZF9hdHRyaWJ1dGVzIjogeyI3OTQ4YTU1Ni0zMTM3LTRlMzgtOWVjMi0xMTk1NGI5NzY1MmEiOiB7Im5hbWUiOiAiZW1haWwiLCAicmVzdHJpY3Rpb25zIjogW119fSwgInJlcXVlc3RlZF9wcmVkaWNhdGVzIjoge30sICJub25jZSI6ICI1MjMzMjczMDc0MjI1NTYxMTQ2MzA0NDgifQ==" }, "mime-type": "application/json", }], "~service": { "serviceEndpoint": "endpoint", "recipientKeys": ["verkey"], "routingKeys": None, }, "comment": None, "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", "@id": "id", } presentation = PresentationFactory.from_json(presentation_json) assert presentation.to_json() == presentation_json
def authorization(pres_req_conf_id: str, request_parameters: dict): aca_client = ACAClient(settings.ACA_PY_URL, settings.ACA_PY_TRANSPORT_URL) presentation_configuration = PresentationConfigurations.objects.get( id=pres_req_conf_id) response = aca_client.create_proof_request( presentation_configuration.to_json()) public_did = aca_client.get_public_did() endpoint = aca_client.get_endpoint_url() presentation_request = PresentationFactory.from_params( presentation_request=response.get("presentation_request"), p_id=response.get("thread_id"), verkey=[public_did.get("verkey")], endpoint=endpoint, ).to_json() presentation_request_id = response["presentation_exchange_id"] session = AuthSession.objects.create( presentation_record_id=pres_req_conf_id, presentation_request_id=presentation_request_id, presentation_request=presentation_request, request_parameters=request_parameters, expired_timestamp=timezone.now() + timedelta(minutes=60), ) url, b64_presentation = create_short_url(presentation_request) mapped_url = MappedUrl.objects.create(url=url, session=session) short_url = mapped_url.get_short_url() return short_url, str( session.pk), presentation_request_id, b64_presentation
def extract_claims(session: AuthSession): IDENTITY_PARAM = "sub" presentation_configuration = PresentationConfigurations.objects.filter( id=session.presentation_record_id).last() if not presentation_configuration: raise Exception( "Presenstation configuraton not found with id: {session.presentation_record_id}" ) nonce = session.request_parameters.get("nonce") claims = { "pres_req_conf_id": session.presentation_request_id, "acr": "vc_authn" } if nonce: claims.update({"nonce": nonce}) presentation_factory = PresentationFactory.from_json( session.presentation_request) requested_parameters = presentation_factory.presentation.presentation if requested_parameters: for requested_attr in requested_parameters: for k, v in requested_attr.data.get("requested_attributes", {}).items(): attr = session.presentation.get("revealed_attrs", {}).get(k) if attr: attr_name = v.get("name") claims.update({attr_name: attr.get("raw", "")}) if (presentation_configuration and presentation_configuration.subject_identifier == attr_name): claims.update({IDENTITY_PARAM: attr.get("raw", "")}) if IDENTITY_PARAM not in claims.keys(): claims.update({IDENTITY_PARAM: str(uuid.uuid4())}) claims.update({"iat": timezone.now()}) return claims
def test_create_presentation_from_params(self): presentation = PresentationFactory.from_params( presentation_request={ "name": "Basic Proof", "version": "1.0", "requested_attributes": { "7948a556-3137-4e38-9ec2-11954b97652a": { "name": "emails", "restrictions": [], } }, "requested_predicates": {}, "nonce": "523327307422556114630448", }, p_id="id", verkey=["verkey"], endpoint="endpoint", ) assert presentation.to_json() == { "request_presentations~attach": [{ "@id": "libindy-request-presentation-0", "data": { "base64": "eyJuYW1lIjogIkJhc2ljIFByb29mIiwgInZlcnNpb24iOiAiMS4wIiwgInJlcXVlc3RlZF9hdHRyaWJ1dGVzIjogeyI3OTQ4YTU1Ni0zMTM3LTRlMzgtOWVjMi0xMTk1NGI5NzY1MmEiOiB7Im5hbWUiOiAiZW1haWxzIiwgInJlc3RyaWN0aW9ucyI6IFtdfX0sICJyZXF1ZXN0ZWRfcHJlZGljYXRlcyI6IHt9LCAibm9uY2UiOiAiNTIzMzI3MzA3NDIyNTU2MTE0NjMwNDQ4In0=" }, "mime-type": "application/json", }], "~service": { "serviceEndpoint": "endpoint", "recipientKeys": ["verkey"], "routingKeys": None, }, "comment": None, "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", "@id": "id", }
def test_create_presentation_from_params(self): presentation = PresentationFactory.from_params( presentation_request={ "name": "Basic Proof", "version": "1.0", "requested_attributes": { "7948a556-3137-4e38-9ec2-11954b97652a": { "name": "email", "restrictions": [], } }, "requested_predicates": {}, "nonce": "523327307422556114630448", }, p_id="id", verkey=["verkey"], endpoint="endpoint", ) assert presentation.to_json() == { "request_presentations~attach": [{ "@id": "libindy-request-presentation-0", "data": { "base64": "eyJuYW1lIjogIkJhc2ljIFByb29mIiwgInZlcnNpb24iOiAiMS4wIiwgInJlcXVlc3RlZF9hdHRyaWJ1dGVzIjogeyI3OTQ4YTU1Ni0zMTM3LTRlMzgtOWVjMi0xMTk1NGI5NzY1MmEiOiB7Im5hbWUiOiAiZW1haWwiLCAicmVzdHJpY3Rpb25zIjogW119fSwgInJlcXVlc3RlZF9wcmVkaWNhdGVzIjoge30sICJub25jZSI6ICI1MjMzMjczMDc0MjI1NTYxMTQ2MzA0NDgifQ==" }, "mime-type": "application/json", }], "~service": { "serviceEndpoint": "endpoint", "recipientKeys": ["verkey"], "routingKeys": None, }, "comment": None, "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", "@id": "id", }
async def authorization_async(pres_req_conf_id: str, request_parameters: dict): # Based on the aca-py agent you wish to control # print('AGENT CONNECT') agent_controller = AriesAgentController(admin_url=settings.ACA_PY_URL) # print('ACAPY AGENT CONNECTED') # print('WEBHOOOKS STARTING') # await asyncio.gather(agent_controller.init_webhook_server(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, webhook_base=WEBHOOK_BASE)) # print('WEBHOOOKS STARTED') presentation_configuration = await getPresentationConfig(pres_req_conf_id) print('PRESENTATION CONFIG: ', presentation_configuration) # response = await agent_controller.proofs.create_request(presentation_configuration.to_json()) response = await asyncio.gather( agent_controller.proofs.create_request( presentation_configuration.to_json())) response = response[0] print('PROOF CREATE: ', response) # TODO - the current DID of the Agent is already ledgered on Stagingnet # This creates a scenario where the endpoint being fetched is wrong # Need to update the code so that new DIDs can be ledgered to stagingnet together with endpoints public_did = await asyncio.gather(agent_controller.wallet.get_public_did()) public_did = public_did[0]['result'] print('PUBLIC DID: ', public_did) endpoint = await asyncio.gather( agent_controller.ledger.get_did_endpoint(public_did['did'])) endpoint = endpoint[0]['endpoint'] print('ENDPOINT: ', endpoint) # TODO - this will wail due to no TAA accepted on ledger TAA_response = await agent_controller.ledger.get_taa() TAA = TAA_response['result']['taa_record'] TAA['mechanism'] = "service_agreement" # print(TAA) TAA_accept = await agent_controller.ledger.accept_taa(TAA) ## Will return {} if successful print(TAA_accept) await asyncio.gather( agent_controller.wallet.set_did_endpoint(public_did['did'], settings.ACA_PY_TRANSPORT_URL, 'Endpoint')) endpoint = await asyncio.gather( agent_controller.ledger.get_did_endpoint(public_did['did'])) endpoint = endpoint[0]['endpoint'] print('ENDPOINT ', endpoint) presentation_request = PresentationFactory.from_params( presentation_request=response.get("presentation_request"), p_id=response.get("thread_id"), verkey=[public_did.get("verkey")], endpoint=endpoint, ).to_json() print('PROOF REQUEST: ', presentation_request) presentation_request_id = response["presentation_exchange_id"] url, b64_presentation = create_short_url(presentation_request) print(url) session, mapped_url, short_url = await createSession( pres_req_conf_id, presentation_request_id, presentation_request, request_parameters, url) print('SESSION ', session) print('sessionpk: ', str(session.pk)) print('mapped_url: ', mapped_url) print('short_url: ', short_url) print('presx_id: ', presentation_request_id) print('b64 presx: ', b64_presentation) await agent_controller.terminate() return short_url, str( session.pk), presentation_request_id, b64_presentation