multi: return input.Signature from SignOutputRaw

This commit is contained in:
Conner Fromknecht committed 2020-04-10 14:27:35 -07:00
1 parent 37dffb225a
commit 0f94b8dc62
29 files changed
+168 -110

No files matched your search

+3 -3
View File
@@ -225,7 +225,7 @@ func maybeTweakPrivKey(signDesc *input.SignDescriptor,
//
// This is a part of the WalletController interface.
func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx,
signDesc *input.SignDescriptor) ([]byte, error) {
signDesc *input.SignDescriptor) (input.Signature, error) {
witnessScript := signDesc.WitnessScript
@@ -256,7 +256,7 @@ func (b *BtcWallet) SignOutputRaw(tx *wire.MsgTx,
}
// Chop off the sighash flag at the end of the signature.
return sig[:len(sig)-1], nil
return btcec.ParseDERSignature(sig[:len(sig)-1], btcec.S256())
}
// ComputeInputScript generates a complete InputScript for the passed
@@ -358,7 +358,7 @@ var _ input.Signer = (*BtcWallet)(nil)
//
// NOTE: This is a part of the MessageSigner interface.
func (b *BtcWallet) SignMessage(pubKey *btcec.PublicKey,
msg []byte) (*btcec.Signature, error) {
msg []byte) (input.Signature, error) {
// First attempt to fetch the private key which corresponds to the
// specified public key.
+4 -3
View File
@@ -3402,7 +3402,7 @@ func (lc *LightningChannel) SignNextCommitment() (lnwire.Sig, []lnwire.Sig, []ch
close(cancelChan)
return sig, htlcSigs, nil, err
}
sig, err = lnwire.NewSigFromRawSignature(rawSig)
sig, err = lnwire.NewSigFromSignature(rawSig)
if err != nil {
close(cancelChan)
return sig, htlcSigs, nil, err
@@ -5075,7 +5075,7 @@ func (lc *LightningChannel) getSignedCommitTx() (*wire.MsgTx, error) {
return nil, err
}
ourSig := append(ourSigRaw, byte(txscript.SigHashAll))
ourSig := append(ourSigRaw.Serialize(), byte(txscript.SigHashAll))
// With the final signature generated, create the witness stack
// required to spend from the multi-sig output.
@@ -5950,7 +5950,8 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
// settle any in flight.
func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
localDeliveryScript []byte,
remoteDeliveryScript []byte) ([]byte, *chainhash.Hash, btcutil.Amount, error) {
remoteDeliveryScript []byte) (input.Signature, *chainhash.Hash,
btcutil.Amount, error) {
lc.Lock()
defer lc.Unlock()
+8 -8
View File
@@ -616,7 +616,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
if err != nil {
t.Fatalf("unable to create alice coop close proposal: %v", err)
}
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
aliceCloseSig := append(aliceSig.Serialize(), byte(txscript.SigHashAll))
bobFee := bobChannel.CalcFee(bobFeeRate)
bobSig, _, _, err := bobChannel.CreateCloseProposal(
@@ -625,7 +625,7 @@ func TestCooperativeChannelClosure(t *testing.T) {
if err != nil {
t.Fatalf("unable to create bob coop close proposal: %v", err)
}
bobCloseSig := append(bobSig, byte(txscript.SigHashAll))
bobCloseSig := append(bobSig.Serialize(), byte(txscript.SigHashAll))
// With the proposals created, both sides should be able to properly
// process the other party's signature. This indicates that the
@@ -2059,7 +2059,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
aliceCloseSig := append(aliceSig, byte(txscript.SigHashAll))
aliceCloseSig := append(aliceSig.Serialize(), byte(txscript.SigHashAll))
bobFee := btcutil.Amount(bobChannel.CalcFee(bobFeeRate)) + 1000
bobSig, _, _, err := bobChannel.CreateCloseProposal(bobFee,
@@ -2067,7 +2067,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
bobCloseSig := append(bobSig, byte(txscript.SigHashAll))
bobCloseSig := append(bobSig.Serialize(), byte(txscript.SigHashAll))
closeTx, _, err := bobChannel.CompleteCooperativeClose(
bobCloseSig, aliceCloseSig,
@@ -2098,14 +2098,14 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
aliceCloseSig = append(aliceSig.Serialize(), byte(txscript.SigHashAll))
bobSig, _, _, err = bobChannel.CreateCloseProposal(bobFee,
bobDeliveryScript, aliceDeliveryScript)
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
bobCloseSig = append(bobSig, byte(txscript.SigHashAll))
bobCloseSig = append(bobSig.Serialize(), byte(txscript.SigHashAll))
closeTx, _, err = bobChannel.CompleteCooperativeClose(
bobCloseSig, aliceCloseSig,
@@ -2141,7 +2141,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
aliceCloseSig = append(aliceSig, byte(txscript.SigHashAll))
aliceCloseSig = append(aliceSig.Serialize(), byte(txscript.SigHashAll))
bobSig, _, _, err = bobChannel.CreateCloseProposal(
bobFee, bobDeliveryScript, aliceDeliveryScript,
@@ -2149,7 +2149,7 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
bobCloseSig = append(bobSig, byte(txscript.SigHashAll))
bobCloseSig = append(bobSig.Serialize(), byte(txscript.SigHashAll))
closeTx, _, err = bobChannel.CompleteCooperativeClose(
bobCloseSig, aliceCloseSig,
+2 -1
View File
@@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwallet/wallet/txauthor"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)
@@ -292,7 +293,7 @@ type MessageSigner interface {
// that corresponds to the passed public key. 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(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error)
SignMessage(pubKey *btcec.PublicKey, msg []byte) (input.Signature, error)
}
// WalletDriver represents a "driver" for a particular concrete
+2 -2
View File
@@ -1591,7 +1591,7 @@ func txFromOutput(tx *wire.MsgTx, signer input.Signer, fromPubKey,
return nil, fmt.Errorf("unable to generate signature: %v", err)
}
witness := make([][]byte, 2)
witness[0] = append(spendSig, byte(txscript.SigHashAll))
witness[0] = append(spendSig.Serialize(), byte(txscript.SigHashAll))
witness[1] = fromPubKey.SerializeCompressed()
tx1.TxIn[0].Witness = witness
@@ -1976,7 +1976,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness,
t.Fatalf("unable to generate signature: %v", err)
}
witness := make([][]byte, 2)
witness[0] = append(spendSig, byte(txscript.SigHashAll))
witness[0] = append(spendSig.Serialize(), byte(txscript.SigHashAll))
witness[1] = tweakedKey.SerializeCompressed()
sweepTx.TxIn[0].Witness = witness
+10 -6
View File
@@ -134,8 +134,8 @@ type ChannelReservation struct {
theirFundingInputScripts []*input.Script
// Our signature for their version of the commitment transaction.
ourCommitmentSig []byte
theirCommitmentSig []byte
ourCommitmentSig input.Signature
theirCommitmentSig input.Signature
ourContribution *ChannelContribution
theirContribution *ChannelContribution
@@ -538,7 +538,9 @@ func (r *ChannelReservation) TheirContribution() *ChannelContribution {
//
// NOTE: These signatures will only be populated after a call to
// .ProcessContribution()
func (r *ChannelReservation) OurSignatures() ([]*input.Script, []byte) {
func (r *ChannelReservation) OurSignatures() ([]*input.Script,
input.Signature) {
r.RLock()
defer r.RUnlock()
return r.ourFundingInputScripts, r.ourCommitmentSig
@@ -558,7 +560,7 @@ func (r *ChannelReservation) OurSignatures() ([]*input.Script, []byte) {
// confirmations. Once the method unblocks, a LightningChannel instance is
// returned, marking the channel available for updates.
func (r *ChannelReservation) CompleteReservation(fundingInputScripts []*input.Script,
commitmentSig []byte) (*channeldb.OpenChannel, error) {
commitmentSig input.Signature) (*channeldb.OpenChannel, error) {
// TODO(roasbeef): add flag for watch or not?
errChan := make(chan error, 1)
@@ -585,7 +587,7 @@ func (r *ChannelReservation) CompleteReservation(fundingInputScripts []*input.Sc
// called as a response to a single funder channel, only a commitment signature
// will be populated.
func (r *ChannelReservation) CompleteReservationSingle(fundingPoint *wire.OutPoint,
commitSig []byte) (*channeldb.OpenChannel, error) {
commitSig input.Signature) (*channeldb.OpenChannel, error) {
errChan := make(chan error, 1)
completeChan := make(chan *channeldb.OpenChannel, 1)
@@ -608,7 +610,9 @@ func (r *ChannelReservation) CompleteReservationSingle(fundingPoint *wire.OutPoi
//
// NOTE: These attributes will be unpopulated before a call to
// .CompleteReservation().
func (r *ChannelReservation) TheirSignatures() ([]*input.Script, []byte) {
func (r *ChannelReservation) TheirSignatures() ([]*input.Script,
input.Signature) {
r.RLock()
defer r.RUnlock()
return r.theirFundingInputScripts, r.theirCommitmentSig
+1 -1
View File
@@ -205,7 +205,7 @@ func (s *SigPool) poolWorker() {
}
}
sig, err := lnwire.NewSigFromRawSignature(rawSig)
sig, err := lnwire.NewSigFromSignature(rawSig)
select {
case sigMsg.Resp <- SignJobResp{
Sig: sig,
+8 -18
View File
@@ -215,7 +215,7 @@ type addCounterPartySigsMsg struct {
// This should be 1/2 of the signatures needed to successfully spend our
// version of the commitment transaction.
theirCommitmentSig []byte
theirCommitmentSig input.Signature
// This channel is used to return the completed channel after the wallet
// has completed all of its stages in the funding process.
@@ -240,7 +240,7 @@ type addSingleFunderSigsMsg struct {
// theirCommitmentSig are the 1/2 of the signatures needed to
// successfully spend our version of the commitment transaction.
theirCommitmentSig []byte
theirCommitmentSig input.Signature
// This channel is used to return the completed channel after the wallet
// has completed all of its stages in the funding process.
@@ -1406,18 +1406,13 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// Verify that we've received a valid signature from the remote party
// for our version of the commitment transaction.
theirCommitSig := msg.theirCommitmentSig
sig, err := btcec.ParseSignature(theirCommitSig, btcec.S256())
if err != nil {
msg.err <- err
msg.completeChan <- nil
return
} else if !sig.Verify(sigHash, theirKey.PubKey) {
if !msg.theirCommitmentSig.Verify(sigHash, theirKey.PubKey) {
msg.err <- fmt.Errorf("counterparty's commitment signature is invalid")
msg.completeChan <- nil
return
}
res.partialState.LocalCommitment.CommitSig = theirCommitSig
theirCommitSigBytes := msg.theirCommitmentSig.Serialize()
res.partialState.LocalCommitment.CommitSig = theirCommitSigBytes
// Funding complete, this entry can be removed from limbo.
l.limboMtx.Lock()
@@ -1566,19 +1561,14 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// Verify that we've received a valid signature from the remote party
// for our version of the commitment transaction.
sig, err := btcec.ParseSignature(req.theirCommitmentSig, btcec.S256())
if err != nil {
req.err <- err
req.completeChan <- nil
return
}
if !sig.Verify(sigHash, theirKey.PubKey) {
if !req.theirCommitmentSig.Verify(sigHash, theirKey.PubKey) {
req.err <- fmt.Errorf("counterparty's commitment signature " +
"is invalid")
req.completeChan <- nil
return
}
chanState.LocalCommitment.CommitSig = req.theirCommitmentSig
theirCommitSigBytes := req.theirCommitmentSig.Serialize()
chanState.LocalCommitment.CommitSig = theirCommitSigBytes
// With their signature for our version of the commitment transactions
// verified, we can now generate a signature for their version,