input: add tapscript root hash helper function

This commit is contained in:
Oliver Gugger 2022-07-29 18:20:06 +02:00
parent 0d6e791042
commit 9f47d31681
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -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,
}
}