예제 #1
0
        public PayToTaprootScriptSigParameters?ExtractWitScriptParameters(WitScript witScript)
        {
            if (witScript == null)
            {
                throw new ArgumentNullException(nameof(witScript));
            }

            if (witScript.PushCount != 1 && witScript.PushCount != 2)
            {
                return(null);
            }
            var hasAnex = false;

            if (witScript.PushCount == 2)
            {
                if (!CheckAnnex(witScript[1]))
                {
                    return(null);
                }
                hasAnex = true;
            }
            if (!TaprootSignature.TryParse(witScript[0], out var sig))
            {
                return(null);
            }
            return(new PayToTaprootScriptSigParameters(sig, hasAnex ? witScript[1] : null)
            {
                TransactionSignature = sig,
                Annex = hasAnex ? witScript[1] : null,
            });
        }
예제 #2
0
 public WitScript GenerateWitScript(TaprootSignature signature)
 {
     if (signature == null)
     {
         throw new ArgumentNullException(nameof(signature));
     }
     return(new Script(Op.GetPushOp(signature.ToBytes())));
 }
예제 #3
0
 public PayToTaprootScriptSigParameters(TaprootSignature transactionSignature, byte[]?annex = null)
 {
     if (transactionSignature is null)
     {
         throw new ArgumentNullException(nameof(transactionSignature));
     }
     TransactionSignature = transactionSignature;
     Annex = annex;
 }
        public static bool TryParse(byte[] bytes, [MaybeNullWhen(false)] out TaprootSignature signature)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException(nameof(bytes));
            }
#if HAS_SPAN
            return(TryParse(bytes.AsSpan(), out signature));
#else
            if (bytes.Length == 64)
            {
                if (!SchnorrSignature.TryParse(bytes, out var sig))
                {
                    signature = null;
                    return(false);
                }
                signature = new TaprootSignature(sig);
                return(true);
            }
            else if (bytes.Length == 65)
            {
                if (!TaprootExecutionData.IsValidSigHash(bytes[64]) || bytes[64] == 0)
                {
                    signature = null;
                    return(false);
                }
                var sighash = (TaprootSigHash)bytes[64];
                if (sighash == TaprootSigHash.Default)
                {
                    signature = null;
                    return(false);
                }
                var buff = new byte[64];
                Array.Copy(bytes, 0, buff, 0, 64);
                if (!SchnorrSignature.TryParse(buff, out var sig))
                {
                    signature = null;
                    return(false);
                }
                signature = new TaprootSignature(sig, sighash);
                return(true);
            }
            else
            {
                signature = null;
                return(false);
            }
#endif
        }
예제 #5
0
        public WitScript GenerateWitScript(TaprootSignature signature, byte[] annex)
        {
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }
            if (annex == null)
            {
                return(GenerateWitScript(signature));
            }
            if (!CheckAnnex(annex))
            {
                throw new ArgumentException("The first byte of annex must be 0x50", "annex");
            }

            return(new Script(Op.GetPushOp(signature.ToBytes()), Op.GetPushOp(annex)));
        }
 public static bool TryParse(string hex, [MaybeNullWhen(false)] out TaprootSignature signature)
 {
     if (hex == null)
     {
         throw new ArgumentNullException(nameof(hex));
     }
     try
     {
         var bytes = Encoders.Hex.DecodeData(hex);
         if (TryParse(bytes, out signature))
         {
             return(true);
         }
         signature = null;
         return(false);
     }
     catch (FormatException)
     {
         signature = null;
         return(false);
     }
 }
 public static bool TryParse(ReadOnlySpan <byte> bytes, [MaybeNullWhen(false)] out TaprootSignature signature)
 {
     if (bytes.Length == 64)
     {
         if (!SchnorrSignature.TryParse(bytes, out var sig))
         {
             signature = null;
             return(false);
         }
         signature = new TaprootSignature(sig);
         return(true);
     }
     else if (bytes.Length == 65)
     {
         if (!TaprootExecutionData.IsValidSigHash(bytes[64]))
         {
             signature = null;
             return(false);
         }
         var sighash = (TaprootSigHash)bytes[64];
         if (sighash == TaprootSigHash.Default)
         {
             signature = null;
             return(false);
         }
         if (!SchnorrSignature.TryParse(bytes.Slice(0, 64), out var sig))
         {
             signature = null;
             return(false);
         }
         signature = new TaprootSignature(sig, sighash);
         return(true);
     }
     else
     {
         signature = null;
         return(false);
     }
 }
예제 #8
0
 public Script GenerateScriptSig(TaprootSignature signature)
 {
     return(GenerateWitScript(signature));
 }