Skip to content

Commit a841a9b

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: add TaprootInternalKey method to ShimIntent
If this is a taproot channel, then we'll return the internal key which'll be useful to callers.
1 parent bb71c49 commit a841a9b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lnwallet/chanfunding/canned_assembler.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/btcsuite/btcd/btcec/v2"
7+
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
78
"github.com/btcsuite/btcd/btcutil"
89
"github.com/btcsuite/btcd/chaincfg/chainhash"
910
"github.com/btcsuite/btcd/wire"
@@ -105,6 +106,26 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) {
105106
)
106107
}
107108

109+
// TaprootInternalKey may return the internal key for a MuSig2 funding output,
110+
// but only if this is actually a MuSig2 channel.
111+
func (s *ShimIntent) TaprootInternalKey() fn.Option[*btcec.PublicKey] {
112+
if !s.musig2 {
113+
return fn.None[*btcec.PublicKey]()
114+
}
115+
116+
// Similar to the existing p2wsh script, we'll always ensure the keys
117+
// are sorted before use. Since we're only interested in the internal
118+
// key, we don't need to take into account any tapscript root.
119+
//
120+
// We ignore the error here as this is only called after FundingOutput
121+
// is called.
122+
combinedKey, _, _, _ := musig2.AggregateKeys(
123+
[]*btcec.PublicKey{s.localKey.PubKey, s.remoteKey}, true,
124+
)
125+
126+
return fn.Some(combinedKey.PreTweakedKey)
127+
}
128+
108129
// Cancel allows the caller to cancel a funding Intent at any time. This will
109130
// return any resources such as coins back to the eligible pool to be used in
110131
// order channel fundings.

0 commit comments

Comments
 (0)