Skip to content

Commit

Permalink
lnrpc: add NoHash option to signer.SignMessage rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Oct 17, 2023
1 parent 80bfd17 commit 98a71f7
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 240 deletions.
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
} 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;

/*
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

0 comments on commit 98a71f7

Please sign in to comment.