From 92868cfaa565b18d72fc61d5bdac4f58451a6454 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 16 Jan 2023 19:57:03 -0800 Subject: [PATCH] input: add PayToTaprootScript helper func In this commit, we add a helper function to take a taproot output key and turn it into a v1 witness program. --- input/taproot.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/input/taproot.go b/input/taproot.go index 78294f03a..935050f78 100644 --- a/input/taproot.go +++ b/input/taproot.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/btcsuite/btcd/btcec/v2" + "github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcwallet/waddrmgr" @@ -135,3 +136,15 @@ func TapscriptFullKeyOnly(taprootKey *btcec.PublicKey) *waddrmgr.Tapscript { FullOutputKey: taprootKey, } } + +// PayToTaprootScript creates a new script to pay to a version 1 (taproot) +// witness program. The passed public key will be serialized as an x-only key +// to create the witness program. +func PayToTaprootScript(taprootKey *btcec.PublicKey) ([]byte, error) { + builder := txscript.NewScriptBuilder() + + builder.AddOp(txscript.OP_1) + builder.AddData(schnorr.SerializePubKey(taprootKey)) + + return builder.Script() +}