Correct checksum computation
authorCryptoManiac <balthazar@yandex.ru>
Tue, 18 Aug 2015 18:46:31 +0000 (21:46 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Tue, 18 Aug 2015 18:46:31 +0000 (21:46 +0300)
Novacoin/AddressTools.cs
Novacoin/CNovacoinAddress.cs
NovacoinTest/Program.cs

index 766ae5c..d03efe1 100644 (file)
@@ -37,6 +37,15 @@ namespace Novacoin
             return strResult;
         }
 
+        public static string Base58EncodeCheck(byte[] bytes)
+        {
+            byte[] dataBytes = new byte[bytes.Length + 4];
+            byte[] checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray();
+
+            bytes.CopyTo(dataBytes, 0);
+            checkSum.CopyTo(dataBytes, bytes.Length);
 
+            return Base58Encode(dataBytes);
+        }
     }
 }
index 3f9c0d9..6f4e595 100644 (file)
@@ -66,14 +66,10 @@ namespace Novacoin
         {
             List<byte> r = new List<byte>();
 
-            byte[] checkSum = Hash256.Compute256(addrData).hashBytes;
-            Array.Resize(ref checkSum, 4);
-
             r.Add(nVersion);
             r.AddRange(addrData);
-            r.AddRange(checkSum); // First four bytes of SHA256 hash
 
-            return AddressTools.Base58Encode(r.ToArray());
+            return AddressTools.Base58EncodeCheck(r.ToArray());
         }
     }
 }
index 645c8e7..592f7ff 100644 (file)
@@ -55,6 +55,10 @@ namespace NovacoinTest
             Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes));
             Console.WriteLine("Novacoin address: {0}\n", keyID.ToString());
 
+            string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788";
+            CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest));
+            Console.WriteLine("Donations may be sent to: {0}\n", pubKeyTest.GetKeyID().ToString());
+
             /// ECDSA keypair signing test
 
             string data = "Превед!";