Exemple #1
0
        private static PrivateKey GetPrivateKey(string msg)
        {
            while (true)
            {
                YellowMsg.Write(msg);
                string input = Console.ReadLine();

                if (input.Length != 64)
                {
                    RedMsg.WriteLine("Invalid private key, should be 64 "
                                     + "characters long! Try again.\n");

                    continue;
                }

                if (!input.IsHex())
                {
                    RedMsg.WriteLine("Invalid private key, is not a valid "
                                     + "hexadecimal string!");

                    continue;
                }

                var p = new PrivateKey(Encoding.HexStringToByteArray(input));

                if (!KeyOps.IsValidKey(p))
                {
                    RedMsg.WriteLine("Invalid private key, is not a valid "
                                     + "ED25519 key!");
                }

                return(p);
            }
        }
Exemple #2
0
        public static (bool exit, WalletBackend wallet) SelectionScreen()
        {
            while (true)
            {
                LaunchAction action = GetAction();

                if (action == LaunchAction.Exit)
                {
                    return(true, null);
                }

                /* Get the walletbackend, or an error. On error, return
                 * to selection screen. */
                switch (LaunchWallet.HandleAction(action))
                {
                case ILeft <Error> error:
                {
                    RedMsg.WriteLine(
                        error.Value.errorMessage
                        );

                    YellowMsg.WriteLine("Returning to selection screen.\n");

                    continue;
                }

                case IRight <WalletBackend> wallet:
                {
                    return(false, wallet.Value);
                }
                }
            }
        }
Exemple #3
0
        private static PrivateKeys GetPrivateKeysFromSeed()
        {
            while (true)
            {
                YellowMsg.Write("Mnemonic seed (25 words): ");
                string input = Console.ReadLine();

                switch (Mnemonics.MnemonicToPrivateKey(input))
                {
                case ILeft <Error> error:
                {
                    RedMsg.WriteLine(error.Value.errorMessage);
                    Console.WriteLine("Try again.\n");
                    continue;
                }

                case IRight <PrivateKey> key:
                {
                    var privateSpendKey = key.Value;

                    var privateViewKey
                        = KeyOps.GenerateDeterministicKeys(privateSpendKey)
                          .privateKey;

                    return(new PrivateKeys(privateSpendKey, privateViewKey));
                }
                }
            }
        }
Exemple #4
0
        private static string GetAddress()
        {
            while (true)
            {
                YellowMsg.Write($"Public {Globals.ticker} address: ");

                string input = Console.ReadLine();

                /* Try and parse into public keys to see if it's valid, don't
                 * need the keys so ignore the result. */
                switch (Addresses.KeysFromAddress(input))
                {
                case ILeft <Error> error:
                {
                    RedMsg.WriteLine(error.Value.errorMessage + "\n");
                    continue;
                }

                default:
                {
                    return(input);
                }
                }
            }
        }
        private static void ChangePassword(WalletBackend wallet)
        {
            Utilities.ConfirmPassword(wallet);

            string newPassword;

            while (true)
            {
                YellowMsg.Write("Enter your new password: "******"Confirm your new password: "******"Passwords do not match! Try again.\n");
                    continue;
                }

                break;
            }

            wallet.password = newPassword;

            wallet.Save();

            GreenMsg.WriteLine("\nPassword successfully updated!");
        }
        public static void ConfirmPassword(WalletBackend wallet)
        {
            while (true)
            {
                YellowMsg.Write("Confirm your current password: "******"Incorrect password! Try again.\n");
                    continue;
                }

                return;
            }
        }
Exemple #7
0
        /* Get the filename to use for a new wallet */
        private static string GetNewWalletName()
        {
            while (true)
            {
                YellowMsg.Write(
                    "What filename would you like to give your new wallet?: "
                    );

                string filename = Console.ReadLine();

                string appended = filename + ".wallet";

                if (string.IsNullOrWhiteSpace(filename))
                {
                    RedMsg.WriteLine(
                        "Wallet name cannot be empty! Try again.\n"
                        );

                    continue;
                }

                if (GeneralUtilities.FilenameInUse(filename) ||
                    GeneralUtilities.FilenameInUse(appended))
                {
                    RedMsg.Write("A file with the name ");
                    YellowMsg.Write(filename);
                    RedMsg.Write(" or ");
                    YellowMsg.Write(appended);
                    RedMsg.WriteLine(" already exists! Try again.\n");
                }
                /* If the file already ends with .wallet, return it. */
                else if (filename.EndsWith(".wallet"))
                {
                    return(filename);
                }
                /* Else, append .wallet to the filename */
                else
                {
                    return(appended);
                }
            }
        }
