Remove Hash, Hash256, Hash160 and ScryptHash256 classes.
[NovacoinLibrary.git] / Novacoin / CKey.cs
index 6f9ce35..672f0be 100644 (file)
@@ -1,14 +1,30 @@
-\feffusing System.Collections.Generic;
-using System.Linq;
+\feff/**
+ *  Novacoin classes library
+ *  Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
 
-using Org.BouncyCastle.Crypto;
-using Org.BouncyCastle.Crypto.Parameters;
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Affero General Public License as
+ *  published by the Free Software Foundation, either version 3 of the
+ *  License, or (at your option) any later version.
+
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Affero General Public License for more details.
 
+ *  You should have received a copy of the GNU Affero General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Org.BouncyCastle.Asn1.Sec;
 using Org.BouncyCastle.Asn1.X9;
+using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Parameters;
+using Org.BouncyCastle.Math.EC;
 using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Asn1.Sec;
 
-using Org.BouncyCastle.Math.EC;
+using System.Collections.Generic;
+using System.Linq;
 
 
 namespace Novacoin
@@ -55,7 +71,7 @@ namespace Novacoin
                 return pubKeyParams;
             }
 
-            ECPoint q = new FpPoint(curve.Curve, pubKeyParams.Q.X, pubKeyParams.Q.Y, false);
+            var q = new FpPoint(curve.Curve, pubKeyParams.Q.X, pubKeyParams.Q.Y, false);
 
             return new ECPublicKeyParameters(q, domain);
         }
@@ -63,35 +79,35 @@ namespace Novacoin
         /// <summary>
         /// Does the signature matches our public key?
         /// </summary>
-        /// <param name="data">Data bytes</param>
+        /// <param name="sigHash">Data hash</param>
         /// <param name="signature">Signature bytes</param>
         /// <returns>Checking result</returns>
-        public bool VerifySignature(IEnumerable<byte> data, IEnumerable<byte> signature)
+        public bool VerifySignature(uint256 sigHash, byte[] signature)
         {
-            byte[] dataBytes = data.ToArray();
-
-            ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA");
+            var signer = SignerUtilities.GetSigner("NONEwithECDSA");
             signer.Init(false, _Public);
-            signer.BlockUpdate(dataBytes, 0, dataBytes.Length);
+            signer.BlockUpdate(sigHash, 0, sigHash.Size);
 
-            return signer.VerifySignature(signature.ToArray());
+            return signer.VerifySignature(signature);
         }
 
         /// <summary>
         /// Calculate Hash160 and create new CKeyID instance.
         /// </summary>
         /// <returns>New key ID</returns>
-        public CKeyID GetKeyID()
+        public CKeyID KeyID
         {
-            return new CKeyID(Hash160.Compute160(Public));
+            get { return new CKeyID(CryptoUtils.ComputeHash160(_Public.Q.GetEncoded())); }
         }
 
         /// <summary>
-        /// Public part of key pair
+        /// Is this a compressed public key?
         /// </summary>
-        public IEnumerable<byte> Public
+        /// <returns></returns>
+        public bool IsCompressed
         {
-            get { return _Public.Q.GetEncoded(); }
+            get { return _Public.Q.IsCompressed; }
         }
+
     }
 }