public static void ReceivingAndMaekingManyTransfer_SouldHaveValidTransactionChain() { //Arrange var goofy = new Goofy(); var person1 = new Person(); var person2 = new Person(); var person3 = new Person(); Global.GoofyPk = goofy.PublicKey; var trans1 = goofy.CreateCoin(person1.PublicKey); //Action person1.AddTransaction(trans1); var trans2 = person1.PayTo(person2.PublicKey); person2.AddTransaction(trans2); var trans3 = person2.PayTo(person3.PublicKey); //Assert try { trans3.CheckTransaction(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void DoubleSpendAttach_SouldHaveValidTransactionChain() { //Arrange var goofy = new Goofy(); var person1 = new Signature(256); var person2 = new Person(); var person3 = new Person(); Global.GoofyPk = goofy.PublicKey; var trans1 = goofy.CreateCoin(person1.PublicKey); //Action var sgndTrans1 = person1.SignMessage(trans1); var trans2 = trans1.Payto(sgndTrans1, person2.PublicKey); var trans3 = trans1.Payto(sgndTrans1, person3.PublicKey); //Assert try { trans2.CheckTransaction(); trans3.CheckTransaction(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void ReceivingAndMaekingTransfer_SouldHaveValidTransactionChain() { //Arrange var goofy = new Goofy(); var person1 = new Signature(256); var person2 = new Person(); Global.GoofyPk = goofy.PublicKey; var trans1 = goofy.CreateCoin(person1.PublicKey); //Action var sgndTrans1 = person1.SignMessage(trans1); var trans2 = trans1.Payto(sgndTrans1, person2.PublicKey); //Assert try { //trans2.isValidTransaction(); //previous.receiverPk == previousTransSignedByMe.PublicKey; trans2.CheckTransaction(); if (!sgndTrans1.isValidSignedMsg(trans1)) throw new Exception("The signature of the previous transaction and his pk are invalid"); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { Counter.Coin = 0; Counter.Signature = 0; Counter.Transaction = 0; var goofy = new Goofy(); var alice = new Person(); var bob = new Person(); var clark = new Person(); //goofy transaction var goofyTrans = goofy.CreateCoin(alice.PublicKey); //alice transaction alice.AddTransaction(goofyTrans); var aliceTrans = alice.PayTo(bob.PublicKey); //bob transaction bob.AddTransaction(aliceTrans); var bobTrans = bob.PayTo(clark.PublicKey); //clark transaction clark.AddTransaction(bobTrans); Tests.GoofyCreateAndTansferCoin_SouldHaveValidCoin(); Tests.ReceivingAndMaekingTransfer_SouldHaveValidTransactionChain(); Tests.ReceivingAndMaekingManyTransfer_SouldHaveValidTransactionChain(); Tests.DoubleSpendAttach_SouldHaveValidTransactionChain(); //byte[] publickey; //byte[] data; //byte[] dataHash; //byte[] signature; //byte[] signature2; //using (var dsa = new ECDsaCng(256)) //{ // dsa.HashAlgorithm = CngAlgorithm.Sha256; // publickey = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob); // data = new byte[] { 21, 5, 8, 12, 207 }; // dataHash = new SHA1Managed().ComputeHash(data); // //dataHash = new SHA256Cng().ComputeHash(data); // signature = dsa.SignData(data); // signature2 = dsa.SignHash(dataHash); //} //Console.WriteLine(signature.Length); //Console.WriteLine(Convert.ToBase64String(signature)); //using (var dsa = new ECDsaCng(CngKey.Import(publickey, CngKeyBlobFormat.EccPublicBlob))) //{ // dsa.HashAlgorithm = CngAlgorithm.Sha256; // if (dsa.VerifyData(data, signature)) // Console.WriteLine("Data is good"); // else // Console.WriteLine("Data is bad"); // if (dsa.VerifyHash(dataHash, signature2)) // Console.WriteLine("Data is good"); // else // Console.WriteLine("Data is bad"); //} //Console.ReadKey(); //String a = "Hello wrold!"; //Object b = a; //byte[] c; //BinaryFormatter bf = new BinaryFormatter(); //using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) //{ // bf.Serialize(ms, b); // c = ms.ToArray(); //} //String d; //using (var memStream = new System.IO.MemoryStream()) //{ // var binForm = new BinaryFormatter(); // memStream.Write(c, 0, c.Length); // memStream.Seek(0, System.IO.SeekOrigin.Begin); // var obj = binForm.Deserialize(memStream); // d = (String) obj; //} Console.ReadKey(); //Org.BouncyCastle.Asn1.X9.X9ECParameters ecp = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1"); //ECDomainParameters params = new ECDomainParameters(ecp.Curve, ecp.G, ecp.N, ecp.H); //ECPublicKeySpec pubKeySpec = new ECPublicKeySpec( //ecp.curve.decodePoint(Hex.decode("045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5")), // Q //params); //PublicKey pubKey = f.generatePublic(pubKeySpec); //var signer = SignerUtilities.GetSigner("ECDSA"); // possibly similar to SHA-1withECDSA //signer.Init(false, pubKey); //signer.BlockUpdate(plainTextAsBytes, 0, plainTextAsBytes.Length); //return signer.VerifySignature(signature); }