From 9f47d31681beb7f199dd6a79c1eb71ef54efe35f Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 29 Jul 2022 18:20:06 +0200 Subject: [PATCH] input: add tapscript root hash helper function --- input/taproot.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/input/taproot.go b/input/taproot.go index 0319228ba..621ec731d 100644 --- a/input/taproot.go +++ b/input/taproot.go @@ -105,3 +105,24 @@ func TapscriptPartialReveal(internalKey *btcec.PublicKey, RevealedScript: revealedLeaf.Script, } } + +// TapscriptRootHashOnly creates a waddrmgr.Tapscript for the given internal key +// and root hash. +func TapscriptRootHashOnly(internalKey *btcec.PublicKey, + rootHash []byte) *waddrmgr.Tapscript { + + controlBlock := &txscript.ControlBlock{ + InternalKey: internalKey, + } + + tapKey := txscript.ComputeTaprootOutputKey(internalKey, rootHash) + if tapKey.SerializeCompressed()[0] == PubKeyFormatCompressedOdd { + controlBlock.OutputKeyYIsOdd = true + } + + return &waddrmgr.Tapscript{ + Type: waddrmgr.TaprootKeySpendRootHash, + ControlBlock: controlBlock, + RootHash: rootHash, + } +}