From 9d39ffbdd844923f85cb1138a2a8dbb7666403a7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 22 Oct 2015 12:23:01 -0700 Subject: [PATCH] derive nodeID/addr from the nodes pubKey --- sphinx.go | 12 ++++++++++-- sphinx_test.go | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 sphinx_test.go diff --git a/sphinx.go b/sphinx.go index 038b10706..a84b0bcf7 100644 --- a/sphinx.go +++ b/sphinx.go @@ -10,6 +10,7 @@ import ( "math/big" "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil/base58" ) @@ -295,6 +296,7 @@ func xor(dst, a, b []byte) int { // generateKey... // used to key rand padding generation, mac, and lionness +// TODO(roasbeef): comment... func generateKey(keyType string, sharedKey [sharedSecretSize]byte) [securityParameter]byte { mac := hmac.New(sha256.New, []byte(keyType)) mac.Write(sharedKey[:]) @@ -368,14 +370,20 @@ type processMsgAction struct { type SphinxNode struct { nodeID [securityParameter]byte // TODO(roasbeef): swap out with btcutil.AddressLightningKey maybe? - nodeAddr []byte + nodeAddr *btcutil.AddressPubKeyHash lnKey *btcec.PrivateKey seenSecrets map[[sharedSecretSize]byte]struct{} } // NewSphinxNode... -func NewSphinxNode(nodeID [securityParameter]byte, nodeAddr LightningAddress, nodeKey *btcec.PrivateKey) *SphinxNode { +func NewSphinxNode(nodeKey *btcec.PrivateKey, net *chaincfg.Params) *SphinxNode { + var nodeID [securityParameter]byte + copy(nodeID[:], btcutil.Hash160(nodeKey.PubKey().SerializeCompressed())) + + // Safe to ignore the error here, nodeID is 20 bytes. + nodeAddr, _ := btcutil.NewAddressPubKeyHash(nodeID[:], net) + return &SphinxNode{ nodeID: nodeID, nodeAddr: nodeAddr, diff --git a/sphinx_test.go b/sphinx_test.go new file mode 100644 index 000000000..eedf09b53 --- /dev/null +++ b/sphinx_test.go @@ -0,0 +1,6 @@ +package main + +import "testing" + +func TestSphinxCorrectness(t *testing.T) { +}