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
import (
"io"
"github.com/roasbeef/btcd/btcec"
)
import "io"
// AnnounceSignatures this is a direct message between two endpoints of a
// 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
// channel message, by this signature we proof that we possess of the
// 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
// public key, by this signature we proof that we possess of the
// bitcoin key and and creating the reverse reference bitcoin_key ->
// node_key.
BitcoinSignature *btcec.Signature
BitcoinSignature Sig
}
// A compile time check to ensure AnnounceSignatures implements the

@ -4,7 +4,6 @@ import (
"bytes"
"io"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
)
@ -16,14 +15,14 @@ type ChannelAnnouncement struct {
// references between node's channel and node. Requiring both nodes
// to sign indicates they are both willing to route other payments via
// this node.
NodeSig1 *btcec.Signature
NodeSig2 *btcec.Signature
NodeSig1 Sig
NodeSig2 Sig
// This signatures are used by nodes in order to create cross
// references between node's channel and node. Requiring the bitcoin
// signatures proves they control the channel.
BitcoinSig1 *btcec.Signature
BitcoinSig2 *btcec.Signature
BitcoinSig1 Sig
BitcoinSig2 Sig
// 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

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

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

@ -1,10 +1,6 @@
package lnwire
import (
"io"
"github.com/roasbeef/btcd/btcec"
)
import "io"
// 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
@ -26,7 +22,7 @@ type CommitSig struct {
// If initiating a new commitment state, this signature should ONLY
// cover all of the sending party's pending log updates, and the log
// 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
// 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
// should be signed, for each incoming HTLC the HTLC timeout
// transaction should be signed.
HtlcSigs []*btcec.Signature
HtlcSigs []Sig
}
// NewCommitSig creates a new empty CommitSig message.

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

@ -1,10 +1,6 @@
package lnwire
import (
"io"
"github.com/roasbeef/btcd/btcec"
)
import "io"
// FundingSigned is sent from Bob (the responder) to Alice (the initiator)
// 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
// transaction.
CommitSig *btcec.Signature
CommitSig Sig
}
// 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 {
return err
}
case []*btcec.Signature:
case []Sig:
var b [2]byte
numSigs := uint16(len(e))
binary.BigEndian.PutUint16(b[:], numSigs)
@ -159,18 +159,9 @@ func writeElement(w io.Writer, element interface{}) error {
return err
}
}
case *btcec.Signature:
if e == nil {
return fmt.Errorf("cannot write nil signature")
}
var b [64]byte
err := SerializeSigToWire(&b, e)
if err != nil {
return err
}
case Sig:
// Write buffer
if _, err = w.Write(b[:]); err != nil {
if _, err := w.Write(e[:]); err != nil {
return err
}
case PingPayload:
@ -469,16 +460,16 @@ func readElement(r io.Reader, element interface{}) error {
*e = f
case *[]*btcec.Signature:
case *[]Sig:
var l [2]byte
if _, err := io.ReadFull(r, l[:]); err != nil {
return err
}
numSigs := binary.BigEndian.Uint16(l[:])
var sigs []*btcec.Signature
var sigs []Sig
if numSigs > 0 {
sigs = make([]*btcec.Signature, numSigs)
sigs = make([]Sig, numSigs)
for i := 0; i < int(numSigs); i++ {
if err := readElement(r, &sigs[i]); err != nil {
return err
@ -488,13 +479,8 @@ func readElement(r io.Reader, element interface{}) error {
*e = sigs
case **btcec.Signature:
var b [64]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
return err
}
err = DeserializeSigFromWire(e, b)
if err != nil {
case *Sig:
if _, err := io.ReadFull(r, e[:]); err != nil {
return err
}
case *OpaqueReason:

@ -50,7 +50,7 @@ func (n NodeAlias) String() string {
// announcement via a signature using the advertised node pubkey.
type NodeAnnouncement struct {
// 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 *RawFeatureVector

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

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