mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 13:52:55 +02:00
derive nodeID/addr from the nodes pubKey
This commit is contained in:
12
sphinx.go
12
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,
|
||||
|
6
sphinx_test.go
Normal file
6
sphinx_test.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSphinxCorrectness(t *testing.T) {
|
||||
}
|
Reference in New Issue
Block a user