2020-03-18 00:23:01 +01:00
|
|
|
package netann
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-04-06 02:06:38 +02:00
|
|
|
"github.com/lightningnetwork/lnd/input"
|
2021-09-23 16:54:30 +02:00
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
2020-03-18 00:23:01 +01:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SignAnnouncement signs any type of gossip message that is announced on the
|
|
|
|
// network.
|
2021-09-23 16:54:30 +02:00
|
|
|
func SignAnnouncement(signer lnwallet.MessageSigner, keyLoc keychain.KeyLocator,
|
2020-04-06 02:06:38 +02:00
|
|
|
msg lnwire.Message) (input.Signature, error) {
|
2020-03-18 00:23:01 +01:00
|
|
|
|
|
|
|
var (
|
|
|
|
data []byte
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch m := msg.(type) {
|
|
|
|
case *lnwire.ChannelAnnouncement:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
case *lnwire.ChannelUpdate:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
case *lnwire.NodeAnnouncement:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("can't sign %T message", m)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2024-02-26 12:19:38 +01:00
|
|
|
return nil, fmt.Errorf("unable to get data to sign: %w", err)
|
2020-03-18 00:23:01 +01:00
|
|
|
}
|
|
|
|
|
2021-10-14 15:42:44 +02:00
|
|
|
return signer.SignMessage(keyLoc, data, true)
|
2020-03-18 00:23:01 +01:00
|
|
|
}
|