public async Task SendProofRequestThrowsConnectionNotFound() { var ex = await Assert.ThrowsAsync <AriesFrameworkException>(async() => await _proofService.CreateRequestAsync(_issuerWallet, new ProofRequest { Name = "Test", Nonce = await AnonCreds.GenerateNonceAsync() }, "bad-proof-id")); Assert.True(ex.ErrorCode == ErrorCode.RecordNotFound); }
public async Task <CreateProofRequestResponse> Handle ( CreateProofRequestRequest aCreateProofRequestRequest, CancellationToken aCancellationToken ) { IAgentContext agentContext = await AgentProvider.GetContextAsync(); ConnectionRecord connectionRecord = await ConnectionService.GetAsync(agentContext, aCreateProofRequestRequest.ConnectionId); aCreateProofRequestRequest.ProofRequest.Nonce = await AnonCreds.GenerateNonceAsync(); (RequestPresentationMessage requestPresentationMessage, ProofRecord proofRecord) = await ProofService.CreateRequestAsync(agentContext, aCreateProofRequestRequest.ProofRequest, aCreateProofRequestRequest.ConnectionId); await MessageService.SendAsync(agentContext, requestPresentationMessage, connectionRecord); //(requestPresentationMessage, proofRecord) = // await ProofService.CreateRequestAsync(agentContext, aSendRequestForProofRequest.ProofRequest); //string endpointUri = (await ProvisioningService.GetProvisioningAsync(agentContext.Wallet)).Endpoint.Uri; //string encodedRequestPresentationMessage = requestPresentationMessage.ToJson().ToBase64(); //string proofRequestUrl = $"{endpointUri}?c_i={encodedRequestPresentationMessage}"; var response = new CreateProofRequestResponse(requestPresentationMessage, aCreateProofRequestRequest.CorrelationId); return(await Task.Run(() => response)); }
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); }
/// <inheritdoc /> public virtual async Task ProcessTransactionAsync(IAgentContext agentContext, TransactionResponseMessage connectionTransactionMessage, ConnectionRecord connection) { Logger.LogInformation(CustomLoggingEvents.ProcessTransaction, "To {1}", connection.TheirDid); var transactionRecord = await RecordService.GetAsync <TransactionRecord>(agentContext.Wallet, connectionTransactionMessage.Transaction); if (!transactionRecord.Used) { transactionRecord.ConnectionRecord = connection; if (transactionRecord.ProofRequest != null) { var(message, record) = await ProofService.CreateRequestAsync(agentContext, transactionRecord.ProofRequest); transactionRecord.ProofRecordId = record.Id; var deleteId = Guid.NewGuid().ToString(); message.AddDecorator(deleteId, "delete_id"); record.SetTag("delete_id", deleteId); record.ConnectionId = connection.Id; message.Comment = transactionRecord.ProofComment; await RecordService.UpdateAsync(agentContext.Wallet, record); await MessageService.SendAsync(agentContext.Wallet, message, connection); } if (transactionRecord.OfferConfiguration != null) { var(credentialOfferMessage, credentialRecord) = await CredentialService.CreateOfferAsync(agentContext, transactionRecord.OfferConfiguration, connection.Id); transactionRecord.CredentialRecordId = credentialRecord.Id; credentialOfferMessage.Comment = transactionRecord.CredentialComment; await MessageService.SendAsync(agentContext.Wallet, credentialOfferMessage, connection); } transactionRecord.Used = true; await RecordService.UpdateAsync(agentContext.Wallet, transactionRecord); } else { var message = new TransactionErrorMessage() { Transaction = transactionRecord.Id }; await MessageService.SendAsync(agentContext.Wallet, message, connection); } }
public async Task <RequestPresentationMessage> CreateProofNameMessage(ConnectionRecord connectionRecord) { var agentContext = await _agentProvider.GetContextAsync(); var name = connectionRecord.Alias?.Name ?? connectionRecord.Id; var proofRequest = new ProofRequest { Name = "ProofReq", Version = "1.0", Nonce = await AnonCreds.GenerateNonceAsync(), RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { "firstname-required", new ProofAttributeInfo { Name = "firstname" } } } }; (var msg, _) = await _proofService.CreateRequestAsync(agentContext, proofRequest); return(msg); }
public static async Task <(ProofRecord holderProofRecord, ProofRecord requestorProofRecord)> RequestorInitiatedProofProtocolAsync( 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); return(await ProofProtocolAsync(proofService, messages, holderConnection, requestorConnection, holderContext, requestorContext, requestorProofRecord)); }
public async Task <IActionResult> SendPresentationRequestAsync(OperationBody body) { // NOTE: AATH can only start from presentation request, not respond to previous message var context = await _agentContextProvider.GetContextAsync(); var presentationRequest = body.Data; var connectionId = (string)presentationRequest["connection_id"]; var presentationRequestMessage = presentationRequest["presentation_proposal"]["request_presentations~attach"]["data"]; var proofRequest = new ProofRequest { Name = (string)presentationRequestMessage["name"] ?? "test proof", Version = (string)presentationRequestMessage["version"] ?? "1.0", Nonce = await AnonCreds.GenerateNonceAsync(), RequestedAttributes = presentationRequestMessage["requested_attributes"]?.ToObject <Dictionary <string, ProofAttributeInfo> >() ?? new Dictionary <string, ProofAttributeInfo> { }, RequestedPredicates = presentationRequestMessage["requested_predicates"]?.ToObject <Dictionary <string, ProofPredicateInfo> >() ?? new Dictionary <string, ProofPredicateInfo> { } }; _logger.LogInformation("SendPresentationRequest {proofRequest}", proofRequest.ToJson()); var(requestPresentationMessage, proofRecord) = await _proofService.CreateRequestAsync(context, proofRequest, connectionId); var connection = await _connectionService.GetAsync(context, connectionId); var THPresentationExchange = new TestHarnessPresentationExchange { RecordId = proofRecord.Id, ThreadId = proofRecord.GetTag(TagConstants.LastThreadId), State = TestHarnessPresentationExchangeState.RequestSent }; _proofCache.Set(THPresentationExchange.ThreadId, THPresentationExchange); UpdateStateOnMessage(THPresentationExchange, TestHarnessPresentationExchangeState.PresentationReceived, _ => _.MessageType == MessageTypes.PresentProofNames.Presentation && _.ThreadId == THPresentationExchange.ThreadId); _logger.LogDebug("Send Presentation Request {requestPresentationMessage}", requestPresentationMessage.ToJson()); await _messageService.SendAsync(context, requestPresentationMessage, connection); return(Ok(THPresentationExchange)); }
public async Task RequestIdentityProof() { var context = await _agentContextProvider.GetContextAsync(); //var connection = await _connectionService.GetAsync(context, _connectionRecord.Id); if (SelectedDefinition == null || SelectedSchema == null) { return; } var identityAttributes = new ProofAttributeInfo { Names = new string[] { "fist_name", "last_name" }, Restrictions = new List <AttributeFilter> { new AttributeFilter { SchemaId = SelectedSchema.Id, CredentialDefinitionId = SelectedDefinition.Id } } }; var proofRequestObject = new ProofRequest { Name = "Identity Proof Request", Version = "3.0", Nonce = new BigInteger(Guid.NewGuid().ToByteArray()).ToString(), RequestedAttributes = new Dictionary <string, ProofAttributeInfo> { { $"identity_attrs_requirement", identityAttributes } }, RequestedPredicates = null }; var(request, _) = await _proofService.CreateRequestAsync(context, proofRequestObject, _connectionRecord.Id); await _messageService.SendAsync(context, request, _connectionRecord); }
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 retrieves 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); }