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

+16 -5
View File
@@ -398,7 +398,7 @@ func (b *JusticeKit) encodeV0(w io.Writer) error {
}
// Write 64-byte revocation signature for commit to-local output.
_, err = w.Write(b.CommitToLocalSig[:])
_, err = w.Write(b.CommitToLocalSig.RawBytes())
if err != nil {
return err
}
@@ -410,7 +410,7 @@ func (b *JusticeKit) encodeV0(w io.Writer) error {
}
// Write 64-byte commit to-remote signature, which may be blank.
_, err = w.Write(b.CommitToRemoteSig[:])
_, err = w.Write(b.CommitToRemoteSig.RawBytes())
return err
}
@@ -472,14 +472,20 @@ func (b *JusticeKit) decodeV0(r io.Reader) error {
}
// Read 64-byte revocation signature for commit to-local output.
_, err = io.ReadFull(r, b.CommitToLocalSig[:])
var localSig [64]byte
_, err = io.ReadFull(r, localSig[:])
if err != nil {
return err
}
b.CommitToLocalSig, err = lnwire.NewSigFromWireECDSA(localSig[:])
if err != nil {
return err
}
var (
commitToRemotePubkey PubKey
commitToRemoteSig lnwire.Sig
commitToRemoteSig [64]byte
)
// Read 33-byte commit to-remote public key, which may be discarded.
@@ -498,7 +504,12 @@ func (b *JusticeKit) decodeV0(r io.Reader) error {
// valid compressed public key was read from the reader.
if btcec.IsCompressedPubKey(commitToRemotePubkey[:]) {
b.CommitToRemotePubKey = commitToRemotePubkey
b.CommitToRemoteSig = commitToRemoteSig
b.CommitToRemoteSig, err = lnwire.NewSigFromWireECDSA(
commitToRemoteSig[:],
)
if err != nil {
return err
}
}
return nil
+4 -2
View File
@@ -28,8 +28,10 @@ func makePubKey(i uint64) blob.PubKey {
}
func makeSig(i int) lnwire.Sig {
var sig lnwire.Sig
binary.BigEndian.PutUint64(sig[:8], uint64(i))
var sigBytes [64]byte
binary.BigEndian.PutUint64(sigBytes[:8], uint64(i))
sig, _ := lnwire.NewSigFromWireECDSA(sigBytes[:])
return sig
}