/// <summary>
/// Generates a KeyPair using a BigInteger as a private key.
/// BigInteger is checked for appropriate range.
/// </summary>
public KeyPair(BigInteger bi, bool compressed = false, byte addressType = 0)
{
this.IsCompressedPoint = compressed;
this.AddressType = addressType;
var ps = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1");
if (bi.CompareTo(ps.N) >= 0 || bi.SignValue <= 0) {
throw new ArgumentException("BigInteger is out of range of valid private keys");
}
byte[] bb = Util.Force32Bytes(bi.ToByteArrayUnsigned());
PrivateKeyBytes = bb;
}