diff --git a/nodesigner.go b/netann/node_signer.go similarity index 77% rename from nodesigner.go rename to netann/node_signer.go index b40bce487..8946c2c6b 100644 --- a/nodesigner.go +++ b/netann/node_signer.go @@ -1,4 +1,4 @@ -package main +package netann import ( "fmt" @@ -8,21 +8,21 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" ) -// nodeSigner is an implementation of the MessageSigner interface backed by the +// NodeSigner is an implementation of the MessageSigner interface backed by the // identity private key of running lnd node. -type nodeSigner struct { +type NodeSigner struct { privKey *btcec.PrivateKey } -// newNodeSigner creates a new instance of the nodeSigner backed by the target +// NewNodeSigner creates a new instance of the NodeSigner backed by the target // private key. -func newNodeSigner(key *btcec.PrivateKey) *nodeSigner { +func NewNodeSigner(key *btcec.PrivateKey) *NodeSigner { priv := &btcec.PrivateKey{} priv.Curve = btcec.S256() priv.PublicKey.X = key.X priv.PublicKey.Y = key.Y priv.D = key.D - return &nodeSigner{ + return &NodeSigner{ privKey: priv, } } @@ -30,7 +30,7 @@ func newNodeSigner(key *btcec.PrivateKey) *nodeSigner { // SignMessage signs a double-sha256 digest of the passed msg under the // resident node's private key. If the target public key is _not_ the node's // private key, then an error will be returned. -func (n *nodeSigner) SignMessage(pubKey *btcec.PublicKey, +func (n *NodeSigner) SignMessage(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error) { // If this isn't our identity public key, then we'll exit early with an @@ -52,7 +52,7 @@ func (n *nodeSigner) SignMessage(pubKey *btcec.PublicKey, // SignCompact signs a double-sha256 digest of the msg parameter under the // resident node's private key. The returned signature is a pubkey-recoverable // signature. -func (n *nodeSigner) SignCompact(msg []byte) ([]byte, error) { +func (n *NodeSigner) SignCompact(msg []byte) ([]byte, error) { // We'll sign the dsha256 of the target message. digest := chainhash.DoubleHashB(msg) @@ -61,7 +61,7 @@ func (n *nodeSigner) SignCompact(msg []byte) ([]byte, error) { // SignDigestCompact signs the provided message digest under the resident // node's private key. The returned signature is a pubkey-recoverable signature. -func (n *nodeSigner) SignDigestCompact(hash []byte) ([]byte, error) { +func (n *NodeSigner) SignDigestCompact(hash []byte) ([]byte, error) { // Should the signature reference a compressed public key or not. isCompressedKey := true @@ -77,6 +77,6 @@ func (n *nodeSigner) SignDigestCompact(hash []byte) ([]byte, error) { return sig, nil } -// A compile time check to ensure that nodeSigner implements the MessageSigner +// A compile time check to ensure that NodeSigner implements the MessageSigner // interface. -var _ lnwallet.MessageSigner = (*nodeSigner)(nil) +var _ lnwallet.MessageSigner = (*NodeSigner)(nil) diff --git a/server.go b/server.go index c3378839b..a55f2f607 100644 --- a/server.go +++ b/server.go @@ -38,6 +38,7 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/nat" + "github.com/lightningnetwork/lnd/netann" "github.com/lightningnetwork/lnd/routing" "github.com/lightningnetwork/lnd/sweep" "github.com/lightningnetwork/lnd/ticker" @@ -84,7 +85,7 @@ type server struct { // nodeSigner is an implementation of the MessageSigner implementation // that's backed by the identity private key of the running lnd node. - nodeSigner *nodeSigner + nodeSigner *netann.NodeSigner // listenAddrs is the list of addresses the server is currently // listening on. @@ -266,7 +267,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, invoices: invoices.NewRegistry(chanDB, activeNetParams.Params), identityPriv: privKey, - nodeSigner: newNodeSigner(privKey), + nodeSigner: netann.NewNodeSigner(privKey), listenAddrs: listenAddrs, @@ -754,7 +755,6 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, maxRemoteDelay = maxLtcRemoteDelay } - nodeSigner := newNodeSigner(privKey) var chanIDSeed [32]byte if _, err := rand.Read(chanIDSeed[:]); err != nil { return nil, err @@ -769,7 +769,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, msg []byte) (*btcec.Signature, error) { if pubKey.IsEqual(privKey.PubKey()) { - return nodeSigner.SignMessage(pubKey, msg) + return s.nodeSigner.SignMessage(pubKey, msg) } return cc.msgSigner.SignMessage(pubKey, msg)