Exemplo n.º 1
0
        public static string GetHash(string timeStamp, string lastHash, string data, long nonce, long difficulty)
        {
            string dataToHash = timeStamp + lastHash + data + nonce + difficulty;
            string hash       = Convert.ToBase64String(ChainUtility.Hash(dataToHash));

            return(hash);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Signs a transaction to be sent
 /// 1. Build a transaction input
 /// 2. Generate the hash of the TxOutputs for the transaction
 /// 3. Sign the hash generated with the wallet's private key
 /// </summary>
 /// <param name="transaction"></param>
 /// <param name="senderWallet"></param>
 /// <returns></returns>
 public void SignTransaction(Wallet senderWallet)
 {
     UgoChain.Features.Wallet.TxInput txInput = new UgoChain.Features.Wallet.TxInput();
     byte[] hash = ChainUtility.Hash(JsonConvert.SerializeObject(TxOutputs));
     txInput.TimeStamp = Helper.ConvertToUnixTimeStamp(DateTime.Now).ToString();
     txInput.Address   = senderWallet.PublicKey.Key;
     txInput.Amount    = senderWallet.Balance;
     txInput.Signature = senderWallet.SignHash(hash);
     Input             = txInput;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Veify signature using TxInput data-Note the TxInput is build from the wallet object
 /// </summary>
 /// <returns></returns>
 public bool VerifyTransaction()
 {
     byte[] publicKey        = Convert.FromBase64String(Input.Address);
     byte[] dataHashToVerify = ChainUtility.Hash(JsonConvert.SerializeObject(TxOutputs));
     return(ChainUtility.VerifySignature(publicKey, Input.Signature, dataHashToVerify));
 }