use ecies for registerpayment in itest

This commit is contained in:
Jesse de Wit
2022-12-15 15:25:45 +01:00
parent 5cee5f3ec9
commit 18af318798

View File

@@ -12,10 +12,10 @@ import (
"strings" "strings"
"github.com/breez/lntest" "github.com/breez/lntest"
"github.com/breez/lspd/btceclegacy"
lspd "github.com/breez/lspd/rpc" lspd "github.com/breez/lspd/rpc"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/decred/dcrd/dcrec/secp256k1/v4" "github.com/decred/dcrd/dcrec/secp256k1/v4"
ecies "github.com/ecies/go/v2"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
@@ -39,6 +39,7 @@ var (
type LspNode interface { type LspNode interface {
Harness() *lntest.TestHarness Harness() *lntest.TestHarness
PublicKey() *btcec.PublicKey PublicKey() *btcec.PublicKey
EciesPublicKey() *ecies.PublicKey
Rpc() lspd.ChannelOpenerClient Rpc() lspd.ChannelOpenerClient
NodeId() []byte NodeId() []byte
LightningNode() lntest.LightningNode LightningNode() lntest.LightningNode
@@ -49,6 +50,7 @@ type ClnLspNode struct {
lightningNode *lntest.CoreLightningNode lightningNode *lntest.CoreLightningNode
rpc lspd.ChannelOpenerClient rpc lspd.ChannelOpenerClient
publicKey btcec.PublicKey publicKey btcec.PublicKey
eciesPublicKey ecies.PublicKey
postgresBackend *PostgresContainer postgresBackend *PostgresContainer
} }
@@ -60,6 +62,10 @@ func (c *ClnLspNode) PublicKey() *btcec.PublicKey {
return &c.publicKey return &c.publicKey
} }
func (c *ClnLspNode) EciesPublicKey() *ecies.PublicKey {
return &c.eciesPublicKey
}
func (c *ClnLspNode) Rpc() lspd.ChannelOpenerClient { func (c *ClnLspNode) Rpc() lspd.ChannelOpenerClient {
return c.rpc return c.rpc
} }
@@ -86,6 +92,7 @@ type LndLspNode struct {
lightningNode *lntest.LndNode lightningNode *lntest.LndNode
rpc lspd.ChannelOpenerClient rpc lspd.ChannelOpenerClient
publicKey btcec.PublicKey publicKey btcec.PublicKey
eciesPublicKey ecies.PublicKey
postgresBackend *PostgresContainer postgresBackend *PostgresContainer
logFile *os.File logFile *os.File
lspdCmd *exec.Cmd lspdCmd *exec.Cmd
@@ -99,6 +106,10 @@ func (c *LndLspNode) PublicKey() *btcec.PublicKey {
return &c.publicKey return &c.publicKey
} }
func (c *LndLspNode) EciesPublicKey() *ecies.PublicKey {
return &c.eciesPublicKey
}
func (c *LndLspNode) Rpc() lspd.ChannelOpenerClient { func (c *LndLspNode) Rpc() lspd.ChannelOpenerClient {
return c.rpc return c.rpc
} }
@@ -135,7 +146,7 @@ func (l *LndLspNode) LightningNode() lntest.LightningNode {
} }
func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode { func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode {
scriptFilePath, grpcAddress, publ, postgresBackend := setupLspd(h, name, "RUN_CLN=true") scriptFilePath, grpcAddress, publ, eciesPubl, postgresBackend := setupLspd(h, name, "RUN_CLN=true")
args := []string{ args := []string{
fmt.Sprintf("--plugin=%s", scriptFilePath), fmt.Sprintf("--plugin=%s", scriptFilePath),
fmt.Sprintf("--fee-base=%d", lspBaseFeeMsat), fmt.Sprintf("--fee-base=%d", lspBaseFeeMsat),
@@ -161,6 +172,7 @@ func NewClnLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
lightningNode: lightningNode, lightningNode: lightningNode,
rpc: client, rpc: client,
publicKey: *publ, publicKey: *publ,
eciesPublicKey: *eciesPubl,
postgresBackend: postgresBackend, postgresBackend: postgresBackend,
} }
@@ -183,7 +195,7 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
lightningNode := lntest.NewLndNode(h, m, name, args...) lightningNode := lntest.NewLndNode(h, m, name, args...)
tlsCert := strings.Replace(string(lightningNode.TlsCert()), "\n", "\\n", -1) tlsCert := strings.Replace(string(lightningNode.TlsCert()), "\n", "\\n", -1)
scriptFilePath, grpcAddress, publ, postgresBackend := setupLspd(h, name, scriptFilePath, grpcAddress, publ, eciesPubl, postgresBackend := setupLspd(h, name,
"RUN_LND=true", "RUN_LND=true",
fmt.Sprintf("LND_CERT=\"%s\"", tlsCert), fmt.Sprintf("LND_CERT=\"%s\"", tlsCert),
fmt.Sprintf("LND_ADDRESS=%s", lightningNode.GrpcHost()), fmt.Sprintf("LND_ADDRESS=%s", lightningNode.GrpcHost()),
@@ -218,6 +230,7 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
lightningNode: lightningNode, lightningNode: lightningNode,
rpc: client, rpc: client,
publicKey: *publ, publicKey: *publ,
eciesPublicKey: *eciesPubl,
postgresBackend: postgresBackend, postgresBackend: postgresBackend,
logFile: logFile, logFile: logFile,
lspdCmd: lspdCmd, lspdCmd: lspdCmd,
@@ -228,7 +241,7 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
return lspNode return lspNode
} }
func setupLspd(h *lntest.TestHarness, name string, envExt ...string) (string, string, *secp256k1.PublicKey, *PostgresContainer) { func setupLspd(h *lntest.TestHarness, name string, envExt ...string) (string, string, *secp256k1.PublicKey, *ecies.PublicKey, *PostgresContainer) {
scriptDir := h.GetDirectory(fmt.Sprintf("lspd-%s", name)) scriptDir := h.GetDirectory(fmt.Sprintf("lspd-%s", name))
log.Printf("%s: Creating LSPD in dir %s", name, scriptDir) log.Printf("%s: Creating LSPD in dir %s", name, scriptDir)
migrationsDir, err := getMigrationsDir() migrationsDir, err := getMigrationsDir()
@@ -249,6 +262,7 @@ func setupLspd(h *lntest.TestHarness, name string, envExt ...string) (string, st
lntest.CheckError(h.T, err) lntest.CheckError(h.T, err)
_, publ := btcec.PrivKeyFromBytes(lspdPrivateKeyBytes) _, publ := btcec.PrivKeyFromBytes(lspdPrivateKeyBytes)
eciesPubl := ecies.NewPrivateKeyFromBytes(lspdPrivateKeyBytes).PublicKey
host := "localhost" host := "localhost"
grpcAddress := fmt.Sprintf("%s:%d", host, lspdPort) grpcAddress := fmt.Sprintf("%s:%d", host, lspdPort)
env := []string{ env := []string{
@@ -284,14 +298,14 @@ func setupLspd(h *lntest.TestHarness, name string, envExt ...string) (string, st
lntest.CheckError(h.T, err) lntest.CheckError(h.T, err)
scriptFile.Close() scriptFile.Close()
return scriptFilePath, grpcAddress, publ, postgresBackend return scriptFilePath, grpcAddress, publ, eciesPubl, postgresBackend
} }
func RegisterPayment(l LspNode, paymentInfo *lspd.PaymentInformation) { func RegisterPayment(l LspNode, paymentInfo *lspd.PaymentInformation) {
serialized, err := proto.Marshal(paymentInfo) serialized, err := proto.Marshal(paymentInfo)
lntest.CheckError(l.Harness().T, err) lntest.CheckError(l.Harness().T, err)
encrypted, err := btceclegacy.Encrypt(l.PublicKey(), serialized) encrypted, err := ecies.Encrypt(l.EciesPublicKey(), serialized)
lntest.CheckError(l.Harness().T, err) lntest.CheckError(l.Harness().T, err)
log.Printf("Registering payment") log.Printf("Registering payment")