2022-08-12 09:16:35 +02:00
|
|
|
//go:build !integration
|
2020-10-21 19:34:05 +02:00
|
|
|
|
|
|
|
package lnwallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
|
|
|
"github.com/lightningnetwork/lnd/shachain"
|
|
|
|
)
|
|
|
|
|
|
|
|
// nextRevocationProducer creates a new revocation producer, deriving the
|
2023-01-20 02:15:12 +01:00
|
|
|
// revocation root by applying ECDH to a new key from our revocation root
|
|
|
|
// family and the multisig key we use for the channel. For taproot channels a
|
|
|
|
// related shachain revocation root is also returned.
|
2020-10-21 19:34:05 +02:00
|
|
|
func (l *LightningWallet) nextRevocationProducer(res *ChannelReservation,
|
2023-01-20 02:15:12 +01:00
|
|
|
keyRing keychain.KeyRing,
|
|
|
|
) (shachain.Producer, shachain.Producer, error) {
|
2020-10-21 19:34:05 +02:00
|
|
|
|
|
|
|
// Derive the next key in the revocation root family.
|
|
|
|
nextRevocationKeyDesc, err := keyRing.DeriveNextKey(
|
|
|
|
keychain.KeyFamilyRevocationRoot,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2023-01-20 02:15:12 +01:00
|
|
|
return nil, nil, err
|
2020-10-21 19:34:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the DeriveNextKey call returns the first key with Index 0, we need
|
|
|
|
// to re-derive the key as the keychain/btcwallet.go DerivePrivKey call
|
|
|
|
// special-cases Index 0.
|
|
|
|
if nextRevocationKeyDesc.Index == 0 {
|
|
|
|
nextRevocationKeyDesc, err = keyRing.DeriveNextKey(
|
|
|
|
keychain.KeyFamilyRevocationRoot,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2023-01-20 02:15:12 +01:00
|
|
|
return nil, nil, err
|
2020-10-21 19:34:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res.nextRevocationKeyLoc = nextRevocationKeyDesc.KeyLocator
|
|
|
|
|
|
|
|
// Perform an ECDH operation between the private key described in
|
|
|
|
// nextRevocationKeyDesc and our public multisig key. The result will be
|
|
|
|
// used to seed the revocation producer.
|
|
|
|
revRoot, err := l.ECDH(
|
|
|
|
nextRevocationKeyDesc, res.ourContribution.MultiSigKey.PubKey,
|
|
|
|
)
|
|
|
|
if err != nil {
|
2023-01-20 02:15:12 +01:00
|
|
|
return nil, nil, err
|
2020-10-21 19:34:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Once we have the root, we can then generate our shachain producer
|
|
|
|
// and from that generate the per-commitment point.
|
2023-01-20 02:15:12 +01:00
|
|
|
shaChainRoot := shachain.NewRevocationProducer(revRoot)
|
2023-07-11 03:25:06 +02:00
|
|
|
taprootShaChainRoot, err := deriveMusig2Shachain(shaChainRoot)
|
2023-01-20 02:15:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return shaChainRoot, taprootShaChainRoot, nil
|
2020-10-21 19:34:05 +02:00
|
|
|
}
|