Beispiel #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();
     }
 }
Beispiel #2
0
        public static bool TryParse(string s, out SecretShare share)
        {
            var match = _Parser.Match(s);

            FiniteFieldPoint point;

            if (!FiniteFieldPoint.TryParse(match, out point))
            {
                share = null;
                return(false);
            }

            if (!match.Success)
            {
                share = null;
                return(false);
            }

            var rawShareType = match.Groups["shareType"].Value;
            var shareType    = String.IsNullOrWhiteSpace(rawShareType) ? "0" : rawShareType;

            int shareTypeVal;

            if (!Int32.TryParse(shareType, NumberStyles.Integer, CultureInfo.InvariantCulture, out shareTypeVal))
            {
                share = null;
                return(false);
            }

            var checksum = match.Groups["checksum"].Value ?? "";

            share             = new SecretShare((SecretShareType)shareTypeVal, point, checksum);
            share.ParsedValue = s;
            return(true);
        }
Beispiel #3
0
        public void ParseTests()
        {
            const string toParse = "2-ef3305516d35b906812e181cb72e42967b1bc3c1791363";
            var          p       = FiniteFieldPoint.Parse(toParse);

            Assert.AreEqual(new BigInteger(2), p.X.PolynomialValue);
            var expectedY = BigInteger.Parse("0ef3305516d35b906812e181cb72e42967b1bc3c1791363", NumberStyles.HexNumber);

            Assert.AreEqual(expectedY, p.Y.PolynomialValue);
        }
Beispiel #4
0
 public SecretShare(SecretShareType shareType, FiniteFieldPoint point, string checksum = null)
 {
     ShareType = shareType;
     Point     = point;
     Checksum  = checksum;
 }