Ejemplo n.º 1
0
        public void CanDecodeMessageFromUrl()
        {
            var urlEncodedMessage =
                "http://127.0.1.1:8080/indy?c_i=eyJAdHlwZSI6ICJkaWQ6c292OkJ6Q2JzTlloTXJqSGlxWkRUVUFTSGc7c3BlYy9jb25uZWN0aW9ucy8xLjAvaW52aXRhdGlvbiIsICJsYWJlbCI6ICJNb250eSIsICJpbWFnZVVybCI6ICJodHRwczovL3Bicy50d2ltZy5jb20vcHJvZmlsZV9pbWFnZXMvNjk3MDM1MzgzNjc5Mjk1NDg4L182dmw3NHRNXzQwMHg0MDAucG5nIiwgInJlY2lwaWVudEtleXMiOiBbInljVW80QzdCRUxLcG9OaVA4ZDgxQ254cG1TU0J3alREZUNaTEpETkNUR0ciXSwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwOi8vMTI3LjAuMS4xOjgwODAvaW5keSIsICJyb3V0aW5nS2V5cyI6IFtdLCAiQGlkIjogIjA1YjNjMjkxLWE1YWEtNGJjOS1iZGU5LTdiMzNkMWRmZDMwMCJ9";

            var message = MessageUtils.DecodeMessageFromUrlFormat <ConnectionRequestMessage>(urlEncodedMessage);

            Assert.NotNull(message);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AcceptInvitation(AcceptConnectionViewModel model)
        {
            var context = await _agentContextProvider.GetContextAsync();

            var invite = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(model.InvitationDetails);

            var(request, record) = await _connectionService.CreateRequestAsync(context, invite);

            await _messageService.SendAsync(context.Wallet, request, record);

            return(RedirectToAction("Index"));
        }
            public override Task <Unit> Handle
            (
                ViewInvitationAction aViewInvitationAction,
                CancellationToken aCancellationToken
            )
            {
                ConnectionState.ConnectionInvitationMessage =
                    MessageUtils
                    .DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(aViewInvitationAction.InvitationDetails);

                return(Unit.Task);
            }
            public override Task <Unit> Handle
            (
                ViewProofRequestAction aViewProofRequestAction,
                CancellationToken aCancellationToken
            )
            {
                PresentProofState.RequestPresentationMessage =
                    MessageUtils
                    .DecodeMessageFromUrlFormat <RequestPresentationMessage>(aViewProofRequestAction.EncodedProofRequestMessage);

                return(Unit.Task);
            }
Ejemplo n.º 5
0
        public IActionResult ViewInvitation(AcceptConnectionViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect(Request.Headers["Referer"].ToString()));
            }

            ViewData["InvitationDetails"] = model.InvitationDetails;

            var invite = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(model.InvitationDetails);

            return(View(invite));
        }
Ejemplo n.º 6
0
        public async Task <ReceiveInvitationResponse> Handle
        (
            ReceiveInvitationRequest aReceiveInvitationRequest,
            CancellationToken aCancellationToken
        )
        {
            ConnectionInvitationMessage connectionInvitationMessage =
                MessageUtils
                .DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(aReceiveInvitationRequest.InvitationDetails);

            var response =
                new ReceiveInvitationResponse(aReceiveInvitationRequest.CorrelationId, connectionInvitationMessage);

            return(await Task.Run(() => response));
        }
Ejemplo n.º 7
0
        public async Task AcceptConnectionButton()
        {
            ConnectionInvitationMessage invitation;

            try
            {
                invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(InvitationMessageUrl);
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid invitation!");
                Device.BeginInvokeOnMainThread(async() => await NavigationService.PopModalAsync());
                return;
            }
        }
