watchtower/blob/justice_kit: return DER signatures

This commit fixes an issue with the witness stack
construction for to-local and to-remote inputs,
that would cause the justice kit to return
signatures as fixed-size, 64-byte signatures.
The correct behavior is to return DER-encoded
signatures so that they will properly verify on
the network, since the consensus rules won't
be able to understand the fixed-size variant.
This commit is contained in:
Conner Fromknecht 2018-10-30 01:22:30 -07:00
parent fb4d3909a1
commit 2dd399ca52
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -180,12 +180,18 @@ func (b *JusticeKit) CommitToLocalWitnessScript() ([]byte, error) {
// CommitToLocalRevokeWitnessStack constructs a witness stack spending the
// revocation clause of the commitment to-local output.
// <revocation-sig> 1
func (b *JusticeKit) CommitToLocalRevokeWitnessStack() [][]byte {
func (b *JusticeKit) CommitToLocalRevokeWitnessStack() ([][]byte, error) {
toLocalSig, err := b.CommitToLocalSig.ToSignature()
if err != nil {
return nil, err
}
witnessStack := make([][]byte, 2)
witnessStack[0] = append(b.CommitToLocalSig[:], byte(txscript.SigHashAll))
witnessStack[0] = append(toLocalSig.Serialize(),
byte(txscript.SigHashAll))
witnessStack[1] = []byte{1}
return witnessStack
return witnessStack, nil
}
// HasCommitToRemoteOutput returns true if the blob contains a to-remote p2wkh
@ -207,11 +213,17 @@ func (b *JusticeKit) CommitToRemoteWitnessScript() ([]byte, error) {
// CommitToRemoteWitnessStack returns a witness stack spending the commitment
// to-remote output, which is a regular p2wkh.
// <to-remote-sig>
func (b *JusticeKit) CommitToRemoteWitnessStack() [][]byte {
witnessStack := make([][]byte, 1)
witnessStack[0] = append(b.CommitToRemoteSig[:], byte(txscript.SigHashAll))
func (b *JusticeKit) CommitToRemoteWitnessStack() ([][]byte, error) {
toRemoteSig, err := b.CommitToRemoteSig.ToSignature()
if err != nil {
return nil, err
}
return witnessStack
witnessStack := make([][]byte, 1)
witnessStack[0] = append(toRemoteSig.Serialize(),
byte(txscript.SigHashAll))
return witnessStack, nil
}
// Encrypt encodes the blob of justice using encoding version, and then