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, }); }
public WitScript GenerateWitScript(TaprootSignature signature) { if (signature == null) { throw new ArgumentNullException(nameof(signature)); } return(new Script(Op.GetPushOp(signature.ToBytes()))); }
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 }
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); } }
public Script GenerateScriptSig(TaprootSignature signature) { return(GenerateWitScript(signature)); }