Пример #1
0
        static void GetBalances(Balances balances) ///Gets the Balance for 5 YottaChain Addresses
        {
            try
            {
                List <string> addresses  = new List <string>(); //List with all addresses in the Wallet
                WalletData    walletData = new WalletData();

                if (!File.Exists($@"Wallets/{openedWalletName}.json"))
                {
                    Print("Write your 5 Addresses:");
                    for (int i = 0; i < 5; i++)
                    {
                        string address = ReadLine();
                        addresses.Add(address);
                    }
                }

                else
                {
                    using (StreamReader r = new StreamReader($@"Wallets/{openedWalletName}.json"))
                    {
                        string json = r.ReadToEnd();
                        walletData = JsonConvert.DeserializeObject <WalletData>(json);
                        for (int i = 0; i < 5; i++)
                        {
                            addresses.Add(walletData.Addresses[i]);
                        }
                    }
                }
                WriteLine();
                for (int i = 0; i < 5; i++)
                {
                    try
                    {
                        Print($"\"{addresses[i]}\" : {balances.AddressBalances[addresses[i]]}");
                    }
                    catch
                    {
                        Print($"\"{addresses[i]}\" : 0");
                    }
                }
            }
            catch
            {
                Print("ERROR! COULD NOT GET BALANCES!");
            }
        }
Пример #2
0
 static bool SaveToJSON(string walletName, string password, List <string> privateKeys, List <string> publicKeys, List <string> pubKeysCompressed, List <string> addresses) ///Saves Wallet to an Encrypted JSON file in a ZIP Folder
 {
     if (!Directory.Exists($@"Wallets/{walletName}"))
     {
         Directory.CreateDirectory($@"Wallets/{walletName}");
         WalletData walletData = new WalletData(walletName, password, privateKeys, publicKeys, pubKeysCompressed, addresses);
         string     json       = JsonConvert.SerializeObject(walletData, Formatting.Indented);
         File.WriteAllText($@"Wallets/{walletName}/walletData.json", json);
         CreateSample($@"Wallets/{walletName}.zip", password, $@"Wallets/{walletName}");
         Directory.Delete($@"Wallets/{walletName}", true);
         Print($"Wallet saved to Wallets/{walletName}.zip/walletData.json");
         Print("Extract with your Password.");
         return(true);
     }
     Print($"ERROR! WALLET \"{walletName}\" ALREADY EXISTS!");
     return(false);
 }
Пример #3
0
 static bool LoadWallet() ///Loads an existing wallet
 {
     try
     {
         WalletData walletData = new WalletData();
         Write(">>> Place .json file in \"Wallets/\" with the name of the Wallet on it!");
         ReadKey();
         WriteLine();
         Write(">>> Enter Wallet Name: ");
         string walletName = ReadLine();
         if (!File.Exists($@"Wallets/{walletName}.json"))
         {
             Print($"ERROR! THERE IS NO WALLET NAMED \"{walletName.ToUpper()}\"!");
             return(false);
         }
         Write($">>> Enter Wallet \"{walletName}\"'s Password: "******"Wallets/{walletName}.json"))
         {
             string json = r.ReadToEnd();
             walletData = JsonConvert.DeserializeObject <WalletData>(json);
         }
         if (!(walletData.PasswordHash == GetPasswordHash(password)))
         {
             Print("ERROR! PASSWORD IS NOT CORRECT!");
             return(false);
         }
         openedWalletName = walletName;
         return(true);
     }
     catch
     {
         Print("ERROR! COULD NOT LOAD WALLET!");
         return(false);
     }
 }
        static bool CreateWallet() ///Creates Account with its Private Keys, Public Keys and Addresses
        {
            Write(">>> Type Wallet Name: ");
            string walletName = ReadLine();

            if (File.Exists($@"Wallets/{walletName}.zip") || File.Exists($@"Wallets/{walletName}.json"))
            {
                Print($"ERROR! WALLET \"{walletName.ToUpper()}\" ALREADY EXISTS!");
                return(false);
            }
            Write(">>> Type Wallet Password ");
            string password = GetHiddenConsoleInput();

            WriteLine();
            Write(">>> Password Confirmation ");
            string pwConfirm = GetHiddenConsoleInput();

            WriteLine();
            if (password == pwConfirm)
            {
                try
                {
                    List <byte[]> privateKeys = new List <byte[]>();       //List with all Private Keys in Byte Type
                    List <byte[]> publicKeys  = new List <byte[]>();       //List with all Public Keys in Byte Type

                    List <string> privateKeysString = new List <string>(); //List with all Private Keys
                    List <string> publicKeysString  = new List <string>(); //List with all Public Keys
                    List <string> pubKeysCompressed = new List <string>(); //List of Compressed Public Keys
                    List <string> addresses         = new List <string>(); //List of Addresses extracted from Compressed Public Keys

                    try
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Byte[] privKey = GenerateRandomBytes();
                            privateKeys.Add(privKey);
                        }
                    }
                    catch
                    {
                        throw new ArgumentException("COULD NOT GENERATE PRIVATE KEYS!");
                    }

                    try
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Byte[] pubKey = Secp256K1Manager.GetPublicKey(privateKeys[i], false);
                            publicKeys.Add(pubKey);
                        }
                    }
                    catch
                    {
                        throw new ArgumentException("COULD NOT RECOVER PUBLIC KEYS!");
                    }

                    for (int i = 0; i < 5; i++)
                    {
                        string privKeyString = GeneratePrivateKey(privateKeys[i]).ToLower();
                        string pubKeyString  = string.Join("", BitConverter.ToString(publicKeys[i]).Replace("-", "").Skip(2)).ToLower();
                        privateKeysString.Add(privKeyString);
                        publicKeysString.Add(pubKeyString);
                    }

                    try
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            string pubKeyCompressed = GetPublicKeyCompressed(publicKeysString[i]).ToLower();
                            string address          = RipeMDHash(pubKeyCompressed);
                            pubKeysCompressed.Add(pubKeyCompressed);
                            addresses.Add(address);
                        }
                    }
                    catch
                    {
                        throw new ArgumentException("COULD NOT COMPRESS PUBLIC KEYS!");
                    }
                    WriteLine("--------------- WALLET INFO ---------------");
                    WriteLine();
                    WriteLine("--------------- Private Keys --------------\n" + string.Join("\n", privateKeysString));
                    WriteLine("--------------- Public Keys ---------------\n" + string.Join("\n", publicKeysString));
                    WriteLine("---------- PublicKeys Compressed ----------\n" + string.Join("\n", pubKeysCompressed));
                    WriteLine("---------------- Addresses ----------------\n" + string.Join("\n", addresses));
                    WriteLine();
                    WriteLine("Write down and keep in SECURE place your private keys. Only through them you can access your coins!");
                    WriteLine();
                    Write(">>> Do you want to Save your Wallet to a JSON file? [Y/N]: ");
                    bool saveWallet = ReadLine().ToLower() == "y";
                    if (saveWallet)
                    {
                        SaveToJSON(walletName, password, privateKeysString, publicKeysString, pubKeysCompressed, addresses);
                    }
                    else
                    {
                        walletData = new WalletData(walletName, password, privateKeysString, publicKeysString, pubKeysCompressed, addresses);
                    }
                }
                catch (Exception e)
                {
                    Print($"ERROR! {e.Message}");
                    return(false);
                }
                openedWalletName = walletName;
                return(true);
            }
            else
            {
                Print($"ERROR! PASSWORDS DO NOT MATCH!");
                return(false);
            }
        }