X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FCPubKey.cs;h=33d1b928d6c666eef0cfddf7ea879a15ab58c328;hb=be9d844557911f95165d2c9875c4f5b2822cfc92;hp=fa4c05265530290d2c1f6a0d1a92cb79dadfbaa3;hpb=e03dceab99c6b3db1c55aa8faf7d2a45ef791f52;p=NovacoinLibrary.git
diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs
index fa4c052..33d1b92 100644
--- a/Novacoin/CPubKey.cs
+++ b/Novacoin/CPubKey.cs
@@ -1,6 +1,23 @@
-using System.Collections.Generic;
+/**
+ * Novacoin classes library
+ * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
+
+ * 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 .
+ */
+
+using System.Collections.Generic;
using System.Linq;
-using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Crypto.Parameters;
namespace Novacoin
@@ -23,9 +40,9 @@ namespace Novacoin
/// Initializes a new instance of CPubKey class using supplied sequence of bytes
///
/// Byte sequence
- public CPubKey(IEnumerable bytes)
+ public CPubKey(byte[] bytes)
{
- ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray());
+ var pQ = curve.Curve.DecodePoint(bytes);
_Public = new ECPublicKeyParameters(pQ, domain);
}
@@ -35,7 +52,7 @@ namespace Novacoin
///
public CPubKey(string strBase58)
{
- ECPoint pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray());
+ var pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58));
_Public = new ECPublicKeyParameters(pQ, domain);
}
@@ -50,18 +67,25 @@ namespace Novacoin
public string ToHex()
{
- return Interop.ToHex(Public);
+ return Interop.ToHex(this);
+ }
+
+ ///
+ /// Public part of key pair
+ ///
+ public static implicit operator byte[] (CPubKey p)
+ {
+ return p._Public.Q.GetEncoded();
}
public override string ToString()
{
- List r = new List();
+ var r = new List();
r.Add((byte)(AddrType.PUBKEY_ADDRESS));
+ r.AddRange((byte[])this);
- r.AddRange(Public);
-
- return AddressTools.Base58EncodeCheck(r);
+ return AddressTools.Base58EncodeCheck(r.ToArray());
}
}
}