public static byte[] SignCompact(byte[] data, byte[] seckey, out int recoveryId)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }
            if (seckey == null)
            {
                throw new ArgumentNullException(nameof(seckey));
            }
            if (seckey.Length != 32)
            {
                throw new ArgumentOutOfRangeException(nameof(seckey));
            }
            recoveryId = 0;
            EcdsaRecoverableSignature recoverableSignature = new EcdsaRecoverableSignature();

            if (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, (byte[])null))
            {
                return((byte[])null);
            }
            byte[] output64 = new byte[64];
            byte   recid;

            if (!Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, output64, out recid, recoverableSignature))
            {
                return((byte[])null);
            }
            recoveryId = (int)recid;
            return(output64);
        }
        public static byte[] SignCompressedCompact(byte[] data, byte[] seckey)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }
            if (seckey == null)
            {
                throw new ArgumentNullException(nameof(seckey));
            }
            if (seckey.Length != 32)
            {
                throw new ArgumentOutOfRangeException(nameof(seckey));
            }
            byte recid = 0;
            EcdsaRecoverableSignature recoverableSignature = new EcdsaRecoverableSignature();
            byte num1 = 0;
            int  num2 = 0;

            byte[] numArray = (byte[])null;
            RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();

            do
            {
                if (num1 == byte.MaxValue)
                {
                    ++num2;
                    num1 = (byte)0;
                }
                if (num1 > (byte)0)
                {
                    numArray = new byte[32];
                    randomNumberGenerator.GetBytes(numArray);
                }
                ++num1;
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, numArray) || !Secp256K1Manager.IsCanonical(recoverableSignature.Data));
            byte[] outputxx = new byte[65];
            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, outputxx, 1, out recid, recoverableSignature);
            outputxx[0] = (byte)((int)recid + 4 + 27);
            return(outputxx);
        }
        private static int SignCompact(Context ctx, byte[] msg32, byte[] seckey, byte[] output64, out byte recid)
        {
            EcdsaRecoverableSignature recoverableSignature = new EcdsaRecoverableSignature();
            byte num   = 0;
            int  index = 0;

            byte[] noncedata = new byte[32];
            do
            {
                noncedata[index] = num;
                ++num;
                if (noncedata[index] == byte.MaxValue)
                {
                    ++index;
                }
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(ctx, recoverableSignature, msg32, seckey, (NonceFunction)null, noncedata));
            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(ctx, output64, out recid, recoverableSignature);
            return((int)num);
        }
        private static byte[] SignCompact(byte[] data, byte[] seckey, out byte recoveryId)
        {
            EcdsaRecoverableSignature recoverableSignature = new EcdsaRecoverableSignature();
            byte num   = 0;
            int  index = 0;

            byte[] noncedata = new byte[32];
            do
            {
                noncedata[index] = num++;
                if (num == byte.MaxValue)
                {
                    ++index;
                    num = (byte)0;
                }
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, noncedata));
            byte[] output64 = new byte[64];
            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, output64, out recoveryId, recoverableSignature);
            return(output64);
        }
 private static bool Secp256K1EcdsaRecoverableSignatureSerializeCompact(Context ctx, byte[] output64, out byte recid, EcdsaRecoverableSignature sig)
 {
     return(Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(ctx, output64, 0, out recid, sig));
 }