diff --git a/funding/manager.go b/funding/manager.go index 2d9df837d1..7479d50826 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -327,7 +327,7 @@ type Config struct { // TODO(roasbeef): should instead pass on this responsibility to a // distinct sub-system? SignMessage func(keyLoc keychain.KeyLocator, - msg []byte) (*btcec.Signature, error) + msg []byte, doubleHash bool) (*btcec.Signature, error) // CurrentNodeAnnouncement should return the latest, fully signed node // announcement from the backing Lightning Network node. @@ -2911,7 +2911,7 @@ func (f *Manager) newChanAnnouncement(localPubKey, if err != nil { return nil, err } - sig, err := f.cfg.SignMessage(f.cfg.IDKeyLoc, chanUpdateMsg) + sig, err := f.cfg.SignMessage(f.cfg.IDKeyLoc, chanUpdateMsg, true) if err != nil { return nil, errors.Errorf("unable to generate channel "+ "update announcement signature: %v", err) @@ -2933,13 +2933,13 @@ func (f *Manager) newChanAnnouncement(localPubKey, if err != nil { return nil, err } - nodeSig, err := f.cfg.SignMessage(f.cfg.IDKeyLoc, chanAnnMsg) + nodeSig, err := f.cfg.SignMessage(f.cfg.IDKeyLoc, chanAnnMsg, true) if err != nil { return nil, errors.Errorf("unable to generate node "+ "signature for channel announcement: %v", err) } bitcoinSig, err := f.cfg.SignMessage( - localFundingKey.KeyLocator, chanAnnMsg, + localFundingKey.KeyLocator, chanAnnMsg, true, ) if err != nil { return nil, errors.Errorf("unable to generate bitcoin "+ diff --git a/funding/manager_test.go b/funding/manager_test.go index 7261ab6365..bfd47329fc 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -362,7 +362,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey, Notifier: chainNotifier, FeeEstimator: estimator, SignMessage: func(_ keychain.KeyLocator, - _ []byte) (*btcec.Signature, error) { + _ []byte, _ bool) (*btcec.Signature, error) { return testSig, nil }, @@ -510,7 +510,7 @@ func recreateAliceFundingManager(t *testing.T, alice *testNode) { Notifier: oldCfg.Notifier, FeeEstimator: oldCfg.FeeEstimator, SignMessage: func(_ keychain.KeyLocator, - _ []byte) (*btcec.Signature, error) { + _ []byte, _ bool) (*btcec.Signature, error) { return testSig, nil }, diff --git a/lntest/mock/signer.go b/lntest/mock/signer.go index ce4dc55f3d..a0ce79b929 100644 --- a/lntest/mock/signer.go +++ b/lntest/mock/signer.go @@ -116,7 +116,7 @@ func (s *SingleSigner) ComputeInputScript(tx *wire.MsgTx, // SignMessage takes a public key and a message and only signs the message // with the stored private key if the public key matches the private key. func (s *SingleSigner) SignMessage(keyLoc keychain.KeyLocator, - msg []byte) (*btcec.Signature, error) { + msg []byte, doubleHash bool) (*btcec.Signature, error) { mockKeyLoc := s.KeyLoc if s.KeyLoc.IsEmpty() { @@ -127,7 +127,12 @@ func (s *SingleSigner) SignMessage(keyLoc keychain.KeyLocator, return nil, fmt.Errorf("unknown public key") } - digest := chainhash.DoubleHashB(msg) + var digest []byte + if doubleHash { + digest = chainhash.DoubleHashB(msg) + } else { + digest = chainhash.HashB(msg) + } sign, err := s.Privkey.Sign(digest) if err != nil { return nil, fmt.Errorf("can't sign the message: %v", err) diff --git a/lnwallet/btcwallet/signer.go b/lnwallet/btcwallet/signer.go index a710565e27..277f391320 100644 --- a/lnwallet/btcwallet/signer.go +++ b/lnwallet/btcwallet/signer.go @@ -267,7 +267,7 @@ var _ input.Signer = (*BtcWallet)(nil) // // NOTE: This is a part of the MessageSigner interface. func (b *BtcWallet) SignMessage(keyLoc keychain.KeyLocator, - msg []byte) (*btcec.Signature, error) { + msg []byte, doubleHash bool) (*btcec.Signature, error) { // First attempt to fetch the private key which corresponds to the // specified public key. @@ -279,7 +279,12 @@ func (b *BtcWallet) SignMessage(keyLoc keychain.KeyLocator, } // Double hash and sign the data. - msgDigest := chainhash.DoubleHashB(msg) + var msgDigest []byte + if doubleHash { + msgDigest = chainhash.DoubleHashB(msg) + } else { + msgDigest = chainhash.HashB(msg) + } sign, err := privKey.Sign(msgDigest) if err != nil { return nil, errors.Errorf("unable sign the message: %v", err) diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 9e94cfa0ab..b15fa7a034 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -442,9 +442,9 @@ type MessageSigner interface { // SignMessage attempts to sign a target message with the private key // described in the key locator. 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. - SignMessage(keyLoc keychain.KeyLocator, msg []byte) (*btcec.Signature, - error) + // the single or double SHA-256 of the passed message. + SignMessage(keyLoc keychain.KeyLocator, msg []byte, + doubleHash bool) (*btcec.Signature, error) } // WalletDriver represents a "driver" for a particular concrete diff --git a/netann/channel_update_test.go b/netann/channel_update_test.go index 5af21540fd..e28f381841 100644 --- a/netann/channel_update_test.go +++ b/netann/channel_update_test.go @@ -18,7 +18,7 @@ type mockSigner struct { } func (m *mockSigner) SignMessage(_ keychain.KeyLocator, - _ []byte) (*btcec.Signature, error) { + _ []byte, _ bool) (*btcec.Signature, error) { if m.err != nil { return nil, m.err diff --git a/netann/node_signer.go b/netann/node_signer.go index eb2d813e81..d357282693 100644 --- a/netann/node_signer.go +++ b/netann/node_signer.go @@ -26,7 +26,7 @@ func NewNodeSigner(keySigner keychain.SingleKeyMessageSigner) *NodeSigner { // resident node's private key described in the key locator. If the target key // locator is _not_ the node's private key, then an error will be returned. func (n *NodeSigner) SignMessage(keyLoc keychain.KeyLocator, - msg []byte) (*btcec.Signature, error) { + msg []byte, doubleHash bool) (*btcec.Signature, error) { // If this isn't our identity public key, then we'll exit early with an // error as we can't sign with this key. @@ -35,7 +35,7 @@ func (n *NodeSigner) SignMessage(keyLoc keychain.KeyLocator, } // Otherwise, we'll sign the double-sha256 of the target message. - sig, err := n.keySigner.SignMessage(msg, true) + sig, err := n.keySigner.SignMessage(msg, doubleHash) if err != nil { return nil, fmt.Errorf("can't sign the message: %v", err) } diff --git a/netann/sign.go b/netann/sign.go index 2ee4d0d081..86634f6281 100644 --- a/netann/sign.go +++ b/netann/sign.go @@ -33,5 +33,5 @@ func SignAnnouncement(signer lnwallet.MessageSigner, keyLoc keychain.KeyLocator, return nil, fmt.Errorf("unable to get data to sign: %v", err) } - return signer.SignMessage(keyLoc, data) + return signer.SignMessage(keyLoc, data, true) }