Exemple #8
0
        /* Get the filename of an already existing wallet */
        private static string GetExistingWalletName()
        {
            while (true)
            {
                YellowMsg.Write(
                    "What wallet filename would you like to open?: "
                    );

                string filename = Console.ReadLine();

                string appended = filename + ".wallet";

                if (string.IsNullOrWhiteSpace(filename))
                {
                    RedMsg.WriteLine("Wallet name cannot be empty! Try again.");
                    continue;
                }

                if (File.Exists(filename))
                {
                    return(filename);
                }
                /* Automatically add the .wallet extension for users */
                else if (File.Exists(appended))
                {
                    return(appended);
                }
                else
                {
                    RedMsg.Write("A file with the name ");
                    YellowMsg.Write(filename);
                    RedMsg.Write(" or ");
                    YellowMsg.Write(appended);
                    RedMsg.WriteLine(" doesn't exist!");
                    Console.WriteLine(
                        "Ensure you entered your wallet name correctly.\n"
                        );
                }
            }
        }
Exemple #9
0
        /* Get the password for a new wallet file (Confirm the password) */
        private static string GetNewWalletPassword()
        {
            while (true)
            {
                YellowMsg.Write("Give your new wallet a password: "******"Confirm your new password: "******"Passwords do not match! Try again.\n");
                }
                else
                {
                    return(firstPassword);
                }
            }
        }
Exemple #10
0
        public static void PrintCommands(IEnumerable <Command> commands,

                                         /* The offset to print the command
                                          * numbers at, e.g. command 1, 2, 3
                                          * we need an offset if we're
                                          * printing the advanced commands */
                                         int offset = 0)
        {
            int i = 1 + offset;

            Console.WriteLine();

            /* Print out each command name, description, and possible
             * number accessor */
            foreach (var command in commands)
            {
                YellowMsg.Write($" {i}\t");
                GreenMsg.Write(command.commandName.PadRight(25));
                Console.WriteLine(command.description);
                i++;
            }

            Console.WriteLine();
        }
Exemple #11
0
        /* printableCommands = the commands to print on bad input.
         * availableCommands = the commands that the inputted string is
         *                     checked against.
         *
         * For example, we print basic commands, but can input both basic
         * and advanced commands */
        private static string ParseCommand(
            IEnumerable <Command> printableCommands,
            IEnumerable <Command> availableCommands,
            string prompt)
        {
            string selection = null;

            while (true)
            {
                /* Write the prompt message */
                YellowMsg.Write(prompt);

                selection = Console.ReadLine().ToLower();

                /* \n == no-op */
                if (selection == "")
                {
                    continue;
                }

                /* Check if they entered a command or an number */
                if (int.TryParse(selection, out int selectionNum))
                {
                    /* We print 1, 2, 3, 4 etc to be user friendly but we want
                     * to access it with 0 indexing */
                    selectionNum--;

                    if (selectionNum < 0 ||
                        selectionNum >= availableCommands.Count())
                    {
                        RedMsg.Write("Bad input, expected a command " +
                                     "name, or number from ");
                        YellowMsg.Write("1 ");
                        RedMsg.Write("to ");
                        YellowMsg.WriteLine(availableCommands.Count().ToString());

                        PrintCommands(printableCommands);

                        continue;
                    }

                    /* Set the selection to the command name chosen via
                     * the previously printed numbers */
                    selection = availableCommands.ElementAt(selectionNum)
                                .commandName;
                }
                else
                {
                    /* Does the inputted command exist? */
                    if (!availableCommands.Any(c => c.commandName == selection))
                    {
                        Console.Write("Unknown command: ");
                        RedMsg.Write($"{selection}\n");

                        PrintCommands(printableCommands);

                        continue;
                    }
                }

                return(selection);
            }
        }
Exemple #12
0
 /* Get the password for an already existing wallet (no confirmation) */
 private static string GetWalletPassword()
 {
     YellowMsg.Write("Enter your wallet password: ");
     return(Console.ReadLine());
 }
 private static void Save(WalletBackend wallet)
 {
     YellowMsg.WriteLine("Saving...");
     wallet.Save();
     YellowMsg.WriteLine("Saved!");
 }
 private static bool Exit(WalletBackend wallet)
 {
     YellowMsg.WriteLine("Saving wallet and shutting down...");
     wallet.Save();
     return(true);
 }
Exemple #15
0
 /* Writes out the coin name, version, and wallet name */
 private static void StartupMsg()
 {
     YellowMsg.WriteLine($"{Globals.coinName} {Globals.version} "
                         + $"{Globals.CLIWalletName}");
 }