mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-07 11:22:10 +02:00
multi: refactor SignDigest into SignMessage
To make it possible to use a remote signrpc server as a signer for our wallet, we need to change our main interface to sign the message instead of the message's digest. Otherwise we'd need to alter the signrpc.SignMessage RPC to accept a digest instead of only the message which has security implications.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package keychain
|
||||
|
||||
import "github.com/btcsuite/btcd/btcec"
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
func NewPubKeyDigestSigner(keyDesc KeyDescriptor,
|
||||
signer DigestSignerRing) *PubKeyDigestSigner {
|
||||
@@ -20,10 +23,10 @@ func (p *PubKeyDigestSigner) PubKey() *btcec.PublicKey {
|
||||
return p.keyDesc.PubKey
|
||||
}
|
||||
|
||||
func (p *PubKeyDigestSigner) SignDigest(digest [32]byte) (*btcec.Signature,
|
||||
error) {
|
||||
func (p *PubKeyDigestSigner) SignMessage(message []byte,
|
||||
doubleHash bool) (*btcec.Signature, error) {
|
||||
|
||||
return p.digestSigner.SignDigest(p.keyDesc, digest)
|
||||
return p.digestSigner.SignMessage(p.keyDesc, message, doubleHash)
|
||||
}
|
||||
|
||||
func (p *PubKeyDigestSigner) SignDigestCompact(digest [32]byte) ([]byte,
|
||||
@@ -40,10 +43,16 @@ func (p *PrivKeyDigestSigner) PubKey() *btcec.PublicKey {
|
||||
return p.PrivKey.PubKey()
|
||||
}
|
||||
|
||||
func (p *PrivKeyDigestSigner) SignDigest(digest [32]byte) (*btcec.Signature,
|
||||
error) {
|
||||
func (p *PrivKeyDigestSigner) SignMessage(msg []byte,
|
||||
doubleHash bool) (*btcec.Signature, error) {
|
||||
|
||||
return p.PrivKey.Sign(digest[:])
|
||||
var digest []byte
|
||||
if doubleHash {
|
||||
digest = chainhash.DoubleHashB(msg)
|
||||
} else {
|
||||
digest = chainhash.HashB(msg)
|
||||
}
|
||||
return p.PrivKey.Sign(digest)
|
||||
}
|
||||
|
||||
func (p *PrivKeyDigestSigner) SignDigestCompact(digest [32]byte) ([]byte,
|
||||
|
Reference in New Issue
Block a user