Exemple #1
0
 public void AddRequest(BlockConsensusRequest request, MinerWallet wallet)
 {
     lock (SyncRoot)
     {
         if (request.PrevHash != PrevHash)
         {
             return;
         }
         if (request.Miner == my_pubkey)
         {
             return;
         }
         if (NoncePieces.ContainsKey(request.Miner))
         {
             return;
         }
         byte[] aeskey = wallet.GetAesKey(request.Miner);
         byte[] piece  = request.NoncePieces[my_pubkey];
         using (AesManaged aes = new AesManaged())
             using (ICryptoTransform decryptor = aes.CreateDecryptor(aeskey, request.IV))
             {
                 piece = decryptor.TransformFinalBlock(piece, 0, piece.Length);
             }
         Array.Clear(aeskey, 0, aeskey.Length);
         NoncePieces.Add(request.Miner, new List <FiniteFieldPoint>());
         NoncePieces[request.Miner].Add(FiniteFieldPoint.DeserializeFrom(piece));
         NonceHashes.Add(request.Miner, request.NonceHash);
         TransactionHashes.UnionWith(request.TransactionHashes);
         action_request.CheckPredicate();
     }
 }
Exemple #2
0
 //TODO: 目前没有想到其它安全的方法来保存密码
 //所以只能暂时手动输入,但如此一来就不能以服务的方式启动了
 //未来再想想其它办法,比如采用智能卡之类的
 private bool OnOpenWalletCommand(string[] args)
 {
     if (args.Length < 3)
     {
         Console.WriteLine("error");
         return(true);
     }
     using (SecureString password = ReadSecureString("password"))
     {
         if (password.Length == 0)
         {
             Console.WriteLine("cancelled");
             return(true);
         }
         try
         {
             wallet = MinerWallet.Open(args[2], password);
         }
         catch
         {
             Console.WriteLine($"failed to open file \"{args[2]}\"");
         }
     }
     return(true);
 }
Exemple #3
0
 public BlockConsensusRequest CreateRequest(MinerWallet wallet)
 {
     lock (SyncRoot)
     {
         if (!Valid)
         {
             throw new InvalidOperationException();
         }
         if (_request == null)
         {
             _request = new BlockConsensusRequest
             {
                 PrevHash          = PrevHash,
                 Miner             = my_pubkey,
                 IV                = new byte[16],
                 NonceHash         = NonceHashes[my_pubkey],
                 TransactionHashes = TransactionHashes.ToArray()
             };
             Random rand = new Random();
             rand.NextBytes(_request.IV);
             SplitSecret secret = SecretSharing.Split(Nonces[my_pubkey].ToArray(), (Miners.Length - 1) / 2 + 1);
             for (int i = 0; i < Miners.Length; i++)
             {
                 if (Miners[i].Equals(my_pubkey))
                 {
                     continue;
                 }
                 byte[] aeskey = wallet.GetAesKey(Miners[i]);
                 byte[] piece  = secret.GetShare(i + 1).ToArray();
                 using (AesManaged aes = new AesManaged())
                     using (ICryptoTransform encryptor = aes.CreateEncryptor(aeskey, _request.IV))
                     {
                         piece = encryptor.TransformFinalBlock(piece, 0, piece.Length);
                     }
                 Array.Clear(aeskey, 0, aeskey.Length);
                 _request.NoncePieces.Add(Miners[i], piece);
             }
         }
         return(_request);
     }
 }
Exemple #4
0
        //TODO: 目前没有想到其它安全的方法来保存密码
        //所以只能暂时手动输入,但如此一来就不能以服务的方式启动了
        //未来再想想其它办法,比如采用智能卡之类的
        private async void OnOpenWalletCommand(string path)
        {
            SecureString password = ReadSecureString("password");

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return;
            }
            try
            {
                wallet = MinerWallet.Open(path, password);
            }
            catch
            {
                Console.WriteLine($"failed to open file \"{path}\"");
                return;
            }
            //TODO: 等待连接到其它节点
            context = new BlockConsensusContext(wallet.PublicKey);
            await SendConsensusRequestAsync();
        }
Exemple #5
0
 private bool OnCreateWalletCommand(string[] args)
 {
     if (args.Length < 3)
     {
         Console.WriteLine("error");
         return(true);
     }
     using (SecureString password = ReadSecureString("password"))
         using (SecureString password2 = ReadSecureString("password"))
         {
             if (!password.CompareTo(password2))
             {
                 Console.WriteLine("error");
                 return(true);
             }
             wallet = MinerWallet.Create(args[2], password);
             foreach (Account account in wallet.GetAccounts())
             {
                 Console.WriteLine(account.PublicKey.EncodePoint(true).ToHexString());
             }
         }
     return(true);
 }