Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lnrpc: add NoHash option to signer.SignMessage rpc #8098

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions keychain/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,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, noHash bool, taprootTweak []byte,
) (*schnorr.Signature, error) {

privKey, err := b.DerivePrivKey(KeyDescriptor{
KeyLocator: keyLoc,
Expand All @@ -477,7 +477,9 @@ func (b *BtcWalletKeyRing) SignMessageSchnorr(keyLoc KeyLocator,
}

var digest []byte
if doubleHash {
if noHash {
digest = msg
orbitalturtle marked this conversation as resolved.
Show resolved Hide resolved
} else if doubleHash {
digest = chainhash.DoubleHashB(msg)
} else {
digest = chainhash.HashB(msg)
Expand Down
4 changes: 2 additions & 2 deletions keychain/derivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, noHash bool, taprootTweak []byte,
) (*schnorr.Signature, error)
}

// SingleKeyMessageSigner is an abstraction interface that hides the
Expand Down
470 changes: 241 additions & 229 deletions lnrpc/signrpc/signer.pb.go

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions lnrpc/signrpc/signer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,27 @@ message SignMessageReq {
// Double-SHA256 hash instead of just the default single round.
bool double_hash = 3;

// Don't hash the message before signing it. This option is only available
// when using a Schnorr signature.
bool no_hash = 4;

/*
Use the compact (pubkey recoverable) format instead of the raw lnwire
format. This option cannot be used with Schnorr signatures.
*/
bool compact_sig = 4;
bool compact_sig = 5;
orbitalturtle marked this conversation as resolved.
Show resolved Hide resolved

/*
Use Schnorr signature. This option cannot be used with compact format.
*/
bool schnorr_sig = 5;
bool schnorr_sig = 6;

/*
The optional Taproot tweak bytes to apply to the private key before creating
a Schnorr signature. The private key is tweaked as described in BIP-341:
privKey + h_tapTweak(internalKey || tapTweak)
*/
bytes schnorr_sig_tap_tweak = 6;
bytes schnorr_sig_tap_tweak = 7;
}
message SignMessageResp {
/*
Expand Down
4 changes: 4 additions & 0 deletions lnrpc/signrpc/signer.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@
"type": "boolean",
"description": "Double-SHA256 hash instead of just the default single round."
},
"no_hash": {
"type": "boolean",
"description": "Don't hash the message before signing it. This option is only available\nwhen using a Schnorr signature."
},
"compact_sig": {
"type": "boolean",
"description": "Use the compact (pubkey recoverable) format instead of the raw lnwire\nformat. This option cannot be used with Schnorr signatures."
Expand Down
2 changes: 1 addition & 1 deletion lnrpc/signrpc/signer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (s *Server) SignMessage(_ context.Context,
// Use the schnorr signature algorithm to sign the message.
if in.SchnorrSig {
sig, err := s.cfg.KeyRing.SignMessageSchnorr(
keyLocator, in.Msg, in.DoubleHash,
keyLocator, in.Msg, in.DoubleHash, in.NoHash,
in.SchnorrSigTapTweak,
)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions lnwallet/rpcwallet/rpcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ func (r *RPCKeyRing) SignMessageCompact(keyLoc keychain.KeyLocator,
//
// NOTE: This method is part of the keychain.MessageSignerRing interface.
func (r *RPCKeyRing) SignMessageSchnorr(keyLoc keychain.KeyLocator,
msg []byte, doubleHash bool, taprootTweak []byte) (*schnorr.Signature,
error) {
msg []byte, doubleHash bool, noHash bool, taprootTweak []byte,
) (*schnorr.Signature, error) {

ctxt, cancel := context.WithTimeout(context.Background(), r.rpcTimeout)
defer cancel()
Expand All @@ -526,6 +526,7 @@ func (r *RPCKeyRing) SignMessageSchnorr(keyLoc keychain.KeyLocator,
KeyIndex: int32(keyLoc.Index),
},
DoubleHash: doubleHash,
NoHash: noHash,
SchnorrSig: true,
SchnorrSigTapTweak: taprootTweak,
})
Expand Down