Add license header.
[NovacoinLibrary.git] / Novacoin / CKey.cs
index 3fe695e..a24d6c8 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
@@ -63,16 +79,14 @@ 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(Hash sigHash, IEnumerable<byte> signature)
         {
-            byte[] dataBytes = data.ToArray();
-
-            ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA");
+            ISigner signer = SignerUtilities.GetSigner("NONEwithECDSA");
             signer.Init(false, _Public);
-            signer.BlockUpdate(dataBytes, 0, dataBytes.Length);
+            signer.BlockUpdate(sigHash.hashBytes, 0, sigHash.hashSize);
 
             return signer.VerifySignature(signature.ToArray());
         }
@@ -81,15 +95,15 @@ namespace Novacoin
         /// 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(Hash160.Compute160(PublicBytes)); }
         }
 
         /// <summary>
-        /// Public part of key pair
+        /// PublicBytes part of key pair
         /// </summary>
-        public IEnumerable<byte> Public
+        public IEnumerable<byte> PublicBytes
         {
             get { return _Public.Q.GetEncoded(); }
         }