lnwire: replace usage of btcec.Signature with the new lnwire.Sig type

This commit is contained in:
Olaoluwa Osuntokun 2018-01-30 19:41:52 -08:00
parent 0d7b8be11b
commit 4dd108c827
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
11 changed files with 31 additions and 60 deletions

@ -1,10 +1,6 @@
package lnwire package lnwire
import ( import "io"
"io"
"github.com/roasbeef/btcd/btcec"
)
// AnnounceSignatures this is a direct message between two endpoints of a // AnnounceSignatures this is a direct message between two endpoints of a
// channel and serves as an opt-in mechanism to allow the announcement of // channel and serves as an opt-in mechanism to allow the announcement of
@ -27,13 +23,13 @@ type AnnounceSignatures struct {
// NodeSignature is the signature which contains the signed announce // NodeSignature is the signature which contains the signed announce
// channel message, by this signature we proof that we possess of the // channel message, by this signature we proof that we possess of the
// node pub key and creating the reference node_key -> bitcoin_key. // node pub key and creating the reference node_key -> bitcoin_key.
NodeSignature *btcec.Signature NodeSignature Sig
// BitcoinSignature is the signature which contains the signed node // BitcoinSignature is the signature which contains the signed node
// public key, by this signature we proof that we possess of the // public key, by this signature we proof that we possess of the
// bitcoin key and and creating the reverse reference bitcoin_key -> // bitcoin key and and creating the reverse reference bitcoin_key ->
// node_key. // node_key.
BitcoinSignature *btcec.Signature BitcoinSignature Sig
} }
// A compile time check to ensure AnnounceSignatures implements the // A compile time check to ensure AnnounceSignatures implements the

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"io" "io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
) )
@ -16,14 +15,14 @@ type ChannelAnnouncement struct {
// references between node's channel and node. Requiring both nodes // references between node's channel and node. Requiring both nodes
// to sign indicates they are both willing to route other payments via // to sign indicates they are both willing to route other payments via
// this node. // this node.
NodeSig1 *btcec.Signature NodeSig1 Sig
NodeSig2 *btcec.Signature NodeSig2 Sig
// This signatures are used by nodes in order to create cross // This signatures are used by nodes in order to create cross
// references between node's channel and node. Requiring the bitcoin // references between node's channel and node. Requiring the bitcoin
// signatures proves they control the channel. // signatures proves they control the channel.
BitcoinSig1 *btcec.Signature BitcoinSig1 Sig
BitcoinSig2 *btcec.Signature BitcoinSig2 Sig
// Features is the feature vector that encodes the features supported // Features is the feature vector that encodes the features supported
// by the target node. This field can be used to signal the type of the // by the target node. This field can be used to signal the type of the

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"io" "io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
) )
@ -32,7 +31,7 @@ const (
type ChannelUpdate struct { type ChannelUpdate struct {
// Signature is used to validate the announced data and prove the // Signature is used to validate the announced data and prove the
// ownership of node id. // ownership of node id.
Signature *btcec.Signature Signature Sig
// ChainHash denotes the target chain that this channel was opened // ChainHash denotes the target chain that this channel was opened
// within. This value should be the genesis hash of the target chain. // within. This value should be the genesis hash of the target chain.

@ -3,7 +3,6 @@ package lnwire
import ( import (
"io" "io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
) )
@ -27,12 +26,12 @@ type ClosingSigned struct {
FeeSatoshis btcutil.Amount FeeSatoshis btcutil.Amount
// Signature is for the proposed channel close transaction. // Signature is for the proposed channel close transaction.
Signature *btcec.Signature Signature Sig
} }
// NewClosingSigned creates a new empty ClosingSigned message. // NewClosingSigned creates a new empty ClosingSigned message.
func NewClosingSigned(cid ChannelID, fs btcutil.Amount, func NewClosingSigned(cid ChannelID, fs btcutil.Amount,
sig *btcec.Signature) *ClosingSigned { sig Sig) *ClosingSigned {
return &ClosingSigned{ return &ClosingSigned{
ChannelID: cid, ChannelID: cid,

@ -1,10 +1,6 @@
package lnwire package lnwire
import ( import "io"
"io"
"github.com/roasbeef/btcd/btcec"
)
// CommitSig is sent by either side to stage any pending HTLC's in the // CommitSig is sent by either side to stage any pending HTLC's in the
// receiver's pending set into a new commitment state. Implicitly, the new // receiver's pending set into a new commitment state. Implicitly, the new
@ -26,7 +22,7 @@ type CommitSig struct {
// If initiating a new commitment state, this signature should ONLY // If initiating a new commitment state, this signature should ONLY
// cover all of the sending party's pending log updates, and the log // cover all of the sending party's pending log updates, and the log
// updates of the remote party that have been ACK'd. // updates of the remote party that have been ACK'd.
CommitSig *btcec.Signature CommitSig Sig
// HtlcSigs is a signature for each relevant HTLC output within the // HtlcSigs is a signature for each relevant HTLC output within the
// created commitment. The order of the signatures is expected to be // created commitment. The order of the signatures is expected to be
@ -35,7 +31,7 @@ type CommitSig struct {
// sender of this message), a signature for a HTLC timeout transaction // sender of this message), a signature for a HTLC timeout transaction
// should be signed, for each incoming HTLC the HTLC timeout // should be signed, for each incoming HTLC the HTLC timeout
// transaction should be signed. // transaction should be signed.
HtlcSigs []*btcec.Signature HtlcSigs []Sig
} }
// NewCommitSig creates a new empty CommitSig message. // NewCommitSig creates a new empty CommitSig message.

@ -3,7 +3,6 @@ package lnwire
import ( import (
"io" "io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
) )
@ -24,7 +23,7 @@ type FundingCreated struct {
// CommitSig is Alice's signature from Bob's version of the commitment // CommitSig is Alice's signature from Bob's version of the commitment
// transaction. // transaction.
CommitSig *btcec.Signature CommitSig Sig
} }
// A compile time check to ensure FundingCreated implements the lnwire.Message // A compile time check to ensure FundingCreated implements the lnwire.Message

@ -1,10 +1,6 @@
package lnwire package lnwire
import ( import "io"
"io"
"github.com/roasbeef/btcd/btcec"
)
// FundingSigned is sent from Bob (the responder) to Alice (the initiator) // FundingSigned is sent from Bob (the responder) to Alice (the initiator)
// after receiving the funding outpoint and her signature for Bob's version of // after receiving the funding outpoint and her signature for Bob's version of
@ -16,7 +12,7 @@ type FundingSigned struct {
// CommitSig is Bob's signature for Alice's version of the commitment // CommitSig is Bob's signature for Alice's version of the commitment
// transaction. // transaction.
CommitSig *btcec.Signature CommitSig Sig
} }
// A compile time check to ensure FundingSigned implements the lnwire.Message // A compile time check to ensure FundingSigned implements the lnwire.Message

@ -146,7 +146,7 @@ func writeElement(w io.Writer, element interface{}) error {
if _, err := w.Write(b[:]); err != nil { if _, err := w.Write(b[:]); err != nil {
return err return err
} }
case []*btcec.Signature: case []Sig:
var b [2]byte var b [2]byte
numSigs := uint16(len(e)) numSigs := uint16(len(e))
binary.BigEndian.PutUint16(b[:], numSigs) binary.BigEndian.PutUint16(b[:], numSigs)
@ -159,18 +159,9 @@ func writeElement(w io.Writer, element interface{}) error {
return err return err
} }
} }
case *btcec.Signature: case Sig:
if e == nil {
return fmt.Errorf("cannot write nil signature")
}
var b [64]byte
err := SerializeSigToWire(&b, e)
if err != nil {
return err
}
// Write buffer // Write buffer
if _, err = w.Write(b[:]); err != nil { if _, err := w.Write(e[:]); err != nil {
return err return err
} }
case PingPayload: case PingPayload:
@ -469,16 +460,16 @@ func readElement(r io.Reader, element interface{}) error {
*e = f *e = f
case *[]*btcec.Signature: case *[]Sig:
var l [2]byte var l [2]byte
if _, err := io.ReadFull(r, l[:]); err != nil { if _, err := io.ReadFull(r, l[:]); err != nil {
return err return err
} }
numSigs := binary.BigEndian.Uint16(l[:]) numSigs := binary.BigEndian.Uint16(l[:])
var sigs []*btcec.Signature var sigs []Sig
if numSigs > 0 { if numSigs > 0 {
sigs = make([]*btcec.Signature, numSigs) sigs = make([]Sig, numSigs)
for i := 0; i < int(numSigs); i++ { for i := 0; i < int(numSigs); i++ {
if err := readElement(r, &sigs[i]); err != nil { if err := readElement(r, &sigs[i]); err != nil {
return err return err
@ -488,13 +479,8 @@ func readElement(r io.Reader, element interface{}) error {
*e = sigs *e = sigs
case **btcec.Signature: case *Sig:
var b [64]byte if _, err := io.ReadFull(r, e[:]); err != nil {
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
err = DeserializeSigFromWire(e, b)
if err != nil {
return err return err
} }
case *OpaqueReason: case *OpaqueReason:

@ -50,7 +50,7 @@ func (n NodeAlias) String() string {
// announcement via a signature using the advertised node pubkey. // announcement via a signature using the advertised node pubkey.
type NodeAnnouncement struct { type NodeAnnouncement struct {
// Signature is used to prove the ownership of node id. // Signature is used to prove the ownership of node id.
Signature *btcec.Signature Signature Sig
// Features is the list of protocol features this node supports. // Features is the list of protocol features this node supports.
Features *RawFeatureVector Features *RawFeatureVector

@ -11,8 +11,9 @@ var (
testAmount = MilliSatoshi(1) testAmount = MilliSatoshi(1)
testCtlvExpiry = uint32(2) testCtlvExpiry = uint32(2)
testFlags = uint16(2) testFlags = uint16(2)
sig, _ = NewSigFromSignature(testSig)
testChannelUpdate = ChannelUpdate{ testChannelUpdate = ChannelUpdate{
Signature: testSig, Signature: sig,
ShortChannelID: NewShortChanIDFromInt(1), ShortChannelID: NewShortChanIDFromInt(1),
Timestamp: 1, Timestamp: 1,
Flags: 1, Flags: 1,

@ -14,16 +14,16 @@ func TestSignatureSerializeDeserialize(t *testing.T) {
// Local-scoped closure to serialize and deserialize a Signature and // Local-scoped closure to serialize and deserialize a Signature and
// check for errors as well as check if the results are correct. // check for errors as well as check if the results are correct.
signatureSerializeDeserialize := func(e btcec.Signature) error { signatureSerializeDeserialize := func(e btcec.Signature) error {
var b [64]byte sig, err := NewSigFromSignature(&e)
err := SerializeSigToWire(&b, &e)
if err != nil { if err != nil {
return err return err
} }
var e2 *btcec.Signature
err = DeserializeSigFromWire(&e2, b) e2, err := sig.ToSignature()
if err != nil { if err != nil {
return err return err
} }
if e.R.Cmp(e2.R) != 0 { if e.R.Cmp(e2.R) != 0 {
return fmt.Errorf("Pre/post-serialize Rs don't match"+ return fmt.Errorf("Pre/post-serialize Rs don't match"+
": %s, %s", e.R, e2.R) ": %s, %s", e.R, e2.R)