lnwire: update Sig to support both ECDSA and schnorr sigs

In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:29:19 -07:00
1 parent eccc77315b
commit b368e476c5
29 files changed
+296 -128

No files matched your search

+6 -4
View File
@@ -785,16 +785,18 @@ func (c *ChanCloser) proposeCloseSigned(fee btcutil.Amount) (*lnwire.ClosingSign
return nil, err
}
// We'll note our last signature and proposed fee so when the remote party
// responds we'll be able to decide if we've agreed on fees or not.
// We'll note our last signature and proposed fee so when the remote
// party responds we'll be able to decide if we've agreed on fees or
// not.
c.lastFeeProposal = fee
parsedSig, err := lnwire.NewSigFromSignature(rawSig)
if err != nil {
return nil, err
}
chancloserLog.Infof("ChannelPoint(%v): proposing fee of %v sat to close "+
"chan", c.chanPoint, int64(fee))
chancloserLog.Infof("ChannelPoint(%v): proposing fee of %v sat to "+
"close chan", c.chanPoint, int64(fee))
// We'll assemble a ClosingSigned message using this information and return
// it to the caller so we can kick off the final stage of the channel
+2 -2
View File
@@ -320,7 +320,7 @@ type PaymentDescriptor struct {
// local node. This signature is generated by the remote node and
// stored by the local node in the case that local node needs to
// broadcast their commitment transaction.
sig *ecdsa.Signature
sig input.Signature
// addCommitHeight[Remote|Local] encodes the height of the commitment
// which included this HTLC on either the remote or local commitment
@@ -4331,7 +4331,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
var (
htlcIndex uint64
sigHash func() ([]byte, error)
sig *ecdsa.Signature
sig input.Signature
err error
)
+5 -1
View File
@@ -5331,7 +5331,11 @@ func TestInvalidCommitSigError(t *testing.T) {
// Before the signature gets to Bob, we'll mutate it, such that the
// signature is now actually invalid.
aliceSig[0] ^= 88
aliceSigCopy := aliceSig.Copy()
aliceSigCopyBytes := aliceSigCopy.RawBytes()
aliceSigCopyBytes[0] ^= 88
aliceSig, err = lnwire.NewSigFromWireECDSA(aliceSigCopyBytes)
require.NoError(t, err)
// Bob should reject this new state, and return the proper error.
err = bobChannel.ReceiveNewCommitment(aliceSig, aliceHtlcSigs)
+12 -3
View File
@@ -454,11 +454,20 @@ func (r *RPCKeyRing) SignMessage(keyLoc keychain.KeyLocator,
"signer instance: %v", err)
}
wireSig, err := lnwire.NewSigFromRawSignature(resp.Signature)
wireSig, err := lnwire.NewSigFromECDSARawSignature(resp.Signature)
if err != nil {
return nil, fmt.Errorf("error parsing raw signature: %v", err)
return nil, fmt.Errorf("unable to create sig: %w", err)
}
return wireSig.ToSignature()
sig, err := wireSig.ToSignature()
if err != nil {
return nil, fmt.Errorf("unable to parse sig: %w", err)
}
ecdsaSig, ok := sig.(*ecdsa.Signature)
if !ok {
return nil, fmt.Errorf("unexpected signature type: %T", sig)
}
return ecdsaSig, nil
}
// SignMessageCompact signs the given message, single or double SHA256 hashing
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"sync"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwire"
@@ -36,7 +35,7 @@ type VerifyJob struct {
// Sig is the raw signature generated using the above public key. This
// is the signature to be verified.
Sig *ecdsa.Signature
Sig input.Signature
// SigHash is a function closure generates the sighashes that the
// passed signature is known to have signed.