multi: add tag option to SignMessageSchnorr

This commit is contained in:
Orbital
2023-10-21 17:05:53 -05:00
parent dd81edd817
commit ed373baed0
5 changed files with 23 additions and 13 deletions

View File

@@ -458,8 +458,8 @@ func (b *BtcWalletKeyRing) SignMessageCompact(keyLoc KeyLocator,
//
// NOTE: This is part of the keychain.MessageSignerRing interface.
func (b *BtcWalletKeyRing) SignMessageSchnorr(keyLoc KeyLocator,
msg []byte, doubleHash bool, taprootTweak []byte) (*schnorr.Signature,
error) {
msg []byte, doubleHash bool, taprootTweak []byte,
tag []byte) (*schnorr.Signature, error) {
privKey, err := b.DerivePrivKey(KeyDescriptor{
KeyLocator: keyLoc,
@@ -472,10 +472,15 @@ func (b *BtcWalletKeyRing) SignMessageSchnorr(keyLoc KeyLocator,
privKey = txscript.TweakTaprootPrivKey(*privKey, taprootTweak)
}
// If a tag was provided, we need to take the tagged hash of the input.
var digest []byte
if doubleHash {
switch {
case len(tag) > 0:
taggedHash := chainhash.TaggedHash(tag, msg)
digest = taggedHash[:]
case doubleHash:
digest = chainhash.DoubleHashB(msg)
} else {
default:
digest = chainhash.HashB(msg)
}
return schnorr.Sign(privKey, digest)

View File

@@ -239,8 +239,8 @@ type MessageSignerRing interface {
// hashing it first, with the private key described in the key locator
// and the optional Taproot tweak applied to the private key.
SignMessageSchnorr(keyLoc KeyLocator, msg []byte,
doubleHash bool, taprootTweak []byte) (*schnorr.Signature,
error)
doubleHash bool, taprootTweak []byte,
tag []byte) (*schnorr.Signature, error)
}
// SingleKeyMessageSigner is an abstraction interface that hides the