mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
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:
@@ -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"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -121,8 +122,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
|
||||
}
|
||||
@@ -359,7 +359,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.
|
||||
@@ -461,7 +461,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
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package zpay32
|
||||
|
||||
import "github.com/btcsuite/btcd/btcec"
|
||||
import "github.com/btcsuite/btcd/btcec/v2"
|
||||
|
||||
const (
|
||||
// DefaultAssumedFinalCLTVDelta is the default value to be used as the
|
||||
|
||||
@@ -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"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -103,7 +103,7 @@ type MessageSigner struct {
|
||||
// SignCompact signs the hash of the passed msg 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(msg []byte) ([]byte, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/btcutil/bech32"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -452,7 +452,8 @@ func TestParseDestination(t *testing.T) {
|
||||
if test.valid && !comparePubkeys(destination, test.result) {
|
||||
t.Fatalf("test %d failed decoding destination: "+
|
||||
"expected %x, got %x",
|
||||
i, *test.result, *destination)
|
||||
i, test.result.SerializeCompressed(),
|
||||
destination.SerializeCompressed())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,12 @@ 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"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
||||
)
|
||||
@@ -55,7 +56,7 @@ var (
|
||||
testPleaseConsider = "Please consider supporting this project"
|
||||
|
||||
testPrivKeyBytes, _ = hex.DecodeString("e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734")
|
||||
testPrivKey, testPubKey = btcec.PrivKeyFromBytes(btcec.S256(), testPrivKeyBytes)
|
||||
testPrivKey, testPubKey = btcec.PrivKeyFromBytes(testPrivKeyBytes)
|
||||
|
||||
testDescriptionHashSlice = chainhash.HashB([]byte("One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"))
|
||||
|
||||
@@ -69,9 +70,9 @@ var (
|
||||
testAddrMainnetP2WSH, _ = btcutil.DecodeAddress("bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3", &chaincfg.MainNetParams)
|
||||
|
||||
testHopHintPubkeyBytes1, _ = hex.DecodeString("029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255")
|
||||
testHopHintPubkey1, _ = btcec.ParsePubKey(testHopHintPubkeyBytes1, btcec.S256())
|
||||
testHopHintPubkey1, _ = btcec.ParsePubKey(testHopHintPubkeyBytes1)
|
||||
testHopHintPubkeyBytes2, _ = hex.DecodeString("039e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255")
|
||||
testHopHintPubkey2, _ = btcec.ParsePubKey(testHopHintPubkeyBytes2, btcec.S256())
|
||||
testHopHintPubkey2, _ = btcec.ParsePubKey(testHopHintPubkeyBytes2)
|
||||
|
||||
testSingleHop = []HopHint{
|
||||
{
|
||||
@@ -102,9 +103,7 @@ var (
|
||||
testMessageSigner = MessageSigner{
|
||||
SignCompact: func(msg []byte) ([]byte, error) {
|
||||
hash := chainhash.HashB(msg)
|
||||
sig, err := btcec.SignCompact(
|
||||
btcec.S256(), testPrivKey, hash, true,
|
||||
)
|
||||
sig, err := ecdsa.SignCompact(testPrivKey, hash, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't sign the "+
|
||||
"message: %v", err)
|
||||
@@ -914,11 +913,11 @@ func TestInvoiceChecksumMalleability(t *testing.T) {
|
||||
var payHash [32]byte
|
||||
ts := time.Unix(0, 0)
|
||||
|
||||
privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), privKeyBytes)
|
||||
privKey, _ := btcec.PrivKeyFromBytes(privKeyBytes)
|
||||
msgSigner := MessageSigner{
|
||||
SignCompact: func(msg []byte) ([]byte, error) {
|
||||
hash := chainhash.HashB(msg)
|
||||
return btcec.SignCompact(btcec.S256(), privKey, hash, true)
|
||||
return ecdsa.SignCompact(privKey, hash, true)
|
||||
},
|
||||
}
|
||||
opts := []func(*Invoice){Description("test")}
|
||||
@@ -981,7 +980,8 @@ func compareInvoices(expected, actual *Invoice) error {
|
||||
|
||||
if !comparePubkeys(expected.Destination, actual.Destination) {
|
||||
return fmt.Errorf("expected destination pubkey %x, got %x",
|
||||
expected.Destination, actual.Destination)
|
||||
expected.Destination.SerializeCompressed(),
|
||||
actual.Destination.SerializeCompressed())
|
||||
}
|
||||
|
||||
if !compareHashes(expected.DescriptionHash, actual.DescriptionHash) {
|
||||
@@ -1054,7 +1054,8 @@ func compareRouteHints(a, b []HopHint) error {
|
||||
for i := 0; i < len(a); i++ {
|
||||
if !comparePubkeys(a[i].NodeID, b[i].NodeID) {
|
||||
return fmt.Errorf("expected routeHint nodeID %x, "+
|
||||
"got %x", a[i].NodeID, b[i].NodeID)
|
||||
"got %x", a[i].NodeID.SerializeCompressed(),
|
||||
b[i].NodeID.SerializeCompressed())
|
||||
}
|
||||
|
||||
if a[i].ChannelID != b[i].ChannelID {
|
||||
|
||||
Reference in New Issue
Block a user