multi: use key locator only for signing messages

To simplify the API surface of a remote signer even more, we refactor
the SignMessage and SignMessageCompact calls to only accept a key
locator as we always know what key we're using for signing anyway.
This commit is contained in:
Oliver Gugger
2021-09-23 16:54:29 +02:00
parent 8b7c88537c
commit afa03f22cc
6 changed files with 46 additions and 37 deletions

View File

@@ -392,13 +392,15 @@ func (b *BtcWalletKeyRing) ECDH(keyDesc KeyDescriptor,
}
// SignMessage signs the given message, single or double SHA256 hashing it
// first, with the private key described in the key descriptor.
// first, with the private key described in the key locator.
//
// NOTE: This is part of the keychain.MessageSignerRing interface.
func (b *BtcWalletKeyRing) SignMessage(keyDesc KeyDescriptor,
func (b *BtcWalletKeyRing) SignMessage(keyLoc KeyLocator,
msg []byte, doubleHash bool) (*btcec.Signature, error) {
privKey, err := b.DerivePrivKey(keyDesc)
privKey, err := b.DerivePrivKey(KeyDescriptor{
KeyLocator: keyLoc,
})
if err != nil {
return nil, err
}
@@ -413,14 +415,16 @@ func (b *BtcWalletKeyRing) SignMessage(keyDesc KeyDescriptor,
}
// SignMessageCompact signs the given message, single or double SHA256 hashing
// it first, with the private key described in the key descriptor and returns
// it first, with the private key described in the key locator and returns
// the signature in the compact, public key recoverable format.
//
// NOTE: This is part of the keychain.MessageSignerRing interface.
func (b *BtcWalletKeyRing) SignMessageCompact(keyDesc KeyDescriptor,
func (b *BtcWalletKeyRing) SignMessageCompact(keyLoc KeyLocator,
msg []byte, doubleHash bool) ([]byte, error) {
privKey, err := b.DerivePrivKey(keyDesc)
privKey, err := b.DerivePrivKey(KeyDescriptor{
KeyLocator: keyLoc,
})
if err != nil {
return nil, err
}

View File

@@ -192,15 +192,15 @@ type SecretKeyRing interface {
// signing on keys within a key ring.
type MessageSignerRing interface {
// SignMessage signs the given message, single or double SHA256 hashing
// it first, with the private key described in the key descriptor.
SignMessage(keyDesc KeyDescriptor, message []byte,
// it first, with the private key described in the key locator.
SignMessage(keyLoc KeyLocator, msg []byte,
doubleHash bool) (*btcec.Signature, error)
// SignMessageCompact signs the given message, single or double SHA256
// hashing it first, with the private key described in the key
// descriptor and returns the signature in the compact, public key
// recoverable format.
SignMessageCompact(keyDesc KeyDescriptor, message []byte,
// hashing it first, with the private key described in the key locator
// and returns the signature in the compact, public key recoverable
// format.
SignMessageCompact(keyLoc KeyLocator, msg []byte,
doubleHash bool) ([]byte, error)
}

View File

@@ -5,34 +5,36 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
)
func NewPubKeyMessageSigner(keyDesc KeyDescriptor,
func NewPubKeyMessageSigner(pubKey *btcec.PublicKey, keyLoc KeyLocator,
signer MessageSignerRing) *PubKeyMessageSigner {
return &PubKeyMessageSigner{
keyDesc: keyDesc,
pubKey: pubKey,
keyLoc: keyLoc,
digestSigner: signer,
}
}
type PubKeyMessageSigner struct {
keyDesc KeyDescriptor
pubKey *btcec.PublicKey
keyLoc KeyLocator
digestSigner MessageSignerRing
}
func (p *PubKeyMessageSigner) PubKey() *btcec.PublicKey {
return p.keyDesc.PubKey
return p.pubKey
}
func (p *PubKeyMessageSigner) SignMessage(message []byte,
doubleHash bool) (*btcec.Signature, error) {
return p.digestSigner.SignMessage(p.keyDesc, message, doubleHash)
return p.digestSigner.SignMessage(p.keyLoc, message, doubleHash)
}
func (p *PubKeyMessageSigner) SignMessageCompact(msg []byte,
doubleHash bool) ([]byte, error) {
return p.digestSigner.SignMessageCompact(p.keyDesc, msg, doubleHash)
return p.digestSigner.SignMessageCompact(p.keyLoc, msg, doubleHash)
}
type PrivKeyMessageSigner struct {