diff --git a/channeldb/graph.go b/channeldb/graph.go index eaf3503c..79258397 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -1982,7 +1982,6 @@ func (l *LightningNode) PubKey() (*btcec.PublicKey, error) { return nil, err } l.pubKey = key - l.pubKey.Curve = nil return key, nil } diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index f3fde1d2..fd471231 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -41,14 +41,9 @@ var ( testFeatures = lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures) ) -func createTestVertex(db *DB) (*LightningNode, error) { +func createLightningNode(db *DB, priv *btcec.PrivateKey) (*LightningNode, error) { updateTime := prand.Int63() - priv, err := btcec.NewPrivateKey(btcec.S256()) - if err != nil { - return nil, err - } - pub := priv.PubKey().SerializeCompressed() n := &LightningNode{ HaveNodeAnnouncement: true, @@ -65,6 +60,15 @@ func createTestVertex(db *DB) (*LightningNode, error) { return n, nil } +func createTestVertex(db *DB) (*LightningNode, error) { + priv, err := btcec.NewPrivateKey(btcec.S256()) + if err != nil { + return nil, err + } + + return createLightningNode(db, priv) +} + func TestNodeInsertionAndDeletion(t *testing.T) { t.Parallel() @@ -3005,3 +3009,54 @@ func compareEdgePolicies(a, b *ChannelEdgePolicy) error { } return nil } + +// TestLightningNodeSigVerifcation checks that we can use the LightningNode's +// pubkey to verify signatures. +func TestLightningNodeSigVerification(t *testing.T) { + t.Parallel() + + // Create some dummy data to sign. + var data [32]byte + if _, err := prand.Read(data[:]); err != nil { + t.Fatalf("unable to read prand: %v", err) + } + + // Create private key and sign the data with it. + priv, err := btcec.NewPrivateKey(btcec.S256()) + 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) + } + + // Sanity check that the signature checks out. + if !sign.Verify(data[:], priv.PubKey()) { + t.Fatalf("signature doesn't check out") + } + + // Create a LightningNode from the same private key. + db, cleanUp, err := makeTestDB() + if err != nil { + t.Fatalf("unable to make test database: %v", err) + } + defer cleanUp() + + node, err := createLightningNode(db, priv) + if err != nil { + t.Fatalf("unable to create node: %v", err) + } + + // And finally check that we can verify the same signature from the + // pubkey returned from the lightning node. + nodePub, err := node.PubKey() + if err != nil { + t.Fatalf("unable to get pubkey: %v", err) + } + + if !sign.Verify(data[:], nodePub) { + t.Fatalf("unable to verify sig") + } +}