Example #1
0
        public async Task <bool> RequestSignIn(string contractId, string title, Uri successUrl, Uri failureUrl, Uri appUrl)
        {
            if (!string.IsNullOrWhiteSpace(GetAccountId()))
            {
                return(true);
            }
            if (await _keyStore.GetKeyAsync(_networkId, GetAccountId()) != null)
            {
                return(true);
            }

            var accessKey = KeyPair.FromRandom("ed25519");

            var url = new UriBuilder(_walletBaseUrl + LoginWalletUrlSuffix);

            url.Query = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "title", title },
                { "contract_id", contractId },
                { "success_url", successUrl.AbsoluteUri },
                { "failure_url", failureUrl.AbsoluteUri },
                { "app_url", appUrl.AbsoluteUri },
                { "public_key", accessKey.GetPublicKey().ToString() },
            }).ReadAsStringAsync().Result;

            await _keyStore.SetKeyAsync(_networkId, PendingAccessKeyPrefix + accessKey.GetPublicKey(), accessKey);

            return(_authService.OpenUrl(url.Uri.AbsoluteUri));
        }
        public async Task CanCompleteSignIn()
        {
            var keyPair = KeyPair.FromRandom("ed25519");
            await _keyStore.SetKeyAsync("networkId", "pending_key" + keyPair.GetPublicKey().ToString(), keyPair);

            var url = "http://example.com/location?account_id=near.account&public_key=" + keyPair.GetPublicKey().ToString();
            await _walletAccount.CompleteSignIn(url);

            Assert.AreEqual((await _keyStore.GetKeyAsync("networkId", "near.account")).ToString(), keyPair.ToString());
            Assert.IsTrue(_walletAccount.IsSignedIn());
            Assert.AreEqual("near.account", _walletAccount.GetAccountId());
        }
Example #3
0
        public async void ReadSuccessfully()
        {
            var fileServiceMock = new Mock <IFileService>();

            fileServiceMock.Setup(x => x.Exists(It.IsAny <string>())).Returns(true);
            fileServiceMock.Setup(x => x.ReadAllText(It.IsAny <string>())).Returns("{ \"thehost\" : \"abc123\" }");

            var fileService = fileServiceMock.Object;

            var keyStore = new KeyStore(fileService);

            Assert.Equal("abc123", await keyStore.GetKeyAsync("thehost"));
        }
Example #4
0
        public override async Task <PublicKey> GetPublicKeyAsync(string accountId = "", string networkId = "")
        {
            var keyPair = await _keyStore.GetKeyAsync(networkId, accountId);

            return(keyPair?.GetPublicKey());
        }