예제 #1
0
        /// <summary>
        /// Open and connect the wallet.
        /// </summary>
        /// <returns></returns>
        private void OpenAndConnectWallet()
        {
            if (textBoxPasswordWallet.Text == "")
            {
#if WINDOWS
                ClassFormPhase.MessageBoxInterface(ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NO_PASSWORD_WRITTED_CONTENT_TEXT"),
                                                   ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NO_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
#else
                MessageBox.Show(ClassFormPhase.WalletXiropht, ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NO_PASSWORD_WRITTED_CONTENT_TEXT"),
                                ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NO_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif
                return;
            }

            new Thread(async delegate()
            {
                try
                {
                    bool error = false;

                    string passwordEncrypted = ClassAlgo.GetEncryptedResultManual(ClassAlgoEnumeration.Rijndael,
                                                                                  textBoxPasswordWallet.Text, textBoxPasswordWallet.Text, ClassWalletNetworkSetting.KeySize);

                    ClassWalletObject.WalletDataDecrypted = ClassAlgo.GetDecryptedResultManual(ClassAlgoEnumeration.Rijndael,
                                                                                               _walletFileData, passwordEncrypted, ClassWalletNetworkSetting.KeySize); // AES
                    if (ClassWalletObject.WalletDataDecrypted == ClassAlgoErrorEnumeration.AlgoError)
                    {
                        error = true;
                    }

                    if (error)
                    {
                        ClassWalletObject.WalletDataDecrypted = ClassAlgo.GetDecryptedResultManual(ClassAlgoEnumeration.Rijndael,
                                                                                                   _walletFileData, textBoxPasswordWallet.Text, ClassWalletNetworkSetting.KeySize); // AES
                    }

                    if (ClassWalletObject.WalletDataDecrypted == ClassAlgoErrorEnumeration.AlgoError)
                    {
#if WINDOWS
                        ClassFormPhase.MessageBoxInterface(
                            ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_WRONG_PASSWORD_WRITTED_CONTENT_TEXT"),
                            ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_WRONG_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                        MessageBox.Show(ClassFormPhase.WalletXiropht,
                                        ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_WRONG_PASSWORD_WRITTED_CONTENT_TEXT"),
                                        ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_WRONG_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
                        return;
                    }

                    var splitWalletFileDecrypted =
                        ClassWalletObject.WalletDataDecrypted.Split(new[] { "\n" }, StringSplitOptions.None);
                    string walletAddress = splitWalletFileDecrypted[0];
                    string walletKey     = splitWalletFileDecrypted[1];
                    if (!await ClassWalletObject.InitializationWalletConnection(walletAddress, textBoxPasswordWallet.Text,
                                                                                walletKey, ClassWalletPhase.Login))
                    {
                        MethodInvoker invoker = () => textBoxPasswordWallet.Text = "";
                        BeginInvoke(invoker);
#if WINDOWS
                        ClassFormPhase.MessageBoxInterface(
                            ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_CONTENT_TEXT"), ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_TITLE_TEXT"), MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
#else
                        MessageBox.Show(ClassFormPhase.WalletXiropht,
                                        ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_CONTENT_TEXT"), ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_TITLE_TEXT"), MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
#endif
                        return;
                    }

                    MethodInvoker invoke = () => textBoxPasswordWallet.Text = "";
                    BeginInvoke(invoke);

                    ClassWalletObject.ListenSeedNodeNetworkForWallet();

                    Stopwatch packetSpeedCalculator = new Stopwatch();
                    packetSpeedCalculator.Start();
                    if (await ClassWalletObject.WalletConnect.SendPacketWallet(ClassWalletObject.Certificate, string.Empty, false))
                    {
                        packetSpeedCalculator.Stop();
                        if (packetSpeedCalculator.ElapsedMilliseconds > 0)
                        {
                            Thread.Sleep((int)packetSpeedCalculator.ElapsedMilliseconds);
                        }
                        await ClassWalletObject.WalletConnect.SendPacketWallet(
                            ClassConnectorSettingEnumeration.WalletLoginType + "|" + ClassWalletObject.WalletConnect.WalletAddress, ClassWalletObject.Certificate, true);
                        _walletFileData   = string.Empty;
                        _fileSelectedPath = string.Empty;
                        invoke            = () => labelOpenFileSelected.Text = ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_LABEL_FILE_SELECTED_TEXT");
                        BeginInvoke(invoke);
                    }
                }
                catch
                {
#if WINDOWS
                    ClassFormPhase.MessageBoxInterface(
                        ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_WRONG_PASSWORD_WRITTED_CONTENT_TEXT"),
                        ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_WRONG_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                    MessageBox.Show(ClassFormPhase.WalletXiropht,
                                    ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_WRONG_PASSWORD_WRITTED_CONTENT_TEXT"),
                                    ClassTranslation.GetLanguageTextFromOrder("OPEN_WALLET_ERROR_MESSAGE_NETWORK_WRONG_PASSWORD_WRITTED_TITLE_TEXT"), MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
                }
            }).Start();
        }
예제 #2
0
        private async Task CreateWalletAsync()
        {
            if (InCreation)
            {
                ClassWalletObject.FullDisconnection(true);
                InCreation = false;
            }

            if (textBoxPathWallet.Text != "")
            {
                if (textBoxSelectWalletPassword.Text != "")
                {
                    if (await ClassWalletObject
                        .InitializationWalletConnection("", textBoxSelectWalletPassword.Text, "",
                                                        ClassWalletPhase.Create))
                    {
                        ClassWalletObject.WalletNewPassword = textBoxSelectWalletPassword.Text;
                        ClassWalletObject.ListenSeedNodeNetworkForWallet();

                        InCreation = true;
                        ClassWalletObject.WalletDataCreationPath = textBoxPathWallet.Text;

                        new Thread(async delegate()
                        {
                            Stopwatch packetSpeedCalculator = new Stopwatch();
                            packetSpeedCalculator.Start();
                            if (await ClassWalletObject.WalletConnect
                                .SendPacketWallet(ClassWalletObject.Certificate, string.Empty, false))
                            {
                                packetSpeedCalculator.Stop();
                                if (packetSpeedCalculator.ElapsedMilliseconds > 0)
                                {
                                    Thread.Sleep((int)packetSpeedCalculator.ElapsedMilliseconds);
                                }
                                if (!await ClassWalletObject
                                    .SendPacketWalletToSeedNodeNetwork(
                                        ClassWalletCommand.ClassWalletSendEnumeration.CreatePhase + "|" +
                                        textBoxSelectWalletPassword.Text))
                                {
#if WINDOWS
                                    ClassFormPhase.MessageBoxInterface(
                                        ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                                    MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht,
                                                                                 ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"));
                                    ClassFormPhase.WalletXiropht.BeginInvoke(invoke);
#endif
                                }

                                void MethodInvoker() => textBoxSelectWalletPassword.Text = "";
                                BeginInvoke((MethodInvoker)MethodInvoker);
                            }
                            else
                            {
#if WINDOWS
                                ClassFormPhase.MessageBoxInterface(
                                    ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                                MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht,
                                                                             ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"));
                                ClassFormPhase.WalletXiropht.BeginInvoke(invoke);
#endif
                            }
                        }).Start();
                    }
                }
            }
        }
예제 #3
0
        private async void buttonRestoreYourWallet_ClickAsync(object sender, EventArgs e)
        {
            string walletPath     = textBoxPathWallet.Text;
            string walletPassword = textBoxPassword.Text;
            string walletKey      = textBoxPrivateKey.Text;

            walletKey              = Regex.Replace(walletKey, @"\s+", string.Empty);
            textBoxPassword.Text   = string.Empty;
            textBoxPathWallet.Text = string.Empty;
            textBoxPrivateKey.Text = string.Empty;

            if (await ClassWalletObject.InitializationWalletConnection(string.Empty, walletPassword, string.Empty, ClassWalletPhase.Create))
            {
                ClassWalletObject.ListenSeedNodeNetworkForWallet();

                ClassWalletObject.WalletDataCreationPath = walletPath;

                new Thread(async delegate()
                {
                    Stopwatch packetSpeedCalculator = new Stopwatch();

                    packetSpeedCalculator.Start();
                    if (await ClassWalletObject.WalletConnect.SendPacketWallet(ClassWalletObject.Certificate, string.Empty, false))
                    {
                        packetSpeedCalculator.Stop();
                        if (packetSpeedCalculator.ElapsedMilliseconds > 0)
                        {
                            Thread.Sleep(1000);
                        }


                        string requestRestoreQrCodeEncrypted = null;

                        using (ClassWalletRestoreFunctions walletRestoreFunctions = new ClassWalletRestoreFunctions())
                        {
                            requestRestoreQrCodeEncrypted = walletRestoreFunctions.GenerateQRCodeKeyEncryptedRepresentation(walletKey, walletPassword);
                            if (requestRestoreQrCodeEncrypted != null)
                            {
                                ClassWalletObject.WalletNewPassword = walletPassword;
                                ClassWalletObject.WalletPrivateKeyEncryptedQRCode = walletKey;
                                if (!await ClassWalletObject.SeedNodeConnectorWallet.SendPacketToSeedNodeAsync(ClassWalletCommand.ClassWalletSendEnumeration.AskPhase + "|" + requestRestoreQrCodeEncrypted, ClassWalletObject.Certificate, false, true))
                                {
#if WINDOWS
                                    ClassFormPhase.MessageBoxInterface(ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                                    MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht,
                                                                                 ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"));
                                    ClassFormPhase.WalletXiropht.BeginInvoke(invoke);
#endif
                                }
                            }
                            else
                            {
#if WINDOWS
                                ClassFormPhase.MessageBoxInterface("Invalid private key inserted.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                                MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht, "Invalid private key inserted.");
                                ClassFormPhase.WalletXiropht.BeginInvoke(invoke);
#endif
                            }
                        }
                    }
                    else
                    {
#if WINDOWS
                        ClassFormPhase.MessageBoxInterface(
                            ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                        MethodInvoker invoke = () => MessageBox.Show(ClassFormPhase.WalletXiropht,
                                                                     ClassTranslation.GetLanguageTextFromOrder("CREATE_WALLET_ERROR_CANT_CONNECT_MESSAGE_CONTENT_TEXT"));
                        ClassFormPhase.WalletXiropht.BeginInvoke(invoke);
#endif
                    }
                }).Start();
            }
        }