Example #1
0
        /// <summary>
        /// Get Entered Password and encryp with SHA256
        /// </summary>
        /// <param name="password"></param>
        public static void GetPassword(out string password)
        {
            password = string.Empty;
            string inputPassword   = string.Empty;
            string confirmPassword = string.Empty;
            bool   shouldContinue  = true;

            do
            {
                Console.WriteLine("Plase Enter Password: "******"Incorect password. Passwords for this wallet are at least 6 symbols log");
                }
            } while (shouldContinue);

            password = CryptoHelper.GetSHA256(inputPassword);
        }
Example #2
0
        private static void CreateWallet(out Safe safe)
        {
            Network network = null;

            safe = null;
            CommonWalletHelper.SelectNetwork(out network);
            string filePath       = string.Empty;
            string password       = string.Empty;
            bool   shouldContinue = true;

            do
            {
                Console.WriteLine("Please enter valid folder file path where .json file should be saved\n");
                filePath = Console.ReadLine();
                CommonWalletHelper.CheckForSpecialCommand(filePath.ToLower());
                shouldContinue = !CommonWalletHelper.CheckDirectory(filePath);
            } while (shouldContinue);
            CreateWalletHelper.GetPassword(out password);
            Mnemonic mnemonic;

            CreateWalletHelper.CreateJsonFile(password, filePath, network, out mnemonic, out safe);
            Console.WriteLine("File Successfuly Created!\nAfter 2 second full information will be presented\n");
            _safe = safe;
            Thread.Sleep(2000);
            Console.Clear();
            CreateWalletHelper.PrintInformation(safe, filePath, mnemonic, password);
            var sha256PublicKey = CryptoHelper.GetSHA256(safe.GetBitcoinExtPubKey().ToString());

            CommonWalletHelper.AddNewRecordInWalletConfig(_config, sha256PublicKey);
        }
Example #3
0
        public static void LoadWallet(out Safe safe)
        {
            safe = null;
            string path;
            bool   @continue = true;
            string password;

            Console.WriteLine();
            RecoverWalletHelper.GetPassword(out password);
            do
            {
                Console.WriteLine("Please enter the full file path of the wallet json file:");
                path      = Console.ReadLine();
                @continue = !CommonWalletHelper.CheckDirectory(path);
            } while (@continue);
            Console.WriteLine("Please enter the name of the wallet: ");
            var name = Console.ReadLine();

            RecoverWalletHelper.LoadFromExistingWalletFile(password, string.Format("{0}\\{1}", path, name), out safe);
            _safe = safe;
            var sha256Public = CryptoHelper.GetSHA256(safe.GetBitcoinExtPubKey().ToString());

            if (!CommonWalletHelper.IsWalletSavedInConfig(_config, sha256Public))
            {
                CommonWalletHelper.AddNewRecordInWalletConfig(_config, sha256Public);
            }
        }
Example #4
0
 private static void GetConfig(out WalletConfig config)
 {
     config = null;
     if (!CommonWalletHelper.TryToOpenWalletConfig(out config))
     {
         CommonWalletHelper.CreateWalletConfigFile();
         config = new WalletConfig();
     }
 }
Example #5
0
        static void Main(string[] args)
        {
            GetConfig(out _config);
            Safe safe = null;

            FirstMessages();
            string input = string.Empty;

            while (true)
            {
                input = Console.ReadLine();
                if (input.ToLower() == "\\exit")
                {
                    Console.WriteLine("Exiting Wallet...");
                    Thread.Sleep(1000);
                    Console.Clear();
                    break;
                }
                switch (input.ToLower())
                {
                case "\\help":
                    GetCommandsInfo();
                    break;

                case "\\create":
                    CreateWallet(out safe);
                    break;

                case "\\recover":
                    RecoverWallet(out safe);
                    break;

                case "\\get-address":
                    break;

                case "\\load":
                    LoadWallet(out safe);
                    break;

                default:
                    if (!CommonWalletHelper.CheckForSpecialCommand(input))
                    {
                        Console.WriteLine("Unknow Command!\n");
                    }
                    break;
                }
            }
        }
Example #6
0
 private static void RecoverWallet(out Safe safe)
 {
     safe = null;
     try
     {
         Mnemonic mnemonic;
         string   password;
         byte     selectedWay;
         Console.WriteLine("IMPORTANT!: The wallet cannot check if the password you passed is correct", ConsoleColor.Red);
         Console.WriteLine("Recovery required valid password and mnemonic phrase");
         RecoverWalletHelper.GetPassword(out password);
         RecoverWalletHelper.GetSelectedWayOfMnemonicInput(out selectedWay);
         if (selectedWay == 0)
         {
             RecoverWalletHelper.LoadMnemonicFromFile(out mnemonic);
         }
         else
         {
             RecoverWalletHelper.LoadMnemonicFromInput(out mnemonic);
         }
         Network network;
         CommonWalletHelper.SelectNetwork(out network);
         string directoryPath;
         CommonWalletHelper.GetDirectoryPath(out directoryPath);
         RecoverWalletHelper.TryRecoverWallet(password, mnemonic, directoryPath, network, out safe);
         Console.WriteLine("Wallet successfuly recoverd!");
         _safe = safe;
         var sha256Public = CryptoHelper.GetSHA256(safe.GetBitcoinExtPubKey().ToString());
         if (!CommonWalletHelper.IsWalletSavedInConfig(_config, sha256Public))
         {
             CommonWalletHelper.AddNewRecordInWalletConfig(_config, sha256Public);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("Recovery FAILED!");
     }
 }
Example #7
0
        public static void LoadMnemonicFromFile(out Mnemonic mnemonic)
        {
            mnemonic = null;
            bool   shouldContinue = true;
            string fullTxtPath;
            string mnemonicAsStringInput = string.Empty;

            Console.WriteLine("IMPORTANT!The mnemonic phrases will be readed as they are in the file. If you make\n changes of the mnemonic phrase the recovery will fail");
            do
            {
                Console.WriteLine("\nPlease provide full file path to the .txt mnemonic file");
                fullTxtPath = Console.ReadLine();
                if (CommonWalletHelper.CheckFilePath(fullTxtPath) && Path.GetExtension(fullTxtPath) == ".txt")
                {
                    shouldContinue = false;
                    using (StreamReader reader = new StreamReader(fullTxtPath))
                    {
                        mnemonicAsStringInput = reader.ReadToEnd();
                        mnemonic = new Mnemonic(mnemonicAsStringInput);
                    }
                }
            }while (shouldContinue);
        }