/// <summary> /// Reference https://github.com/hyperledger/aries-framework-dotnet/blob/master/src/Hyperledger.Aries.TestHarness/AgentScenarios.cs#L214 /// </summary> private async Task CreatePresentation() { base.IsBusy = true; var dialog = UserDialogs.Instance.Loading("Presenting Proof..."); try { var requestedCredentials = new RequestedCredentials(); var requestedAttributes = RequestedAttributes.Where(x => x.SelectedCredential != null && !x.IsPredicate) .Select(y => new KeyValuePair <string, RequestedAttribute>(y.AttributeReferent, new RequestedAttribute { CredentialId = y.SelectedCredential.Credential.CredentialInfo.Referent, Revealed = true }) ).ToDictionary(z => z.Key, z => z.Value); //TODO: Implement Predicate related functionlity if (requestedAttributes != null && requestedAttributes.Count > 0) { requestedCredentials.RequestedAttributes = requestedAttributes; var context = await agentContextProvider.GetContextAsync(); if (requestPresentationMessage != null) { var result = await proofService.CreatePresentationAsync(context, requestPresentationMessage, requestedCredentials); } else { var(proofMsg, holderRecord) = await proofService.CreatePresentationAsync(context, proofRecord.Id, requestedCredentials); await messageService.SendAsync(context, proofMsg, connection); } } eventAggregator.Publish(new ApplicationEvent() { Type = ApplicationEventType.RefreshProofRequests }); await NavigationService.NavigateBackAsync(); } catch (Exception exception) { await Application.Current.MainPage.DisplayAlert("Error", exception.Message, "Ok"); } finally { base.IsBusy = false; dialog?.Hide(); dialog?.Dispose(); } }
private async Task AcceptProofRequest() { if (_proofRecord.State != ProofState.Requested) { await DialogService.AlertAsync(string.Format(AppResources.ProofStateShouldBeMessage, ProofStateTranslator.Translate(ProofState.Requested))); return; } RequestedCredentials requestedCredentials = new RequestedCredentials() { RequestedAttributes = new Dictionary <string, RequestedAttribute>(), RequestedPredicates = new Dictionary <string, RequestedAttribute>() }; foreach (ProofAttributeViewModel proofAttribute in Attributes) { if (proofAttribute.IsPredicate) { requestedCredentials.RequestedPredicates.Add(proofAttribute.Id, new RequestedAttribute { CredentialId = proofAttribute.CredentialId, Revealed = proofAttribute.IsRevealed }); } else { requestedCredentials.RequestedAttributes.Add(proofAttribute.Id, new RequestedAttribute { CredentialId = proofAttribute.CredentialId, Revealed = proofAttribute.IsRevealed }); } } // TODO: Mettre le Timestamp à null car lorsqu'il est présent, la création de la preuve ne marche pas. Pourquoi? //foreach (var keyValue in requestedCredentials.RequestedAttributes.Values) //{ // keyValue.Timestamp = null; //} var context = await _agentContextProvider.GetContextAsync(); ProofRecord proofRecord = await _recordService.GetAsync <ProofRecord>(context.Wallet, _proofRecord.Id); var(msg, rec) = await _proofService.CreatePresentationAsync(context, proofRecord.Id, requestedCredentials); if (string.IsNullOrEmpty(proofRecord.ConnectionId)) { await _messageService.SendAsync(context.Wallet, msg, proofRecord.GetTag("RecipientKey"), proofRecord.GetTag("ServiceEndpoint")); } else { ConnectionRecord connectionRecord = await _recordService.GetAsync <ConnectionRecord>(context.Wallet, proofRecord.ConnectionId); await _messageService.SendAsync(context.Wallet, msg, connectionRecord); } _eventAggregator.Publish(new ApplicationEvent { Type = ApplicationEventType.ProofRequestUpdated }); await NavigationService.PopModalAsync(); }
public static async Task <(ProofRecord holderProofRecord, ProofRecord RequestorProofRecord)> ProofProtocolAsync( IProofService proofService, IProducerConsumerCollection <AgentMessage> messages, ConnectionRecord holderConnection, ConnectionRecord requestorConnection, IAgentContext holderContext, IAgentContext requestorContext, ProofRequest proofRequestObject) { //Requestor sends a proof request var(message, requestorProofRecord) = await proofService.CreateRequestAsync(requestorContext, proofRequestObject, requestorConnection.Id); messages.TryAdd(message); // Holder accepts the proof requests and builds a proof var proofRequest = FindContentMessage <RequestPresentationMessage>(messages); Assert.NotNull(proofRequest); //Holder stores the proof request var holderProofRequestRecord = await proofService.ProcessRequestAsync(holderContext, proofRequest, holderConnection); var holderProofRecord = await proofService.GetAsync(holderContext, holderProofRequestRecord.Id); var holderProofRequest = JsonConvert.DeserializeObject <ProofRequest>(holderProofRecord.RequestJson); // Auto satify the proof with which ever credentials in the wallet are capable var requestedCredentials = await ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials(holderContext, proofService, holderProofRequest); //Holder accepts the proof request and sends a proof (var proofMessage, _) = await proofService.CreatePresentationAsync( holderContext, holderProofRequestRecord.Id, requestedCredentials); messages.TryAdd(proofMessage); //Requestor retrives proof message from their cloud agent var proof = FindContentMessage <PresentationMessage>(messages); Assert.NotNull(proof); //Requestor stores proof requestorProofRecord = await proofService.ProcessPresentationAsync(requestorContext, proof); //Requestor verifies proof var requestorVerifyResult = await proofService.VerifyProofAsync(requestorContext, requestorProofRecord.Id); //Verify the proof is valid Assert.True(requestorVerifyResult); var requestorProofRecordResult = await proofService.GetAsync(requestorContext, requestorProofRecord.Id); var holderProofRecordResult = await proofService.GetAsync(holderContext, holderProofRecord.Id); return(holderProofRecordResult, requestorProofRecordResult); }
private async Task AcceptProofRequest() { var loadingDialog = DialogService.Loading("Proccessing"); try { this.IsBusy = true; var context = await _agentProvider.GetContextAsync(); var(message, proofRecord) = await _proofService.CreatePresentationAsync(context, ProofRequestRecord.Id, RequestedCredentials); var connectionRecord = await _connectionService.GetAsync(context, proofRecord.ConnectionId); await _messageService.SendAsync(context.Wallet, message, connectionRecord); _eventAggregator.Publish(new ApplicationEvent() { Type = ApplicationEventType.NotificationUpdated }); loadingDialog.Hide(); this.IsBusy = false; await NavigationService.NavigateBackAsync(); var toastConfig = new ToastConfig("Accepted Proof!"); toastConfig.BackgroundColor = Color.Green; toastConfig.Position = ToastPosition.Top; toastConfig.SetDuration(3000); DialogService.Toast(toastConfig); } catch (IndyException e) { this.IsBusy = false; loadingDialog.Hide(); if (e.SdkErrorCode == 212) { DialogService.Alert("You don't have any suitable credential to present", "Error", "OK"); } else { Console.WriteLine("Indy Error: " + e.Message); DialogService.Alert("Some error with libindy. We're working on it", "Error", "OK"); } } catch (Exception e) { this.IsBusy = false; loadingDialog.Hide(); Console.WriteLine("Error: " + e.Message); DialogService.Alert("Error while accept Proof Request"); } }
public async Task <IActionResult> SendProof(string proofRecordId) { var agentContext = await _agentProvider.GetContextAsync(); var proofRecord = await _proofService.GetAsync(agentContext, proofRecordId); var connectionRecord = await _connectionService.GetAsync(agentContext, proofRecord.ConnectionId); var request = JsonConvert.DeserializeObject <ProofRequest>(proofRecord.RequestJson); var requestedCredentials = new RequestedCredentials(); foreach (var requestedAttribute in request.RequestedAttributes) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(agentContext, request, requestedAttribute.Key); requestedCredentials.RequestedAttributes.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } foreach (var requestedAttribute in request.RequestedPredicates) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(agentContext, request, requestedAttribute.Key); requestedCredentials.RequestedPredicates.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = false }); } var(proofMsg, record) = await _proofService.CreatePresentationAsync(agentContext, proofRecordId, requestedCredentials); await _messageService.SendAsync(agentContext.Wallet, proofMsg, connectionRecord); return(RedirectToAction("Index")); }
public async Task <IActionResult> SendProofPresentationAsync(OperationBody body) { var context = await _agentContextProvider.GetContextAsync(); var threadId = body.Id; var THPresentationExchange = _proofCache.Get <TestHarnessPresentationExchange>(threadId); var requestedCredentialsJson = body.Data; var requestedCredentials = requestedCredentialsJson.ToObject <RequestedCredentials>(); _logger.LogInformation("SendProofPresentation {requestedCredentials}", requestedCredentials.ToJson()); var(presentationMessage, proofRecord) = await _proofService.CreatePresentationAsync(context, THPresentationExchange.RecordId, requestedCredentials); var connection = await _connectionService.GetAsync(context, proofRecord.ConnectionId); THPresentationExchange.State = TestHarnessPresentationExchangeState.PresentationSent; _logger.LogDebug("Send Presentation {presentationMessage}", presentationMessage.ToJson()); await _messageService.SendAsync(context, presentationMessage, connection); return(Ok(THPresentationExchange)); }
public async Task ProcessProofInvalidState() { //Setup a connection and issue the credentials to the holder var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); await Scenarios.IssueCredentialAsync( _schemaService, _credentialService, _messages, issuerConnection, holderConnection, _issuerWallet, _holderWallet, await _holderWallet.Pool, TestConstants.DefaultMasterSecret, true, new List <CredentialPreviewAttribute> { new CredentialPreviewAttribute("first_name", "Test"), new CredentialPreviewAttribute("last_name", "Holder") }); _messages.Clear(); //Requestor initialize a connection with the holder var(_, requestorConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _holderWallet, _requestorWallet); // Verifier sends a proof request to prover { var proofRequestObject = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = await AnonCreds.GenerateNonceAsync(), RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "first-name-requirement", new ProofAttributeInfo { Name = "first_name" } } } }; //Requestor sends a proof request var(message, _) = await _proofService.CreateRequestAsync(_requestorWallet, proofRequestObject, requestorConnection.Id); _messages.Add(message); } // Holder accepts the proof requests and builds a proof { //Holder retrives proof request message from their cloud agent var proofRequest = FindContentMessage <RequestPresentationMessage>(); Assert.NotNull(proofRequest); //Holder stores the proof request var holderProofRequestId = await _proofService.ProcessRequestAsync(_holderWallet, proofRequest, holderConnection); var holderProofRecord = await _proofService.GetAsync(_holderWallet, holderProofRequestId.Id); var holderProofObject = JsonConvert.DeserializeObject <ProofRequest>(holderProofRecord.RequestJson); var requestedCredentials = new RequestedCredentials(); foreach (var requestedAttribute in holderProofObject.RequestedAttributes) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedAttributes.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } foreach (var requestedAttribute in holderProofObject.RequestedPredicates) { var credentials = await _proofService.ListCredentialsForProofRequestAsync(_holderWallet, holderProofObject, requestedAttribute.Key); requestedCredentials.RequestedPredicates.Add(requestedAttribute.Key, new RequestedAttribute { CredentialId = credentials.First().CredentialInfo.Referent, Revealed = true }); } //Holder accepts the proof request and sends a proof (var proofMessage, var _) = await _proofService.CreatePresentationAsync(_holderWallet, holderProofRequestId.Id, requestedCredentials); _messages.Add(proofMessage); } //Requestor retrives proof message from their cloud agent var proof = FindContentMessage <PresentationMessage>(); Assert.NotNull(proof); //Requestor stores proof await _proofService.ProcessPresentationAsync(_requestorWallet, proof); var ex = await Assert.ThrowsAsync <AriesFrameworkException>(async() => await _proofService.ProcessPresentationAsync(_requestorWallet, proof)); Assert.True(ex.ErrorCode == ErrorCode.RecordInInvalidState); }