diff --git a/lnwire/announcement_signatures.go b/lnwire/announcement_signatures.go index fabefadd..748f29b1 100644 --- a/lnwire/announcement_signatures.go +++ b/lnwire/announcement_signatures.go @@ -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 diff --git a/lnwire/channel_announcement.go b/lnwire/channel_announcement.go index 29dbb39a..ed776ca7 100644 --- a/lnwire/channel_announcement.go +++ b/lnwire/channel_announcement.go @@ -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 diff --git a/lnwire/channel_update.go b/lnwire/channel_update.go index 0243cc68..cf6482a2 100644 --- a/lnwire/channel_update.go +++ b/lnwire/channel_update.go @@ -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. diff --git a/lnwire/closing_signed.go b/lnwire/closing_signed.go index 087f879b..81a7d1b5 100644 --- a/lnwire/closing_signed.go +++ b/lnwire/closing_signed.go @@ -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, diff --git a/lnwire/commit_sig.go b/lnwire/commit_sig.go index 0d966e53..a66a0dae 100644 --- a/lnwire/commit_sig.go +++ b/lnwire/commit_sig.go @@ -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. diff --git a/lnwire/funding_created.go b/lnwire/funding_created.go index b9481ebf..66f36fc0 100644 --- a/lnwire/funding_created.go +++ b/lnwire/funding_created.go @@ -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 diff --git a/lnwire/funding_signed.go b/lnwire/funding_signed.go index 7e795986..19f3ba8f 100644 --- a/lnwire/funding_signed.go +++ b/lnwire/funding_signed.go @@ -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 diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index 450b8b21..5e486582 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -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: diff --git a/lnwire/node_announcement.go b/lnwire/node_announcement.go index 1eaeade3..3f6988f7 100644 --- a/lnwire/node_announcement.go +++ b/lnwire/node_announcement.go @@ -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 diff --git a/lnwire/onion_error_test.go b/lnwire/onion_error_test.go index 7817f677..6d68991b 100644 --- a/lnwire/onion_error_test.go +++ b/lnwire/onion_error_test.go @@ -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, diff --git a/lnwire/signature_test.go b/lnwire/signature_test.go index 0b5b3775..2e27e135 100644 --- a/lnwire/signature_test.go +++ b/lnwire/signature_test.go @@ -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)