lnwallet/btcwallet: remove FundingSigner, implement MessageSigner

This commit removes the now deprecated FundingSigner struct as part of
the btcwallet package, and instead replaces it within an implementation
of the MessageSigner interface.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-14 11:05:18 -07:00
parent 98c58ddb67
commit 4e988b228e
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -206,39 +206,32 @@ func (b *BtcWallet) ComputeInputScript(tx *wire.MsgTx,
// interface.
var _ lnwallet.Signer = (*BtcWallet)(nil)
// FundingSigner responsible for signing the data with the keys that were
// generated by the wallet. At the moment of creation it is used for signing
// the data with funding keys.
type FundingSigner struct {
wallet *BtcWallet
}
// NewFundingSigner creates new instance of signer.
func NewFundingSigner(wallet *BtcWallet) *FundingSigner {
return &FundingSigner{
wallet: wallet,
}
}
// SignData sign given data with the private key which corresponds to the given
// public key.
// SignMessage attempts to sign a target message with the private key that
// corresponds to the passed public key. If the target private key is unable to
// be found, then an error will be returned. The actual digest signed is the
// double SHA-256 of the passed message.
//
// NOTE: This is a part of the DataSigner interface.
func (s *FundingSigner) SignData(data []byte,
pubKey *btcec.PublicKey) (*btcec.Signature, error) {
// NOTE: This is a part of the MessageSigner interface.
func (b *BtcWallet) SignMessage(pubKey *btcec.PublicKey,
msg []byte) (*btcec.Signature, error) {
// First attempt to fetch the private key which corresponds to the
// specified public key.
privKey, err := s.wallet.fetchPrivKey(pubKey)
privKey, err := b.fetchPrivKey(pubKey)
if err != nil {
return nil, err
}
// Double hash and sign data.
sign, err := privKey.Sign(chainhash.DoubleHashB(data))
// Double hash and sign the data.
msgDigest := chainhash.DoubleHashB(msg)
sign, err := privKey.Sign(msgDigest)
if err != nil {
return nil, errors.Errorf("unable sign the message: %v", err)
}
return sign, nil
}
// A compile time check to ensure that BtcWallet implements the MessageSigner
// interface.
var _ lnwallet.MessageSigner = (*BtcWallet)(nil)