Beispiel #1
0
        public void ShouldFindPublicKeysAccountUsingIndexInitialisingWithPublicKey(string address, int index)
        {
            var wallet = new Wallet(Words, Password);
            var bytes  = wallet.GetMasterExtPubKey().ToBytes();
            var hex    = bytes.ToHex();

            Console.WriteLine(hex);
            var publicWallet = new PublicWallet(hex);

            var account = publicWallet.GetAddress(index);

            Assert.Equal(address, account);
        }
Beispiel #2
0
        public void ShouldFindPublicKeysAccountUsingIndexInitialisingWithWif(string address, int index)
        {
            var wallet    = new Wallet(Words, Password);
            var wif       = wallet.GetMasterExtPubKey().GetWif(Network.Main).ToWif();
            var extPubKey = ExtPubKey.Parse(wif, Network.Main);

            Console.WriteLine(wif);
            var publicWallet = new PublicWallet(extPubKey);

            var account = publicWallet.GetAddress(index);

            Assert.Equal(address, account);
        }
Beispiel #3
0
        public async Task <IActionResult> GetStoreEthereumLikePaymentMethod(string cryptoCode,
                                                                            EditEthereumPaymentMethodViewModel viewModel)
        {
            var network = _btcPayNetworkProvider.GetNetwork <EthereumBTCPayNetwork>(cryptoCode);

            if (network is null)
            {
                return(NotFound());
            }

            var store           = StoreData;
            var blob            = StoreData.GetStoreBlob();
            var paymentMethodId = new PaymentMethodId(network.CryptoCode, EthereumPaymentType.Instance);

            var currentPaymentMethod = StoreData.GetSupportedPaymentMethods(_btcPayNetworkProvider)
                                       .OfType <EthereumSupportedPaymentMethod>().SingleOrDefault(method =>
                                                                                                  method.PaymentId == paymentMethodId);

            if (currentPaymentMethod != null && currentPaymentMethod.CurrentIndex != viewModel.Index &&
                viewModel.OriginalIndex == viewModel.Index)
            {
                viewModel.Index         = currentPaymentMethod.CurrentIndex;
                viewModel.OriginalIndex = currentPaymentMethod.CurrentIndex;
            }
            else if (currentPaymentMethod != null && currentPaymentMethod.CurrentIndex != viewModel.Index &&
                     viewModel.OriginalIndex != currentPaymentMethod.CurrentIndex)
            {
                ModelState.AddModelError(nameof(viewModel.Index),
                                         $"You tried to update the index (to {viewModel.Index}) but new derivations in the background updated the index (to {currentPaymentMethod.CurrentIndex}) ");
                viewModel.Index         = currentPaymentMethod.CurrentIndex;
                viewModel.OriginalIndex = currentPaymentMethod.CurrentIndex;
            }

            Wallet wallet = null;

            try
            {
                if (!string.IsNullOrEmpty(viewModel.Seed))
                {
                    wallet = new Wallet(viewModel.Seed, viewModel.Passphrase,
                                        string.IsNullOrEmpty(viewModel.KeyPath) ? network.GetDefaultKeyPath() : viewModel.KeyPath);
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(nameof(viewModel.Seed), $"seed was incorrect");
            }

            if (wallet != null)
            {
                try
                {
                    wallet.GetAccount(0);
                }
                catch (Exception)
                {
                    ModelState.AddModelError(nameof(viewModel.KeyPath), $"keypath was incorrect");
                }
            }

            PublicWallet publicWallet = null;

            try
            {
                if (!string.IsNullOrEmpty(viewModel.XPub))
                {
                    try
                    {
                        publicWallet = new PublicWallet(viewModel.XPub);
                    }
                    catch (Exception)
                    {
                        publicWallet = new PublicWallet(new BitcoinExtPubKey(viewModel.XPub, Network.Main).ExtPubKey);
                    }

                    if (wallet != null && !publicWallet.ExtPubKey.Equals(wallet.GetMasterPublicWallet().ExtPubKey))
                    {
                        ModelState.AddModelError(nameof(viewModel.XPub),
                                                 $"The xpub does not match the seed/pass/key path provided");
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(nameof(viewModel.XPub), $"xpub was incorrect");
            }

            if (!string.IsNullOrEmpty(viewModel.AddressCheck))
            {
                int index = -1;
                if (wallet != null)
                {
                    index = wallet.GetAddresses(1000)
                            .IndexOf(viewModel.AddressCheck);
                }
                else if (publicWallet != null)
                {
                    index = publicWallet.GetAddresses(1000)
                            .IndexOf(viewModel.AddressCheck);
                }

                if (viewModel.AddressCheckLastUsed && index > -1)
                {
                    viewModel.Index = index;
                }

                if (index == -1)
                {
                    ModelState.AddModelError(nameof(viewModel.AddressCheck),
                                             "Could not confirm address belongs to configured wallet");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            currentPaymentMethod ??= new EthereumSupportedPaymentMethod();
            currentPaymentMethod.Password = viewModel.StoreSeed ? viewModel.Passphrase : "";
            currentPaymentMethod.Seed     = viewModel.StoreSeed ? viewModel.Seed : "";
            currentPaymentMethod.XPub     = string.IsNullOrEmpty(viewModel.XPub) && wallet != null
                ? wallet.GetMasterPublicWallet().ExtPubKey.ToBytes().ToHex()
                : viewModel.XPub;

            currentPaymentMethod.CryptoCode = cryptoCode;
            currentPaymentMethod.KeyPath    = string.IsNullOrEmpty(viewModel.KeyPath)
                ? network.GetDefaultKeyPath()
                : viewModel.KeyPath;
            currentPaymentMethod.CurrentIndex = viewModel.Index;

            blob.SetExcluded(paymentMethodId, !viewModel.Enabled);
            store.SetSupportedPaymentMethod(currentPaymentMethod);
            store.SetStoreBlob(blob);
            await _storeRepository.UpdateStore(store);

            TempData.SetStatusMessageModel(new StatusMessageModel()
            {
                Message = $"updated {cryptoCode}", Severity = StatusMessageModel.StatusSeverity.Success
            });

            return(RedirectToAction("GetStoreEthereumLikePaymentMethods", new { storeId = store.Id }));
        }
Beispiel #4
0
 public void GenerateWatchOnlyWallet(string extPubKey)
 {
     PublicWallet = new PublicWallet(extPubKey);
 }