Ejemplo n.º 8
0
        public async Task AcceptInvitation()
        {
            Console.Write("Invitation = ");
            var invitationUrl = Console.ReadLine();

            try
            {
                var invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(invitationUrl);
                var(request, record) = await connectionService.CreateRequestAsync(agentContext, invitation);

                await messageService.SendAsync(agentContext.Wallet, request, record);

                Console.Write("Accept invitation completed.");
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }

            Console.ReadLine();
        }
        public async Task <AcceptInvitationResponse> Handle
        (
            AcceptInvitationRequest aAcceptInvitationRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            ConnectionInvitationMessage connectionInvitationMessage =
                MessageUtils
                .DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(aAcceptInvitationRequest.InvitationDetails);

            (ConnectionRequestMessage connectionRequestMessage, ConnectionRecord connectionRecord)
                = await ConnectionService.CreateRequestAsync(agentContext, connectionInvitationMessage);

            await MessageService.SendAsync(agentContext, connectionRequestMessage, connectionRecord);

            var response = new AcceptInvitationResponse(aAcceptInvitationRequest.CorrelationId);

            return(response);
        }
        public async Task <AcceptProofRequestResponse> Handle
        (
            AcceptProofRequestRequest aAcceptProofRequestRequest,
            CancellationToken aCancellationToken
        )
        {
            IAgentContext agentContext = await AgentProvider.GetContextAsync();

            RequestPresentationMessage requestPresentationMessage =
                MessageUtils
                .DecodeMessageFromUrlFormat <RequestPresentationMessage>(aAcceptProofRequestRequest.EncodedProofRequestMessage);

            //ProofRecord proofRecord =
            //  await ProofService.
            //  CreatePresentationAsync(agentContext, requestPresentationMessage, requestedCredentials: null);

            //await MessageService.SendAsync(agentContext.Wallet, requestPresentationMessage, proofRecord);
            var response = new AcceptProofRequestResponse(aAcceptProofRequestRequest.CorrelationId);

            return(await Task.Run(() => response));
        }
Ejemplo n.º 11
0
        private async Task TextInviteAsync()
        {
            ConnectionInvitationMessage invitation;

            try
            {
                invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(InputText);
            }
            catch (Exception)
            {
                DialogService.Alert("Invalid invitation!");
                Device.BeginInvokeOnMainThread(async() => await NavigationService.PopModalAsync());
                return;
            }

            Device.BeginInvokeOnMainThread(async() =>
            {
                await NavigationService.NavigateBackAsync();
                await NavigationService.NavigateToAsync <AcceptInviteViewModel>(invitation, NavigationType.Modal);
            });
        }
Ejemplo n.º 12
0
        static async Task Main(string[] args)
        {
            await Task.Delay(TimeSpan.FromSeconds(5));

            //var host1 = CreateHostBuilder("Edge1").Build();
            var host2 = CreateHostBuilder("MyTest").Build();

            try
            {
                //await host1.StartAsync();
                await host2.StartAsync();

                //var context1 = await host1.Services.GetRequiredService<IAgentProvider>().GetContextAsync();
                var context2 = await host2.Services.GetRequiredService <IAgentProvider>().GetContextAsync();

                //var (invitation, record1) = await host1.Services.GetRequiredService<IConnectionService>().CreateInvitationAsync(context1, new InviteConfiguration { AutoAcceptConnection = true });
                var invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(@"http://15.206.165.79/?c_i=eyJsYWJlbCI6Ik15IEFnZW5jeSIsImltYWdlVXJsIjpudWxsLCJzZXJ2aWNlRW5kcG9pbnQiOiJodHRwOi8vMTUuMjA2LjE2NS43OS8iLCJyb3V0aW5nS2V5cyI6WyJ5THZFNnJuckNKWG5iYzNOUXFhcWdQazJHUmtDd2p1dmJFR3gxOFh5Y0JHIl0sInJlY2lwaWVudEtleXMiOlsiMjVGV1NQZG5kSno4RlIyVE1IQmZmdnlKaHFIVnlrSFNHRzNFbmN1WEdjRmEiXSwiQGlkIjoiY2UyMmJkZWYtYTA3Zi00NGY2LThiOWMtNWViNDIzZTFkYjIxIiwiQHR5cGUiOiJkaWQ6c292OkJ6Q2JzTlloTXJqSGlxWkRUVUFTSGc7c3BlYy9jb25uZWN0aW9ucy8xLjAvaW52aXRhdGlvbiJ9");
                var(request, record2) = await host2.Services.GetRequiredService <IConnectionService>().CreateRequestAsync(context2, invitation);

                await host2.Services.GetRequiredService <IMessageService>().SendAsync(context2.Wallet, request, record2);

                //await host1.Services.GetRequiredService<IEdgeClientService>().FetchInboxAsync(context1);
                await host2.Services.GetRequiredService <IEdgeClientService>().FetchInboxAsync(context2);

                //record1 = await host1.Services.GetRequiredService<IConnectionService>().GetAsync(context1, record1.Id);
                record2 = await host2.Services.GetRequiredService <IConnectionService>().GetAsync(context2, record2.Id);

                //await host1.Services.GetRequiredService<IEdgeClientService>().AddDeviceAsync(context1, new AddDeviceInfoMessage { DeviceId = "123", DeviceVendor = "Apple" });

                //Console.WriteLine($"Record1 is {record1.State}, Record2 is {record2.State}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Connected");
        }
Ejemplo n.º 13
0
        private async Task ScanPhysicalInviteAsync()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            var opts           = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var scannerPage = new ZXingScannerPage(opts);

            scannerPage.OnScanResult += (result) => {
                scannerPage.IsScanning = false;

                ConnectionInvitationMessage invitation;

                try
                {
                    invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(result.Text);
                }
                catch (Exception)
                {
                    DialogService.Alert("Invalid invitation!");
                    Device.BeginInvokeOnMainThread(async() => await NavigationService.PopModalAsync());
                    return;
                }

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

            await NavigationService.NavigateToAsync((Page)scannerPage, NavigationType.Modal);
        }
Ejemplo n.º 14
0
 public void DecodeMessageToUrlThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => MessageUtils.DecodeMessageFromUrlFormat(null));
     Assert.Throws <ArgumentNullException>(() => MessageUtils.DecodeMessageFromUrlFormat(""));
 }
