using System.Collections.Generic;
using System.Linq;
using Org.BouncyCastle.Math.EC;
using Org.BouncyCastle.Crypto.Parameters;
namespace Novacoin
{
///
/// Representation of ECDSA public key
///
public class CPubKey : CKey
{
///
/// Initializes a new instance of CPubKey class as the copy of another instance
///
/// Another CPubKey instance
public CPubKey(CPubKey pubKey)
{
_Public = pubKey._Public;
}
///
/// Initializes a new instance of CPubKey class using supplied sequence of bytes
///
/// Byte sequence
public CPubKey(IEnumerable bytes)
{
ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray());
_Public = new ECPublicKeyParameters(pQ, domain);
}
///
/// Init with base58 encoded sequence of bytes
///
///
public CPubKey(string strBase58)
{
ECPoint pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray());
_Public = new ECPublicKeyParameters(pQ, domain);
}
///
/// Quick validity test
///
/// Validation result
public bool IsValid
{
get { return !_Public.Q.IsInfinity; }
}
public string ToHex()
{
return Interop.ToHex(PublicBytes);
}
public override string ToString()
{
List r = new List();
r.Add((byte)(AddrType.PUBKEY_ADDRESS));
r.AddRange(PublicBytes);
return AddressTools.Base58EncodeCheck(r);
}
}
}