public ProofRequestViewModel(IUserDialogs userDialogs,
                                     INavigationService navigationService,
                                     IProofService proofService,
                                     IAgentProvider agentContextProvider,
                                     IMessageService messageService,
                                     IConnectionService connectionService,
                                     IEventAggregator eventAggregator,
                                     IWalletRecordService recordService,
                                     IProofCredentialSelector proofCredentialSelector,
                                     ProofRecord proof) : base(AppResources.ProofRequestPageTitle, userDialogs, navigationService)
        {
            _proofRecord             = proof;
            _proofService            = proofService;
            _agentContextProvider    = agentContextProvider;
            _messageService          = messageService;
            _connectionService       = connectionService;
            _eventAggregator         = eventAggregator;
            _userDialogs             = userDialogs;
            _recordService           = recordService;
            _navigationService       = navigationService;
            _proofCredentialSelector = proofCredentialSelector;
            GetConnectionAlias();

            _proofRequest = JsonConvert.DeserializeObject <ProofRequest>(_proofRecord.RequestJson);

            ProofName = _proofRequest.Name;

            Version = _proofRequest.Version;

            State = ProofStateTranslator.Translate(_proofRecord.State);

            AreButtonsVisible = _proofRecord.State == ProofState.Requested;

            Attributes = new List <ProofAttributeViewModel>();
        }
        public async Task <ProofRequestViewModel> Assemble(ProofRecord proofRecord)
        {
            if (proofRecord == null)
            {
                return(null);
            }

            ProofRequestViewModel proofRequest2 = _scope.Resolve <ProofRequestViewModel>(new NamedParameter("proof", proofRecord));

            proofRequest2.Id = proofRecord.Id;

            if (proofRecord.ProofJson != null)
            {
                var partialProof = JsonConvert.DeserializeObject <PartialProof>(proofRecord.ProofJson);
                var proofRequest = JsonConvert.DeserializeObject <ProofRequest>(proofRecord.RequestJson);
                proofRequest2.Attributes.Clear();
                foreach (var revealedAttributeKey in partialProof.RequestedProof.RevealedAttributes.Keys)
                {
                    var proofAttribute = new ProofAttributeViewModel
                    {
                        Name        = proofRequest.RequestedAttributes[revealedAttributeKey].Name, // TODO: Que faire pour gérer l'attribut Names?
                        IsPredicate = false,
                        IsRevealed  = true,
                        Type        = "Text",
                        Value       = partialProof.RequestedProof.RevealedAttributes[revealedAttributeKey].Raw
                    };
                    proofRequest2.Attributes.Add(proofAttribute);
                }
            }
            else
            {
                ProofRequest proofRequest = JsonConvert.DeserializeObject <ProofRequest>(proofRecord.RequestJson);
                proofRequest2.Attributes.Clear();
                foreach (KeyValuePair <string, ProofAttributeInfo> requestedAttribute in proofRequest.RequestedAttributes)
                {
                    proofRequest2.Attributes.Add(new ProofAttributeViewModel
                    {
                        Id   = requestedAttribute.Key,
                        Name = requestedAttribute.Value.Name // TODO: Que faire pour gérer l'attribut Names?
                    });
                }
                foreach (KeyValuePair <string, ProofPredicateInfo> requestedAttribute in proofRequest.RequestedPredicates)
                {
                    proofRequest2.Attributes.Add(new ProofAttributeViewModel
                    {
                        Id          = requestedAttribute.Key,
                        Name        = requestedAttribute.Value.Name, // TODO: Que faire pour gérer l'attribut Names?
                        IsPredicate = true
                    });
                }
            }

            proofRequest2.State = ProofStateTranslator.Translate(proofRecord.State);

            return(proofRequest2);
        }
        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();
        }