private static void GeneratePublicPrivateKeys()
        {
            // Generate keys for signing.
            var    mnemonicForSigningKey = new Mnemonic(Wordlist.English, WordCount.Twelve);
            PubKey signingPubKey         = mnemonicForSigningKey.DeriveExtKey().PrivateKey.PubKey;

            // Generate keys for migning.
            var tool = new KeyTool(new DataFolder(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)));
            Key key  = tool.GeneratePrivateKey();

            string savePath = tool.GetPrivateKeySavePath();

            tool.SavePrivateKey(key);
            PubKey miningPubKey = key.PubKey;

            Console.WriteLine($"-----------------------------------------------------------------------------");
            Console.WriteLine($"-- Please give the following 2 public keys to the federation administrator --");
            Console.WriteLine($"-----------------------------------------------------------------------------");
            Console.WriteLine($"1. Your signing pubkey: {Encoders.Hex.EncodeData(signingPubKey.ToBytes(false))}");
            Console.WriteLine($"2. Your mining pubkey: {Encoders.Hex.EncodeData(miningPubKey.ToBytes(false))}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"------------------------------------------------------------------------------------------");
            Console.WriteLine($"-- Please keep the following 12 words for yourself and note them down in a secure place --");
            Console.WriteLine($"------------------------------------------------------------------------------------------");
            Console.WriteLine($"Your signing mnemonic: {string.Join(" ", mnemonicForSigningKey.Words)}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"-- Please save the following file in a secure place, you'll need it when the federation has been created. --");
            Console.WriteLine($"------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"File path: {savePath}");
            Console.WriteLine(Environment.NewLine);
        }
Beispiel #2
0
        public CoreNode CreatePoANode(PoANetwork network, Key key)
        {
            string   dataFolder = this.GetNextDataFolderName();
            CoreNode node       = this.CreateNode(new PoANodeRunner(dataFolder, network, this.TimeProvider), "poa.conf");

            var settings = new NodeSettings(network, args: new string[] { "-conf=poa.conf", "-datadir=" + dataFolder });
            var tool     = new KeyTool(settings.DataFolder);

            tool.SavePrivateKey(key);

            return(node);
        }
Beispiel #3
0
        public CoreNode CreateWhitelistedContractPoANode(SmartContractsPoARegTest network, int nodeIndex)
        {
            string dataFolder = this.GetNextDataFolderName();

            CoreNode node     = this.CreateNode(new WhitelistedContractPoARunner(dataFolder, network, this.TimeProvider), "poa.conf");
            var      settings = new NodeSettings(network, args: new string[] { "-conf=poa.conf", "-datadir=" + dataFolder });

            var tool = new KeyTool(settings.DataFolder);

            tool.SavePrivateKey(network.FederationKeys[nodeIndex]);
            return(node);
        }
Beispiel #4
0
        private bool CreateFederationKey()
        {
            var keyFilePath = Path.Combine(this.rootDataDir, this.sidechainNetwork.RootFolderName, this.sidechainNetwork.Name, KeyTool.KeyFileDefaultName);

            if (File.Exists(keyFilePath))
            {
                Console.WriteLine($"Your masternode public key file already exists.");
                return(true);
            }

            Console.Clear();
            Console.WriteLine($"Your masternode public key will now be generated.");

            string publicKeyPassphrase;

            do
            {
                Console.WriteLine($"Please enter a passphrase (this can be anything, but please write it down):");
                publicKeyPassphrase = Console.ReadLine();

                if (!string.IsNullOrEmpty(publicKeyPassphrase))
                {
                    break;
                }

                Console.WriteLine("ERROR: Please ensure that you enter a valid passphrase.");
            } while (true);



            // Generate keys for mining.
            var tool = new KeyTool(keyFilePath);

            Key key = tool.GeneratePrivateKey();

            string savePath = tool.GetPrivateKeySavePath();

            tool.SavePrivateKey(key);
            PubKey miningPubKey = key.PubKey;

            Console.WriteLine($"Your Masternode Public Key (PubKey) is: {Encoders.Hex.EncodeData(miningPubKey.ToBytes(false))}");

            if (publicKeyPassphrase != null)
            {
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine($"Your passphrase: {publicKeyPassphrase}");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"It has been saved in the root Cirrus data folder: {savePath}");
            Console.WriteLine($"Please ensure that you take a backup of this file.");
            return(true);
        }
Beispiel #5
0
        public CoreNode CreateSidechainNode(Network network, Key key)
        {
            var      agentName  = $"sidechain{Interlocked.Increment(ref agentCount)}";
            string   dataFolder = this.GetNextDataFolderName(agentName);
            CoreNode node       = this.CreateNode(new SidechainNodeRunner(dataFolder, agentName, network, this.TimeProvider), "poa.conf");

            var settings = new NodeSettings(network, args: new string[] { "-conf=poa.conf", "-datadir=" + dataFolder });
            var tool     = new KeyTool(settings.DataFolder);

            tool.SavePrivateKey(key);

            return(node);
        }
        private static void GeneratePublicPrivateKeys(string passphrase, string keyPath, bool isMultiSigOutput = true)
        {
            // Generate keys for signing.
            var    mnemonicForSigningKey = new Mnemonic(Wordlist.English, WordCount.Twelve);
            PubKey signingPubKey         = mnemonicForSigningKey.DeriveExtKey(passphrase).PrivateKey.PubKey;

            // Generate keys for migning.
            var tool = new KeyTool(keyPath);

            Key key = tool.GeneratePrivateKey();

            string savePath = tool.GetPrivateKeySavePath();

            tool.SavePrivateKey(key);
            PubKey miningPubKey = key.PubKey;

            Console.WriteLine($"Your Masternode Public Key: {Encoders.Hex.EncodeData(miningPubKey.ToBytes(false))}");
            Console.WriteLine($"-----------------------------------------------------------------------------");

            if (isMultiSigOutput)
            {
                Console.WriteLine(
                    $"Your Masternode Signing Key: {Encoders.Hex.EncodeData(signingPubKey.ToBytes(false))}");
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine(
                    $"------------------------------------------------------------------------------------------");
                Console.WriteLine(
                    $"-- Please keep the following 12 words for yourself and note them down in a secure place --");
                Console.WriteLine(
                    $"------------------------------------------------------------------------------------------");
                Console.WriteLine($"Your signing mnemonic: {string.Join(" ", mnemonicForSigningKey.Words)}");
            }

            if (passphrase != null)
            {
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine($"Your passphrase: {passphrase}");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"-- Please save the following file in a secure place, you'll need it when the federation has been created. --");
            Console.WriteLine($"------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"File path: {savePath}");
            Console.WriteLine(Environment.NewLine);
        }
Beispiel #7
0
        private static void GenerateFederationKey(DataFolder dataFolder)
        {
            var tool = new KeyTool(dataFolder);
            Key key  = tool.GeneratePrivateKey();

            string savePath = tool.GetPrivateKeySavePath();

            tool.SavePrivateKey(key);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"Federation key pair was generated and saved to {savePath}.");
            stringBuilder.AppendLine("Make sure to back it up!");
            stringBuilder.AppendLine($"Your public key is {key.PubKey}.");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("Press eny key to exit...");

            Console.WriteLine(stringBuilder.ToString());

            Console.ReadKey();
        }
Beispiel #8
0
        private static void GenerateServiceNodeKey(NodeSettings nodeSettings)
        {
            var tool = new KeyTool(nodeSettings.DataFolder);
            Key key  = tool.GeneratePrivateKey();

            string savePath = tool.GetPrivateKeySavePath();

            tool.SavePrivateKey(key);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"ServiceNode key pair was generated and saved to {savePath}.");
            stringBuilder.AppendLine("Make sure to back it up!");
            stringBuilder.AppendLine($"Your public key is {key.PubKey}.");
            stringBuilder.AppendLine();
            stringBuilder.AppendLine("You can now restart the node to use the key pair. If you need to re-generate add generateKeyPair to settings");
            stringBuilder.AppendLine("Press eny key to exit...");

            Console.WriteLine(stringBuilder.ToString());

            Console.ReadKey();
        }