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

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