From: CryptoManiac Date: Tue, 18 Aug 2015 19:07:00 +0000 (+0300) Subject: Additional CNovacoinAddress verification. X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=152b2eb1dbefc3fd5af09484f88bebc40ef0ee9e Additional CNovacoinAddress verification. --- diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index 6f4e595..d66555e 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace Novacoin { + /// + /// Available address types + /// public enum AddrType { PUBKEY_ADDRESS = 8, @@ -14,31 +17,52 @@ namespace Novacoin SCRIPT_ADDRESS_TEST = 196 }; + /// + /// Represents novacoin address + /// public class CNovacoinAddress { private byte nVersion; private List addrData; + /// + /// Initialize with custom data and version + /// + /// + /// public CNovacoinAddress(byte nVersionIn, IEnumerable addrDataIn) { nVersion = nVersionIn; addrData = addrDataIn.ToList(); } + /// + /// Initialize new instance of PUBKEY_ADDRESS + /// + /// CKeyID instance public CNovacoinAddress(CKeyID keyID) { nVersion = (byte)AddrType.PUBKEY_ADDRESS; addrData = new List(keyID.hashBytes); } + /// + /// Initialize new instance of SCRIPT_ADDRESS + /// + /// CScriptID instance public CNovacoinAddress(CScriptID scriptID) { nVersion = (byte)AddrType.SCRIPT_ADDRESS; addrData = new List(scriptID.hashBytes); } + /// + /// Basic sanity checking + /// + /// public bool IsValid() { + // Address data is normally generated by RIPEMD-160 hash function int nExpectedSize = 20; switch ((AddrType) nVersion) @@ -62,6 +86,10 @@ namespace Novacoin return addrData.Count == nExpectedSize; } + /// + /// Generate base58 serialized representation of novacoin address + /// + /// Base58(data + checksum) public override string ToString() { List r = new List(); diff --git a/NovacoinTest/Program.cs b/NovacoinTest/Program.cs index 592f7ff..dfd1ed8 100644 --- a/NovacoinTest/Program.cs +++ b/NovacoinTest/Program.cs @@ -55,10 +55,6 @@ 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 = "Превед!"; @@ -69,6 +65,15 @@ namespace NovacoinTest Console.WriteLine("Signature is OK: {0} (CKeyPair)", keyPair1.VerifySignature(dataBytes, signature)); Console.WriteLine("Signature is OK: {0} (CPubKey)", pubKey.VerifySignature(dataBytes, signature)); + /// Donation address + + string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788"; + CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest)); + string strDonationAddress = pubKeyTest.GetKeyID().ToString(); + Console.WriteLine("\nDonations may be sent to: {0}", strDonationAddress); + Console.WriteLine("Address generation is OK: {0}", strDonationAddress == "4T2t8uiDtyHceMwMjMHPn88TyJB3trCg3o"); + + Console.ReadLine(); } }