/// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messageContext">The agent message agentContext.</param>
        /// <returns></returns>
        /// <exception cref="AgentFrameworkException">Unsupported message type {messageType}</exception>
        public async Task <AgentMessage> ProcessAsync(IAgentContext agentContext, MessageContext messageContext)
        {
            switch (messageContext.GetMessageType())
            {
            case MessageTypes.ProofRequest:
            {
                var request = messageContext.GetMessage <ProofRequestMessage>();
                var proofId = await _proofService.ProcessProofRequestAsync(agentContext, request, messageContext.Connection);

                messageContext.ContextRecord = await _proofService.GetAsync(agentContext, proofId);

                break;
            }

            case MessageTypes.DisclosedProof:
            {
                var proof   = messageContext.GetMessage <ProofMessage>();
                var proofId = await _proofService.ProcessProofAsync(agentContext, proof);

                messageContext.ContextRecord = await _proofService.GetAsync(agentContext, proofId);

                break;
            }

            default:
                throw new AgentFrameworkException(ErrorCode.InvalidMessage,
                                                  $"Unsupported message type {messageContext.GetMessageType()}");
            }
            return(null);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Details(string proofRecordId)
        {
            var agentContext = await _agentProvider.GetContextAsync();

            var proofRecord = await _proofService.GetAsync(agentContext, proofRecordId);

            var request = JsonConvert.DeserializeObject <ProofRequest>(proofRecord.RequestJson);
            var model   = new ProofsDetailViewModel
            {
                ProofPartial = JsonConvert.DeserializeObject <PartialProof>(proofRecord.ProofJson),
                Name         = request.Name
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <GetCredentialsForProofResponse> Handle
        (
            GetCredentialsForProofRequest aGetCredentialsForProofRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ProofRecord proofRecord = await ProofService.GetAsync(agentContext, aGetCredentialsForProofRequest.ProofId);

            ProofRequest proofRequest = JsonConvert.DeserializeObject <ProofRequest>(proofRecord.RequestJson);

            //ProofServiceUtils.GetAutoRequestedCredentialsForProofCredentials
            List <Credential> credentials =
                await ProofService
                .ListCredentialsForProofRequestAsync
                (
                    agentContext,
                    proofRequest,
                    aGetCredentialsForProofRequest.Referent
                );

            var response = new GetCredentialsForProofResponse(credentials, aGetCredentialsForProofRequest.CorrelationId);

            return(response);
        }
Exemplo n.º 5
0
        private async Task DisplayRequestPresentation(string recordId)
        {
            IAgentContext context = await _agentContextProvider.GetContextAsync();

            ProofRecord proofRecord = await _proofService.GetAsync(context, recordId);

            ProofRequestViewModel proofRequest = await _proofAssembler.Assemble(proofRecord);

            await _requestPresentationFiller.Fill(proofRequest);

            await NavigationService.NavigateToAsync(proofRequest, null, NavigationType.Modal);
        }
        public async Task <GetProofResponse> Handle
        (
            GetProofRequest aGetProofRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ProofRecord proofRecord = await ProofService.GetAsync(agentContext, aGetProofRequest.ProofId);

            var response = new GetProofResponse(proofRecord, aGetProofRequest.CorrelationId);

            return(await Task.Run(() => response));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public async Task CredentialProofDemo()
        {
            int events = 0;

            _eventAggregator.GetEventByType <ServiceMessageProcessingEvent>()
            .Where(_ => (_.MessageType == MessageTypes.ProofRequest ||
                         _.MessageType == MessageTypes.DisclosedProof))
            .Subscribe(_ =>
            {
                events++;
            });

            //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, _pool, MasterSecretId, true);

            _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               = "123",
                    RequestedAttributes = new Dictionary <string, ProofAttributeInfo>
                    {
                        { "first-name-requirement", new ProofAttributeInfo {
                              Name = "first_name"
                          } }
                    }
                };

                //Requestor sends a proof request
                await _proofService.SendProofRequestAsync(_requestorWallet, requestorConnection.Id, proofRequestObject);
            }

            // Holder accepts the proof requests and builds a proof
            {
                //Holder retrives proof request message from their cloud agent
                var proofRequest = FindContentMessage <ProofRequestMessage>();
                Assert.NotNull(proofRequest);

                _holderWallet.Connection = holderConnection;
                //Holder stores the proof request
                var holderProofRequestId = await _proofService.ProcessProofRequestAsync(_holderWallet, proofRequest);

                var holderProofRecord = await _proofService.GetAsync(_holderWallet, holderProofRequestId);

                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,
                        Timestamp    = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
                    });
                }

                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 = await _proofService.AcceptProofRequestAsync(_holderWallet, holderProofRequestId, requestedCredentials);

                _messages.Add(proofMessage);
            }

            //Requestor retrives proof message from their cloud agent
            var proof = FindContentMessage <ProofMessage>();

            Assert.NotNull(proof);

            _requestorWallet.Connection = requestorConnection;
            //Requestor stores proof
            var requestorProofId = await _proofService.ProcessProofAsync(_requestorWallet, proof);

            //Requestor verifies proof
            var requestorVerifyResult = await _proofService.VerifyProofAsync(_requestorWallet, requestorProofId);

            ////Verify the proof is valid
            Assert.True(requestorVerifyResult);

            Assert.True(events == 2);

            ////Get the proof from both parties wallets
            //var requestorProof = await _proofService.GetProof(_requestorWallet, requestorProofId);
            //var holderProof = await _proofService.GetProof(_holderWallet, holderProofRequestId);

            ////Verify that both parties have a copy of the proof
            //Assert.Equal(requestorProof, holderProof);
        }