public async void VerifyEndorsement() { ObservableCollection <ListItemViewModel> identitiesInCommon = new ObservableCollection <ListItemViewModel>(); ListPageViewModel displayListOfCommonIdentities = new ListPageViewModel(identitiesInCommon, this); // Do some endorsement ScanQRCodeViewModel scanListOfEndorsedGuids = new ScanQRCodeViewModel( (string endorsementsAsString) => { List <string> endorsingIDs = JsonConvert.DeserializeObject <List <string> >(endorsementsAsString); IEnumerable <Identity> intersectionOfIdentities = LocalIdentityStore.Instance.GetAllIdentities().Result.Where(x => endorsingIDs.Contains(x.IdentityGUID.ToString())); foreach (var identity in intersectionOfIdentities) { identitiesInCommon.Add(new ListItemViewModel(identity, identity.FriendlyName, () => { MessagePageViewModel verificationResult = new MessagePageViewModel(string.Empty, displayListOfCommonIdentities); QRDisplayViewModel displaySelectedIdentityQR = new QRDisplayViewModel( ((Identity)identity).IdentityGUID.ToString(), "Display selected identity"); ScanQRCodeViewModel scanEndorsement = new ScanQRCodeViewModel( (string endorsement) => { var endorsementIsValid = identity.IsValidEndorsement(Endorsement.GetFromJSONString(endorsement)); if (endorsementIsValid) { verificationResult.Message = "The endorsement is valid!"; verificationResult.MessageIcon = MessagePageViewModel.MessageIcons.Success; } else { verificationResult.Message = "The endorsement is NOT valid!"; verificationResult.MessageIcon = MessagePageViewModel.MessageIcons.Error; } }, verificationResult, "Scan endorsement"); displaySelectedIdentityQR.PostDisplayComplete = scanEndorsement; NavigationMaster.Instance.NavigateTo(displaySelectedIdentityQR); })); } }, displayListOfCommonIdentities, "Scan list of endorsements"); // Navigate back to main page await NavigationMaster.Instance.NavigateTo(scanListOfEndorsedGuids); }
public async Task AcceptEndorsement() { Endorsement endorsement = null; KeyPair publicKey = null; // assigning here to make compiler happy Guid guid; Identity endorserIdentity = null; var getFriendlyName = new InputPageViewModel( new List <InputViewModel>() { new InputViewModel() }, async(content) => { endorserIdentity.FriendlyName = content.First().Content; if (endorserIdentity.IsValidEndorsement(endorsement)) { await LocalIdentityStore.Instance.StoreIdentity(endorserIdentity); LocalIdentityStore.Instance.AcceptEndorsement(endorsement); } }, new MainPageViewModel()); var readEndorsement = new ScanQRCodeViewModel( async(string result) => { endorsement = Endorsement.GetFromJSONString(result); endorserIdentity = await LocalIdentityStore.Instance.GetIdentity(guid); if (endorserIdentity == null) { endorserIdentity = new Identity(guid); } endorserIdentity.KeyPairsAssertingOwnership.Add(publicKey); }, getFriendlyName, "Scan endorsement"); var readPublicKey = new ScanQRCodeViewModel((byte[] result) => { publicKey = new KeyPair(result); }, readEndorsement, "Scan Public Key"); var readGuid = new ScanQRCodeViewModel((string result) => { guid = Guid.Parse(result); }, readPublicKey, "Scan ID"); await NavigationMaster.Instance.NavigateTo(readGuid); }