lnd.xprv/lnwallet/signer.go
Andrey Samokhvalov a23715a9c7 lnwallet: add message signer
Added the signer which will be needed in the funding manager to sign
the lnwaire announcement message before sending them to discovery
package. Also in the future the message signer will be used to sign
the users data.
2017-03-29 19:49:05 -07:00

34 lines
899 B
Go

package lnwallet
import (
"fmt"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
)
// MessageSigner is used for creation the signatures using the node identity key.
// By message we mean the whole range of data that might require our approve,
// starting from node, channel, channel update announcements and ending by user
// data.
type MessageSigner struct {
identityKey *btcec.PrivateKey
}
// NewMessageSigner returns the new instance of message signer.
func NewMessageSigner(key *btcec.PrivateKey) *MessageSigner {
return &MessageSigner{
identityKey: key,
}
}
// SignData sign the message with the node private key.
func (s *MessageSigner) SignData(data []byte) (*btcec.Signature, error) {
sign, err := s.identityKey.Sign(chainhash.DoubleHashB(data))
if err != nil {
return nil, fmt.Errorf("can't sign the message: %v", err)
}
return sign, nil
}