Ejemplo n.º 1
0
 static AccountKeyBuilder()
 {
     eckey = new ECKeyValidator();
 }
Ejemplo n.º 2
0
        public async Task <Transaction> ValidateTransaction(object records, string key)
        {
            IEnumerable <Record> referenceRecords = null;

            if (records is JArray)
            {
                referenceRecords = recordBuilder.ValidateRecords((JArray)records);
            }
            else if (records is IEnumerable <Record> )
            {
                referenceRecords = (IEnumerable <Record>)records;
            }
            else if (records is Record)
            {
                referenceRecords = new[] { (Record)records };
            }
            else
            {
                return(null);
            }

            DateTime date = DateTime.UtcNow;

            var recordValue     = referenceRecords.Select(s => s.Value.ToString()).ToList();
            var concatenateData = Serializer.ConcatenateData(recordValue);
            var transactionHash = Serializer.ComputeHash(concatenateData.ToHexString());

            string         secret = null;
            ECKeyValidator eckey  = new ECKeyValidator();

            try
            {
                secret = File.ReadAllText("/DataChain/privKey/key.xml", UTF8Encoding.UTF8);
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
            catch (IOException)
            {
                return(null);
            }

            string sign = null;

            sign = eckey.SignData(concatenateData);

            if (!eckey.VerifyMessage(concatenateData, sign, key))
            {
                throw new InvalidTransactionException("Signature is not valid");
            }

            SignatureEvidence auth = new SignatureEvidence(new HexString(sign.ToHexString()), new HexString(key.ToHexString()));

            byte[] rawSign = SerializeSignature(auth);


            List <Transaction> tx_list     = new List <Transaction>();
            Transaction        transaction = null;

            tx_list.AddRange(await Task.WhenAll(referenceRecords.Select(async rec =>
            {
                await Task.Delay(100);
                transaction = new Transaction(date, referenceRecords, new HexString(transactionHash),
                                              new HexString(sign.ToHexString()),
                                              new HexString(key.ToHexString()));

                return(transaction);
            }
                                                                        )));

            try
            {
                await txSubscribe.AddTransactionAsync(tx_list);
            }

            catch (InvalidTransactionException)
            {
                return(null);
            }

            try
            {
                await recordBuilder.PostRecordsAsync(referenceRecords);
            }
            catch (Exception)
            {
                return(null);
            }

            return(transaction);
        }
Ejemplo n.º 3
0
 public ChainSerializer()
 {
     key       = new ECKeyValidator();
     subscribe = new TransactionRepository();
 }