Ejemplo n.º 15
0
        static async Task Main(string[] args)
        {
            var host = CreateHostBuilder("Edge").Build();
            await host.StartAsync();

            var context = await host.Services.GetRequiredService <IAgentProvider>().GetContextAsync();

            ConnectionRequestMessage request;
            ConnectionRecord         record = null;

            while (true)
            {
                var options = new List <string>()
                {
                    "1", "2", "3", "4", "0"
                };
                Console.Write(@"
                    Choose your option.
                    1) Request Invitation
                    2) Get basic messages
                    3) List and request offer
                    4) List Credentials
                    0) Exit
                ");
                var option = Console.ReadLine();
                if (options.Contains(option))
                {
                    switch (option)
                    {
                    case "0":
                        Console.WriteLine("Exiting....");
                        break;

                    case "1":
                        Console.WriteLine("Enter Invite");
                        var invite     = Console.ReadLine();
                        var invitation = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(invite);

                        (request, record) = await host.Services.GetRequiredService <IConnectionService>().CreateRequestAsync(context, invitation);

                        await host.Services.GetRequiredService <IMessageService>().SendAsync(context.Wallet, request, record);

                        Console.WriteLine(record);

                        await host.Services.GetRequiredService <IEdgeClientService>().FetchInboxAsync(context);

                        record = await host.Services.GetRequiredService <IConnectionService>().GetAsync(context, record.Id);

                        Console.WriteLine(record);
                        break;

                    case "2":
                        try
                        {
                            await host.Services.GetRequiredService <IEdgeClientService>().FetchInboxAsync(context);

                            var msgs = await host.Services.GetRequiredService <IWalletRecordService>().SearchAsync <BasicMessageRecord>(context.Wallet,
                                                                                                                                        SearchQuery.Equal(nameof(BasicMessageRecord.ConnectionId), record.Id), null, 10);

                            Console.WriteLine("Basic Messages..........");
                            foreach (var item in msgs)
                            {
                                Console.WriteLine(item.Text);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        break;

                    case "3":
                        try
                        {
                            await host.Services.GetRequiredService <IEdgeClientService>().FetchInboxAsync(context);

                            var offers = await host.Services.GetRequiredService <ICredentialService>().ListOffersAsync(context);

                            Console.WriteLine("Credential Offers..........");
                            foreach (var item in offers)
                            {
                                Console.WriteLine(item);
                                (var requestCred, var holderCredentialRecord) = await host.Services.GetRequiredService <ICredentialService>().CreateRequestAsync(context, item.Id);

                                await host.Services.GetRequiredService <IMessageService>().SendAsync(context.Wallet, requestCred, record);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        break;

                    case "4":
                        try
                        {
                            await host.Services.GetRequiredService <IEdgeClientService>().FetchInboxAsync(context);

                            var creds = await host.Services.GetRequiredService <ICredentialService>().ListIssuedCredentialsAsync(context);

                            Console.WriteLine("Credentials..........");
                            foreach (var item in creds)
                            {
                                foreach (var credattr in item.CredentialAttributesValues)
                                {
                                    Console.WriteLine("{0} {1}", credattr.Name, credattr.Value);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        break;

                    default:
                        break;
                    }
                    if (option == "0")
                    {
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Wrong option try again.");
                }
            }
        }
Ejemplo n.º 16
0
 public void OnPost(string invitationDetails)
 {
     this.InvitationDetails = invitationDetails;
     InvitationMessage      = MessageUtils.DecodeMessageFromUrlFormat <ConnectionInvitationMessage>(InvitationDetails);
 }