public async Task ScanProofRequest()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var result = await scanner.Scan(opts);

            if (result == null)
            {
                return;
            }

            RequestPresentationMessage presentationMessage;

            try
            {
                presentationMessage = await MessageDecoder.ParseMessageAsync(result.Text) as RequestPresentationMessage
                                      ?? throw new Exception("Unknown message type");
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid Proof Request!");
                return;
            }

            if (presentationMessage == null)
            {
                return;
            }

            try
            {
                var request = presentationMessage.Requests?.FirstOrDefault((Attachment x) => x.Id == "libindy-request-presentation-0");
                if (request == null)
                {
                    DialogService.Alert("scanned qr code does not look like a proof request", "Error");
                    return;
                }
                var proofRequest = request.Data.Base64.GetBytesFromBase64().GetUTF8String().ToObject <ProofRequest>();
                if (proofRequest == null)
                {
                    return;
                }

                var proofRequestViewModel = _scope.Resolve <ProofRequestViewModel>(new NamedParameter("proofRequest", proofRequest),
                                                                                   new NamedParameter("requestPresentationMessage", presentationMessage));

                await NavigationService.NavigateToAsync(proofRequestViewModel);
            }
            catch (Exception xx)
            {
                DialogService.Alert(xx.Message);
            }
        }
        public async Task ScanInvite()
        {
            ConnectionInvitationMessage invitation = null;
            bool isEmulated = false;  //ONLY FOR TESTING

            if (!isEmulated)
            {
                var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
                var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <ZXing.BarcodeFormat> {
                        expectedFormat
                    }
                };

                var scanner = new ZXing.Mobile.MobileBarcodeScanner();

                var result = await scanner.Scan(opts);

                if (result == null)
                {
                    return;
                }

                try
                {
                    invitation = await MessageDecoder.ParseMessageAsync(result.Text) as ConnectionInvitationMessage
                                 ?? throw new Exception("Unknown message type");
                }
                catch (Exception)
                {
                    DialogService.Alert("Invalid invitation!");
                    return;
                }
            }
            else
            {
                invitation = new ConnectionInvitationMessage()
                {
                    Id            = "453b0d8e-50d0-4a18-bf44-7d7369a0c31f",
                    Label         = "Verifier",
                    Type          = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation",
                    ImageUrl      = "",
                    RecipientKeys = new List <string>()
                    {
                        "DPqj1fdVajDYdVgeT36NUSoVghjkapaHpVUdwbL1z6ye"
                    },
                    RoutingKeys = new List <string>()
                    {
                        "9RUPb4jPtR2S1P9yVy85ugwiywqqzDfxRrDZnKCTQCtH"
                    },
                    ServiceEndpoint = "http://mylocalhost:5002"
                };
            }
            Device.BeginInvokeOnMainThread(async() =>
            {
                await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal);
            });
        }
示例#3
0
        private async Task ScanInvite()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;

            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var context = await _agentContextProvider.GetContextAsync();

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var result = await scanner.Scan(opts);

            if (result == null)
            {
                return;
            }

            AgentMessage message = await MessageDecoder.ParseMessageAsync(result.Text);

            switch (message)
            {
            case ConnectionInvitationMessage invitation:
                break;

            case RequestPresentationMessage presentation:
                RequestPresentationMessage proofRequest = (RequestPresentationMessage)presentation;
                var         service     = message.GetDecorator <ServiceDecorator>(DecoratorNames.ServiceDecorator);
                ProofRecord proofRecord = await _proofService.ProcessRequestAsync(context, proofRequest, null);

                proofRecord.SetTag("RecipientKey", service.RecipientKeys.ToList()[0]);
                proofRecord.SetTag("ServiceEndpoint", service.ServiceEndpoint);
                await _recordService.UpdateAsync(context.Wallet, proofRecord);

                _eventAggregator.Publish(new ApplicationEvent {
                    Type = ApplicationEventType.ProofRequestUpdated
                });
                break;

            default:
                DialogService.Alert("Invalid invitation!");
                return;
            }

            Device.BeginInvokeOnMainThread(async() =>
            {
                if (message is ConnectionInvitationMessage)
                {
                    await NavigationService.NavigateToAsync <AcceptInviteViewModel>(message as ConnectionInvitationMessage, NavigationType.Modal);
                }
            });
        }
示例#4
0
        public async Task ScanInvite()
        {
            if (Result == null)
            {
                return;
            }

            try
            {
                var msg = await MessageDecoder.ParseMessageAsync(Result.Text) ?? throw new Exception("Unknown message type");

                if (msg.Type == MessageTypes.ConnectionInvitation)
                {
                    var invitation = msg as ConnectionInvitationMessage;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal);
                    });
                }
                else if (msg.Type == MessageTypes.PresentProofNames.RequestPresentation)
                {
                    var requestMessage = msg as RequestPresentationMessage;

                    var request = requestMessage.Requests?.FirstOrDefault((Attachment x) => x.Id == "libindy-request-presentation-0");
                    if (request == null)
                    {
                        DialogService.Alert("scanned qr code does not look like a proof request", "Error");
                        return;
                    }
                    var proofRequest = request.Data.Base64.GetBytesFromBase64().GetUTF8String().ToObject <ProofRequest>();
                    if (proofRequest == null)
                    {
                        return;
                    }

                    var proofRequestViewModel = _scope.Resolve <ProofRequestViewModel>(new NamedParameter("proofRequest", proofRequest),
                                                                                       new NamedParameter("requestPresentationMessage", requestMessage));

                    await NavigationService.NavigateToAsync(proofRequestViewModel);
                }
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid invitation!");
                return;
            }
        }
        public async Task ScanInvite()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var result = await scanner.Scan(opts);

            if (result == null)
            {
                return;
            }

            ConnectionInvitationMessage invitation;

            try
            {
                invitation = await MessageDecoder.ParseMessageAsync(result.Text) as ConnectionInvitationMessage
                             ?? throw new Exception("Unknown message type");
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid invitation!");
                return;
            }

            Device.BeginInvokeOnMainThread(async() =>
            {
                await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal);
            });
        }