rpc: add SignMessage and VerifyMessage interface
This commit allows users to sign messages with their node's private key with the SignMessage interface. The signatures are zbase32 encoded for human readability/paste-ability. Others users can verify that a message was signed by another node in their channel database with the VerifyMessage interface.
This commit is contained in:
1 parent
2486097554
commit
2249215260
7 files changed
+694
-333
No files matched your search
+28
-1
@@ -23,7 +23,7 @@ func newNodeSigner(key *btcec.PrivateKey) *nodeSigner {
|
||||
}
|
||||
|
||||
// SignMessage signs a double-sha256 digest of the passed msg under the
|
||||
// resident node private key. If the target public key is _not_ the node's
|
||||
// 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,
|
||||
msg []byte) (*btcec.Signature, error) {
|
||||
@@ -44,6 +44,33 @@ func (n *nodeSigner) SignMessage(pubKey *btcec.PublicKey,
|
||||
return sign, nil
|
||||
}
|
||||
|
||||
// SignCompact 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. The returned signature is a
|
||||
// pubkey-recoverable signature.
|
||||
func (n *nodeSigner) SignCompact(pubKey *btcec.PublicKey,
|
||||
msg []byte) ([]byte, error) {
|
||||
|
||||
// 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()) {
|
||||
return nil, fmt.Errorf("unknown public key")
|
||||
}
|
||||
|
||||
// Otherwise, we'll sign the dsha256 of the target message.
|
||||
digest := chainhash.DoubleHashB(msg)
|
||||
// Should the signature reference a compressed public key or not.
|
||||
compressedPubKey := false
|
||||
// btcec.SignCompact returns a pubkey-recoverable signature
|
||||
sign, err := btcec.SignCompact(
|
||||
btcec.S256(), n.privKey, digest, compressedPubKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't sign the message: %v", err)
|
||||
}
|
||||
|
||||
return sign, nil
|
||||
}
|
||||
|
||||
// A compile time check to ensure that nodeSigner implements the MessageSigner
|
||||
// interface.
|
||||
var _ lnwallet.MessageSigner = (*nodeSigner)(nil)
|
||||
Reference in new issue
Block a user