mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 23:21:12 +02:00
lnd+server+netann: use signing interface in node signer
This commit is contained in:
@@ -6,25 +6,21 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
)
|
||||
|
||||
// NodeSigner is an implementation of the MessageSigner interface backed by the
|
||||
// identity private key of running lnd node.
|
||||
type NodeSigner struct {
|
||||
privKey *btcec.PrivateKey
|
||||
keySigner keychain.SingleKeyDigestSigner
|
||||
}
|
||||
|
||||
// NewNodeSigner creates a new instance of the NodeSigner backed by the target
|
||||
// private key.
|
||||
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
|
||||
func NewNodeSigner(keySigner keychain.SingleKeyDigestSigner) *NodeSigner {
|
||||
return &NodeSigner{
|
||||
privKey: priv,
|
||||
keySigner: keySigner,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +32,14 @@ func (n *NodeSigner) SignMessage(pubKey *btcec.PublicKey,
|
||||
|
||||
// If this isn't our identity public key, then we'll exit early with an
|
||||
// error as we can't sign with this key.
|
||||
if !pubKey.IsEqual(n.privKey.PubKey()) {
|
||||
if !pubKey.IsEqual(n.keySigner.PubKey()) {
|
||||
return nil, fmt.Errorf("unknown public key")
|
||||
}
|
||||
|
||||
// Otherwise, we'll sign the dsha256 of the target message.
|
||||
digest := chainhash.DoubleHashB(msg)
|
||||
sig, err := n.privKey.Sign(digest)
|
||||
var digest [32]byte
|
||||
copy(digest[:], chainhash.DoubleHashB(msg))
|
||||
sig, err := n.keySigner.SignDigest(digest)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't sign the message: %v", err)
|
||||
}
|
||||
@@ -63,14 +60,11 @@ 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) {
|
||||
var digest [32]byte
|
||||
copy(digest[:], hash)
|
||||
|
||||
// Should the signature reference a compressed public key or not.
|
||||
isCompressedKey := true
|
||||
|
||||
// btcec.SignCompact returns a pubkey-recoverable signature
|
||||
sig, err := btcec.SignCompact(
|
||||
btcec.S256(), n.privKey, hash, isCompressedKey,
|
||||
)
|
||||
// keychain.SignDigestCompact returns a pubkey-recoverable signature.
|
||||
sig, err := n.keySigner.SignDigestCompact(digest)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't sign the hash: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user