/// <param name="seedBytes"> - a bytes sequence of arbitrary length which will be hashed </param> /// <param name="discriminator"> - nullable optional uint32 to hash </param> /// <returns> a number between [1, order -1] suitable as a private key /// </returns> public static BigInteger ComputeScalar(byte[] seedBytes, uint?discriminator) { BigInteger key = null; for (uint i = 0; i <= 0xFFFFFFFFL; i++) { var sha512 = new Sha512(seedBytes); if (discriminator != null) { sha512.AddU32(discriminator.Value); } sha512.AddU32(i); byte[] keyBytes = sha512.Finish256(); key = Misc.UBigInt(keyBytes); if (key.CompareTo(BigInteger.Zero) == 1 && key.CompareTo(Secp256K1.Order()) == -1) { break; } } return(key); }