|
4 | 4 | "fmt" |
5 | 5 |
|
6 | 6 | "github.com/btcsuite/btcd/btcec/v2" |
| 7 | + "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2" |
7 | 8 | "github.com/btcsuite/btcd/btcutil" |
8 | 9 | "github.com/btcsuite/btcd/chaincfg/chainhash" |
9 | 10 | "github.com/btcsuite/btcd/wire" |
@@ -105,6 +106,26 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) { |
105 | 106 | ) |
106 | 107 | } |
107 | 108 |
|
| 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 | + |
108 | 129 | // Cancel allows the caller to cancel a funding Intent at any time. This will |
109 | 130 | // return any resources such as coins back to the eligible pool to be used in |
110 | 131 | // order channel fundings. |
|
0 commit comments