multi: use btcd's btcec/v2 and btcutil modules

This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
This commit is contained in:
Oliver Gugger committed 2022-03-09 19:02:37 +01:00
1 parent 8ee9fc837b
commit 7dfe4018ce
350 files changed
+2421 -1289

No files matched your search

+2 -2
View File
@@ -12,10 +12,10 @@ import (
"strings"
"sync"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
+5 -5
View File
@@ -8,10 +8,10 @@ import (
"runtime"
"testing"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/clock"
@@ -35,7 +35,7 @@ var (
0x48, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17,
0x2d, 0xe7, 0x93, 0xe4,
}
privKey, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), key[:])
privKey, pubKey = btcec.PrivKeyFromBytes(key[:])
wireSig, _ = lnwire.NewSigFromSignature(testSig)
@@ -412,7 +412,7 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
// We'll also test that the channel is properly able to hot swap the
// next revocation for the state machine. This tests the initial
// post-funding revocation exchange.
nextRevKey, err := btcec.NewPrivateKey(btcec.S256())
nextRevKey, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to create new private key: %v", err)
}
@@ -756,7 +756,7 @@ func TestChannelStateTransition(t *testing.T) {
// current uncollapsed revocation state to simulate a state transition
// by the remote party.
channel.RemoteCurrentRevocation = channel.RemoteNextRevocation
newPriv, err := btcec.NewPrivateKey(btcec.S256())
newPriv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to generate key: %v", err)
}
+4 -4
View File
@@ -7,10 +7,10 @@ import (
"io"
"net"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/shachain"
@@ -346,7 +346,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), b[:])
priv, _ := btcec.PrivKeyFromBytes(b[:])
*e = priv
case **btcec.PublicKey:
@@ -355,7 +355,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
pubKey, err := btcec.ParsePubKey(b[:], btcec.S256())
pubKey, err := btcec.ParsePubKey(b[:])
if err != nil {
return err
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"net"
"os"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/go-errors/errors"
mig "github.com/lightningnetwork/lnd/channeldb/migration"
+3 -5
View File
@@ -10,10 +10,10 @@ import (
"reflect"
"testing"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
@@ -300,15 +300,13 @@ func genRandomChannelShell() (*ChannelShell, error) {
return nil, err
}
_, pub := btcec.PrivKeyFromBytes(btcec.S256(), testPriv[:])
_, pub := btcec.PrivKeyFromBytes(testPriv[:])
var chanPoint wire.OutPoint
if _, err := rand.Read(chanPoint.Hash[:]); err != nil {
return nil, err
}
pub.Curve = nil
chanPoint.Index = uint32(rand.Intn(math.MaxUint16))
chanStatus := ChanStatusDefault | ChanStatusRestored
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"io"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
+25 -24
View File
@@ -14,11 +14,12 @@ import (
"sync"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/batch"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
@@ -2660,7 +2661,7 @@ func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
return l.pubKey, nil
}
key, err := btcec.ParsePubKey(l.PubKeyBytes[:], btcec.S256())
key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
if err != nil {
return nil, err
}
@@ -2674,8 +2675,8 @@ func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (l *LightningNode) AuthSig() (*btcec.Signature, error) {
return btcec.ParseSignature(l.AuthSigBytes, btcec.S256())
func (l *LightningNode) AuthSig() (*ecdsa.Signature, error) {
return ecdsa.ParseSignature(l.AuthSigBytes)
}
// AddPubKey is a setter-link method that can be used to swap out the public
@@ -3104,7 +3105,7 @@ func (c *ChannelEdgeInfo) NodeKey1() (*btcec.PublicKey, error) {
return c.nodeKey1, nil
}
key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:], btcec.S256())
key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:])
if err != nil {
return nil, err
}
@@ -3126,7 +3127,7 @@ func (c *ChannelEdgeInfo) NodeKey2() (*btcec.PublicKey, error) {
return c.nodeKey2, nil
}
key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:], btcec.S256())
key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:])
if err != nil {
return nil, err
}
@@ -3146,7 +3147,7 @@ func (c *ChannelEdgeInfo) BitcoinKey1() (*btcec.PublicKey, error) {
return c.bitcoinKey1, nil
}
key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:], btcec.S256())
key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:])
if err != nil {
return nil, err
}
@@ -3166,7 +3167,7 @@ func (c *ChannelEdgeInfo) BitcoinKey2() (*btcec.PublicKey, error) {
return c.bitcoinKey2, nil
}
key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:], btcec.S256())
key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:])
if err != nil {
return nil, err
}
@@ -3249,28 +3250,28 @@ func (c *ChannelEdgeInfo) FetchOtherNode(tx kvdb.RTx,
// features.
type ChannelAuthProof struct {
// nodeSig1 is a cached instance of the first node signature.
nodeSig1 *btcec.Signature
nodeSig1 *ecdsa.Signature
// NodeSig1Bytes are the raw bytes of the first node signature encoded
// in DER format.
NodeSig1Bytes []byte
// nodeSig2 is a cached instance of the second node signature.
nodeSig2 *btcec.Signature
nodeSig2 *ecdsa.Signature
// NodeSig2Bytes are the raw bytes of the second node signature
// encoded in DER format.
NodeSig2Bytes []byte
// bitcoinSig1 is a cached instance of the first bitcoin signature.
bitcoinSig1 *btcec.Signature
bitcoinSig1 *ecdsa.Signature
// BitcoinSig1Bytes are the raw bytes of the first bitcoin signature
// encoded in DER format.
BitcoinSig1Bytes []byte
// bitcoinSig2 is a cached instance of the second bitcoin signature.
bitcoinSig2 *btcec.Signature
bitcoinSig2 *ecdsa.Signature
// BitcoinSig2Bytes are the raw bytes of the second bitcoin signature
// encoded in DER format.
@@ -3283,12 +3284,12 @@ type ChannelAuthProof struct {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (c *ChannelAuthProof) Node1Sig() (*btcec.Signature, error) {
func (c *ChannelAuthProof) Node1Sig() (*ecdsa.Signature, error) {
if c.nodeSig1 != nil {
return c.nodeSig1, nil
}
sig, err := btcec.ParseSignature(c.NodeSig1Bytes, btcec.S256())
sig, err := ecdsa.ParseSignature(c.NodeSig1Bytes)
if err != nil {
return nil, err
}
@@ -3304,12 +3305,12 @@ func (c *ChannelAuthProof) Node1Sig() (*btcec.Signature, error) {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (c *ChannelAuthProof) Node2Sig() (*btcec.Signature, error) {
func (c *ChannelAuthProof) Node2Sig() (*ecdsa.Signature, error) {
if c.nodeSig2 != nil {
return c.nodeSig2, nil
}
sig, err := btcec.ParseSignature(c.NodeSig2Bytes, btcec.S256())
sig, err := ecdsa.ParseSignature(c.NodeSig2Bytes)
if err != nil {
return nil, err
}
@@ -3324,12 +3325,12 @@ func (c *ChannelAuthProof) Node2Sig() (*btcec.Signature, error) {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (c *ChannelAuthProof) BitcoinSig1() (*btcec.Signature, error) {
func (c *ChannelAuthProof) BitcoinSig1() (*ecdsa.Signature, error) {
if c.bitcoinSig1 != nil {
return c.bitcoinSig1, nil
}
sig, err := btcec.ParseSignature(c.BitcoinSig1Bytes, btcec.S256())
sig, err := ecdsa.ParseSignature(c.BitcoinSig1Bytes)
if err != nil {
return nil, err
}
@@ -3344,12 +3345,12 @@ func (c *ChannelAuthProof) BitcoinSig1() (*btcec.Signature, error) {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (c *ChannelAuthProof) BitcoinSig2() (*btcec.Signature, error) {
func (c *ChannelAuthProof) BitcoinSig2() (*ecdsa.Signature, error) {
if c.bitcoinSig2 != nil {
return c.bitcoinSig2, nil
}
sig, err := btcec.ParseSignature(c.BitcoinSig2Bytes, btcec.S256())
sig, err := ecdsa.ParseSignature(c.BitcoinSig2Bytes)
if err != nil {
return nil, err
}
@@ -3381,7 +3382,7 @@ type ChannelEdgePolicy struct {
SigBytes []byte
// sig is a cached fully parsed signature.
sig *btcec.Signature
sig *ecdsa.Signature
// ChannelID is the unique channel ID for the channel. The first 3
// bytes are the block height, the next 3 the index within the block,
@@ -3441,12 +3442,12 @@ type ChannelEdgePolicy struct {
//
// NOTE: By having this method to access an attribute, we ensure we only need
// to fully deserialize the signature if absolutely necessary.
func (c *ChannelEdgePolicy) Signature() (*btcec.Signature, error) {
func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error) {
if c.sig != nil {
return c.sig, nil
}
sig, err := btcec.ParseSignature(c.SigBytes, btcec.S256())
sig, err := ecdsa.ParseSignature(c.SigBytes)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"sync"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
+14 -15
View File
@@ -3,12 +3,12 @@ package channeldb
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"image/color"
"io/ioutil"
"math"
"math/big"
prand "math/rand"
"net"
"os"
@@ -18,10 +18,11 @@ import (
"testing"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
@@ -36,12 +37,13 @@ var (
"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
testAddrs = []net.Addr{testAddr, anotherAddr}
testSig = &btcec.Signature{
R: new(big.Int),
S: new(big.Int),
}
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
testRScalar = new(btcec.ModNScalar)
testSScalar = new(btcec.ModNScalar)
_ = testRScalar.SetByteSlice(testRBytes)
_ = testSScalar.SetByteSlice(testSBytes)
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
testFeatures = lnwire.NewFeatureVector(
lnwire.NewRawFeatureVector(lnwire.GossipQueriesRequired),
@@ -114,7 +116,7 @@ func createLightningNode(db kvdb.Backend, priv *btcec.PrivateKey) (*LightningNod
}
func createTestVertex(db kvdb.Backend) (*LightningNode, error) {
priv, err := btcec.NewPrivateKey(btcec.S256())
priv, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}
@@ -3491,15 +3493,12 @@ func TestLightningNodeSigVerification(t *testing.T) {
}
// Create private key and sign the data with it.
priv, err := btcec.NewPrivateKey(btcec.S256())
priv, err := btcec.NewPrivateKey()
if err != nil {
t.Fatalf("unable to crete priv key: %v", err)
}
sign, err := priv.Sign(data[:])
if err != nil {
t.Fatalf("unable to sign: %v", err)
}
sign := ecdsa.Sign(priv, data[:])
// Sanity check that the signature checks out.
if !sign.Verify(data[:], priv.PubKey()) {
@@ -3,8 +3,8 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
)
// AcceptChannel is the message Bob sends to Alice after she initiates the
@@ -3,7 +3,7 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
)
// ChannelReestablish is a message sent between peers that have an existing
@@ -3,7 +3,7 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)
// ClosingSigned is sent by both parties to a channel once the channel is clear
@@ -3,7 +3,7 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
)
// FundingLocked is the message that both parties to a new channel creation
+3 -3
View File
@@ -9,10 +9,10 @@ import (
"math"
"net"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/tor"
)
@@ -529,7 +529,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
pubKey, err := btcec.ParsePubKey(b[:], btcec.S256())
pubKey, err := btcec.ParsePubKey(b[:])
if err != nil {
return err
}
+1 -1
View File
@@ -3,7 +3,7 @@ package lnwire
import (
"fmt"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
)
const (
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"net"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
)
+2 -2
View File
@@ -3,9 +3,9 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil"
)
// FundingFlag represents the possible bit mask values for the ChannelFlags
@@ -3,7 +3,7 @@ package lnwire
import (
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
)
// RevokeAndAck is sent by either side once a CommitSig message has been
+7 -7
View File
@@ -3,14 +3,14 @@ package lnwire
import (
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/lightningnetwork/lnd/input"
)
// Sig is a fixed-sized ECDSA signature. Unlike Bitcoin, we use fixed sized
// signatures on the wire, instead of DER encoded signatures. This type
// provides several methods to convert to/from a regular Bitcoin DER encoded
// signature (raw bytes and *btcec.Signature).
// signature (raw bytes and *ecdsa.Signature).
type Sig [64]byte
// NewSigFromRawSignature returns a Sig from a Bitcoin raw signature encoded in
@@ -27,7 +27,7 @@ func NewSigFromRawSignature(sig []byte) (Sig, error) {
// which means the length of R is the 4th byte and the length of S
// is the second byte after R ends. 0x02 signifies a length-prefixed,
// zero-padded, big-endian bigint. 0x30 signifies a DER signature.
// See the Serialize() method for btcec.Signature for details.
// See the Serialize() method for ecdsa.Signature for details.
rLen := sig[3]
sLen := sig[5+rLen]
@@ -64,7 +64,7 @@ func NewSigFromRawSignature(sig []byte) (Sig, error) {
}
// NewSigFromSignature creates a new signature as used on the wire, from an
// existing btcec.Signature.
// existing ecdsa.Signature.
func NewSigFromSignature(e input.Signature) (Sig, error) {
if e == nil {
return Sig{}, fmt.Errorf("cannot decode empty signature")
@@ -74,12 +74,12 @@ func NewSigFromSignature(e input.Signature) (Sig, error) {
return NewSigFromRawSignature(e.Serialize())
}
// ToSignature converts the fixed-sized signature to a btcec.Signature objects
// ToSignature converts the fixed-sized signature to a ecdsa.Signature objects
// which can be used for signature validation checks.
func (b *Sig) ToSignature() (*btcec.Signature, error) {
func (b *Sig) ToSignature() (*ecdsa.Signature, error) {
// Parse the signature with strict checks.
sigBytes := b.ToSignatureBytes()
sig, err := btcec.ParseDERSignature(sigBytes, btcec.S256())
sig, err := ecdsa.ParseDERSignature(sigBytes)
if err != nil {
return nil, err
}
@@ -5,10 +5,10 @@ import (
"encoding/binary"
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/keychain"
)
@@ -6,10 +6,10 @@ import (
"fmt"
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/channeldb/migration21/common"
"github.com/lightningnetwork/lnd/keychain"
@@ -317,7 +317,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), b[:])
priv, _ := btcec.PrivKeyFromBytes(b[:])
*e = priv
case **btcec.PublicKey:
@@ -326,7 +326,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
pubKey, err := btcec.ParsePubKey(b[:], btcec.S256())
pubKey, err := btcec.ParsePubKey(b[:])
if err != nil {
return err
}
+3 -3
View File
@@ -5,10 +5,10 @@ import (
"fmt"
"io"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/channeldb/migration21/common"
"github.com/lightningnetwork/lnd/keychain"
@@ -276,7 +276,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
pubKey, err := btcec.ParsePubKey(b[:], btcec.S256())
pubKey, err := btcec.ParsePubKey(b[:])
if err != nil {
return err
}
+11 -19
View File
@@ -2,12 +2,13 @@ package migration21
import (
"bytes"
"encoding/hex"
"fmt"
"math/big"
"reflect"
"testing"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
@@ -27,16 +28,17 @@ var (
0x1e, 0xb, 0x4c, 0xf9, 0x9e, 0xc5, 0x8c, 0xe9,
}
_, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), key[:])
_, pubKey = btcec.PrivKeyFromBytes(key[:])
wireSig, _ = lnwire.NewSigFromSignature(testSig)
testSig = &btcec.Signature{
R: new(big.Int),
S: new(big.Int),
}
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
testRScalar = new(btcec.ModNScalar)
testSScalar = new(btcec.ModNScalar)
_ = testRScalar.SetByteSlice(testRBytes)
_ = testSScalar.SetByteSlice(testSBytes)
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
testTx = &wire.MsgTx{
Version: 1,
@@ -390,16 +392,6 @@ func TestMigrateDatabaseWireMessages(t *testing.T) {
return err
}
testChanCloseSummary.RemotePub.Curve = nil
testChanCloseSummary.RemoteCurrentRevocation.Curve = nil
testChanCloseSummary.RemoteNextRevocation.Curve = nil
testChanCloseSummary.LastChanSyncMsg.LocalUnrevokedCommitPoint.Curve = nil
newChanCloseSummary.RemotePub.Curve = nil
newChanCloseSummary.RemoteCurrentRevocation.Curve = nil
newChanCloseSummary.RemoteNextRevocation.Curve = nil
newChanCloseSummary.LastChanSyncMsg.LocalUnrevokedCommitPoint.Curve = nil
if !reflect.DeepEqual(
newChanCloseSummary, testChanCloseSummary,
) {
+3 -3
View File
@@ -9,10 +9,10 @@ import (
"math/rand"
"testing"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/channeldb/migtest"
@@ -62,7 +62,7 @@ var (
},
LockTime: 5,
}
_, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), key[:])
_, pubKey = btcec.PrivKeyFromBytes(key[:])
)
// TestMigrateFwdPkgCleanup asserts that the migration will delete all the
+2 -2
View File
@@ -8,10 +8,10 @@ import (
"strings"
"sync"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/shachain"
+3 -3
View File
@@ -6,10 +6,10 @@ import (
"math/rand"
"os"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/keychain"
@@ -60,7 +60,7 @@ var (
},
LockTime: 5,
}
privKey, pubKey = btcec.PrivKeyFromBytes(btcec.S256(), key[:])
privKey, pubKey = btcec.PrivKeyFromBytes(key[:])
)
// makeTestDB creates a new instance of the ChannelDB for testing purposes. A
+4 -4
View File
@@ -6,10 +6,10 @@ import (
"io"
"net"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/shachain"
@@ -324,7 +324,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), b[:])
priv, _ := btcec.PrivKeyFromBytes(b[:])
*e = priv
case **btcec.PublicKey:
@@ -333,7 +333,7 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
pubKey, err := btcec.ParsePubKey(b[:], btcec.S256())
pubKey, err := btcec.ParsePubKey(b[:])
if err != nil {
return err
}
+3 -3
View File
@@ -9,10 +9,10 @@ import (
"net"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/kvdb"
)
@@ -384,7 +384,7 @@ func (l *LightningNode) PubKey() (*btcec.PublicKey, error) {
return l.pubKey, nil
}
key, err := btcec.ParsePubKey(l.PubKeyBytes[:], btcec.S256())
key, err := btcec.ParsePubKey(l.PubKeyBytes[:])
if err != nil {
return nil, err
}
+11 -9
View File
@@ -1,13 +1,14 @@
package migration_01_to_11
import (
"encoding/hex"
"image/color"
"math/big"
prand "math/rand"
"net"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
)
@@ -18,12 +19,13 @@ var (
"[2001:db8:85a3:0:0:8a2e:370:7334]:80")
testAddrs = []net.Addr{testAddr, anotherAddr}
testSig = &btcec.Signature{
R: new(big.Int),
S: new(big.Int),
}
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
testRScalar = new(btcec.ModNScalar)
testSScalar = new(btcec.ModNScalar)
_ = testRScalar.SetByteSlice(testRBytes)
_ = testSScalar.SetByteSlice(testSBytes)
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
testFeatures = lnwire.NewFeatureVector(nil, nil)
)
@@ -48,7 +50,7 @@ func createLightningNode(db *DB, priv *btcec.PrivateKey) (*LightningNode, error)
}
func createTestVertex(db *DB) (*LightningNode, error) {
priv, err := btcec.NewPrivateKey(btcec.S256())
priv, err := btcec.NewPrivateKey()
if err != nil {
return nil, err
}
@@ -6,7 +6,8 @@ import (
"testing"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
bitcoinCfg "github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/zpay32"
@@ -150,12 +151,10 @@ func signDigestCompact(hash []byte) ([]byte, error) {
// Should the signature reference a compressed public key or not.
isCompressedKey := true
privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), testPrivKeyBytes)
privKey, _ := btcec.PrivKeyFromBytes(testPrivKeyBytes)
// btcec.SignCompact returns a pubkey-recoverable signature
sig, err := btcec.SignCompact(
btcec.S256(), privKey, hash, isCompressedKey,
)
// ecdsa.SignCompact returns a pubkey-recoverable signature
sig, err := ecdsa.SignCompact(privKey, hash, isCompressedKey)
if err != nil {
return nil, fmt.Errorf("can't sign the hash: %v", err)
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"encoding/binary"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/kvdb"
)
@@ -839,7 +839,7 @@ func MigrateOutgoingPayments(tx kvdb.RwTx) error {
// Since we don't have the session key for old payments, we
// create a random one to be able to serialize the attempt
// info.
priv, _ := btcec.NewPrivateKey(btcec.S256())
priv, _ := btcec.NewPrivateKey()
s := &PaymentAttemptInfo{
PaymentID: 0, // unknown.
SessionKey: priv, // unknown.
@@ -10,7 +10,7 @@ import (
"testing"
"time"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
@@ -440,8 +440,6 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
dbChan := dbChannels[0]
if !reflect.DeepEqual(dbChan, test.closeSummary) {
dbChan.RemotePub.Curve = nil
test.closeSummary.RemotePub.Curve = nil
t.Fatalf("not equal: %v vs %v",
spew.Sdump(dbChan),
spew.Sdump(test.closeSummary))
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"sort"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/kvdb"
@@ -6,12 +6,12 @@ import (
"math/rand"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
)
var (
priv, _ = btcec.NewPrivateKey(btcec.S256())
priv, _ = btcec.NewPrivateKey()
pub = priv.PubKey()
)
+2 -4
View File
@@ -9,7 +9,7 @@ import (
"strconv"
"strings"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
sphinx "github.com/lightningnetwork/lightning-onion"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
"github.com/lightningnetwork/lnd/record"
@@ -246,9 +246,7 @@ func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) {
// to an OnionHop with matching per-hop payload within the path as used
// by the sphinx package.
for i, hop := range r.Hops {
pub, err := btcec.ParsePubKey(
hop.PubKeyBytes[:], btcec.S256(),
)
pub, err := btcec.ParsePubKey(hop.PubKeyBytes[:])
if err != nil {
return nil, err
}
@@ -8,11 +8,12 @@ import (
"strings"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/bech32"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
)
@@ -112,8 +113,7 @@ func Decode(invoice string, net *chaincfg.Params) (*Invoice, error) {
} else {
headerByte := recoveryID + 27 + 4
compactSign := append([]byte{headerByte}, sig[:]...)
pubkey, _, err := btcec.RecoverCompact(btcec.S256(),
compactSign, hash)
pubkey, _, err := ecdsa.RecoverCompact(compactSign, hash)
if err != nil {
return nil, err
}
@@ -350,7 +350,7 @@ func parseDestination(data []byte) (*btcec.PublicKey, error) {
return nil, err
}
return btcec.ParsePubKey(base256Data, btcec.S256())
return btcec.ParsePubKey(base256Data)
}
// parseExpiry converts the data (encoded in base32) into the expiry time.
@@ -452,7 +452,7 @@ func parseRouteHint(data []byte) ([]HopHint, error) {
for len(base256Data) > 0 {
hopHint := HopHint{}
hopHint.NodeID, err = btcec.ParsePubKey(base256Data[:33], btcec.S256())
hopHint.NodeID, err = btcec.ParsePubKey(base256Data[:33])
if err != nil {
return nil, err
}
@@ -1,6 +1,6 @@
package zpay32
import "github.com/btcsuite/btcd/btcec"
import "github.com/btcsuite/btcd/btcec/v2"
const (
// DefaultFinalCLTVDelta is the default value to be used as the final
@@ -5,9 +5,9 @@ import (
"fmt"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
)
@@ -103,7 +103,7 @@ type MessageSigner struct {
// SignCompact signs the passed hash with the node's privkey. The
// returned signature should be 65 bytes, where the last 64 are the
// compact signature, and the first one is a header byte. This is the
// format returned by btcec.SignCompact.
// format returned by ecdsa.SignCompact.
SignCompact func(hash []byte) ([]byte, error)
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"io"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
@@ -68,7 +68,7 @@ func NewHtlcAttemptInfo(attemptID uint64, sessionKey *btcec.PrivateKey,
func (h *HTLCAttemptInfo) SessionKey() *btcec.PrivateKey {
if h.cachedSessionKey == nil {
h.cachedSessionKey, _ = btcec.PrivKeyFromBytes(
btcec.S256(), h.sessionKey[:],
h.sessionKey[:],
)
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"net"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/kvdb"
)
@@ -298,7 +298,7 @@ func deserializeLinkNode(r io.Reader) (*LinkNode, error) {
if _, err := io.ReadFull(r, pub[:]); err != nil {
return nil, err
}
node.IdentityPub, err = btcec.ParsePubKey(pub[:], btcec.S256())
node.IdentityPub, err = btcec.ParsePubKey(pub[:])
if err != nil {
return nil, err
}
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"testing"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
)
@@ -23,8 +23,8 @@ func TestLinkNodeEncodeDecode(t *testing.T) {
// First we'll create some initial data to use for populating our test
// LinkNode instances.
_, pub1 := btcec.PrivKeyFromBytes(btcec.S256(), key[:])
_, pub2 := btcec.PrivKeyFromBytes(btcec.S256(), rev[:])
_, pub1 := btcec.PrivKeyFromBytes(key[:])
_, pub2 := btcec.PrivKeyFromBytes(rev[:])
addr1, err := net.ResolveTCPAddr("tcp", "10.0.0.1:9000")
if err != nil {
t.Fatalf("unable to create test addr: %v", err)
@@ -120,7 +120,7 @@ func TestDeleteLinkNode(t *testing.T) {
cdb := fullDB.ChannelStateDB()
_, pubKey := btcec.PrivKeyFromBytes(btcec.S256(), key[:])
_, pubKey := btcec.PrivKeyFromBytes(key[:])
addr := &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 1337,
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcwallet/walletdb"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/kvdb"
@@ -19,7 +19,7 @@ import (
)
var (
priv, _ = btcec.NewPrivateKey(btcec.S256())
priv, _ = btcec.NewPrivateKey()
pub = priv.PubKey()
testHop1 = &route.Hop{
+1 -1
View File
@@ -5,9 +5,9 @@ import (
"errors"
"io"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/tlv"
)