From 07ea3e039f09026c034bd8c25aa5b65a01dea9cb Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 5 Sep 2017 17:56:36 +0200 Subject: [PATCH] nodeSigner: add method for signing already hashed data --- nodesigner.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nodesigner.go b/nodesigner.go index 2155058a..c3e6a458 100644 --- a/nodesigner.go +++ b/nodesigner.go @@ -53,18 +53,24 @@ func (n *nodeSigner) SignMessage(pubKey *btcec.PublicKey, // resident node's private key. The returned signature is a pubkey-recoverable // signature. func (n *nodeSigner) SignCompact(msg []byte) ([]byte, error) { - - // Otherwise, we'll sign the dsha256 of the target message. + // We'll sign the dsha256 of the target message. digest := chainhash.DoubleHashB(msg) + return n.SignDigestCompact(digest) +} + +// 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) { + // 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, digest, + sig, err := btcec.SignCompact(btcec.S256(), n.privKey, hash, isCompressedKey) if err != nil { - return nil, fmt.Errorf("can't sign the message: %v", err) + return nil, fmt.Errorf("can't sign the hash: %v", err) } return sig, nil