Skip to content

Commit 304c8f5

Browse files
committed
lndclient: expose VerifyMessage RPC
1 parent 2a7c518 commit 304c8f5

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

lndclient/signer_client.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type SignerClient interface {
2020
// locator. The returned signature is fixed-size LN wire format encoded.
2121
SignMessage(ctx context.Context, msg []byte,
2222
locator keychain.KeyLocator) ([]byte, error)
23+
24+
// VerifyMessage verifies a signature over a message using the public
25+
// key provided. The signature must be fixed-size LN wire format
26+
// encoded.
27+
VerifyMessage(ctx context.Context, msg, sig []byte, pubkey [33]byte) (
28+
bool, error)
2329
}
2430

2531
type signerClient struct {
@@ -124,3 +130,25 @@ func (s *signerClient) SignMessage(ctx context.Context, msg []byte,
124130

125131
return resp.Signature, nil
126132
}
133+
134+
// VerifyMessage verifies a signature over a message using the public key
135+
// provided. The signature must be fixed-size LN wire format encoded.
136+
func (s *signerClient) VerifyMessage(ctx context.Context, msg, sig []byte,
137+
pubkey [33]byte) (bool, error) {
138+
139+
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
140+
defer cancel()
141+
142+
rpcIn := &signrpc.VerifyMessageReq{
143+
Msg: msg,
144+
Signature: sig,
145+
Pubkey: pubkey[:],
146+
}
147+
148+
rpcCtx = s.signerMac.WithMacaroonAuth(rpcCtx)
149+
resp, err := s.client.VerifyMessage(rpcCtx, rpcIn)
150+
if err != nil {
151+
return false, err
152+
}
153+
return resp.Valid, nil
154+
}

test/lnd_services_mock.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var (
1818
testStartingHeight = int32(600)
1919
testNodePubkey = "03f5374b16f0b1f1b49101de1b9d89e0b460bc57ce9c2f9" +
2020
"132b73dfc76d3704daa"
21-
testSignature = []byte{55, 66, 77, 88, 99}
21+
testSignature = []byte{55, 66, 77, 88, 99}
22+
testSignatureMsg = "test"
2223
)
2324

2425
// NewMockLnd returns a new instance of LndMockServices that can be used in unit
@@ -61,6 +62,7 @@ func NewMockLnd() *LndMockServices {
6162
Height: testStartingHeight,
6263
NodePubkey: testNodePubkey,
6364
Signature: testSignature,
65+
SignatureMsg: testSignatureMsg,
6466
}
6567

6668
lightningClient.lnd = &lnd
@@ -128,9 +130,10 @@ type LndMockServices struct {
128130
RouterSendPaymentChannel chan RouterPaymentChannelMessage
129131
TrackPaymentChannel chan TrackPaymentMessage
130132

131-
Height int32
132-
NodePubkey string
133-
Signature []byte
133+
Height int32
134+
NodePubkey string
135+
Signature []byte
136+
SignatureMsg string
134137

135138
WaitForFinished func()
136139

test/signer_mock.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"bytes"
45
"context"
56

67
"github.com/btcsuite/btcd/wire"
@@ -25,3 +26,14 @@ func (s *mockSigner) SignMessage(ctx context.Context, msg []byte,
2526

2627
return s.lnd.Signature, nil
2728
}
29+
30+
func (s *mockSigner) VerifyMessage(ctx context.Context, msg, sig []byte,
31+
pubkey [33]byte) (bool, error) {
32+
33+
// Make the mock somewhat functional by asserting that the message and
34+
// signature is what we expect from the mock parameters.
35+
mockAssertion := bytes.Equal(msg, []byte(s.lnd.SignatureMsg)) &&
36+
bytes.Equal(sig, s.lnd.Signature)
37+
38+
return mockAssertion, nil
39+
}

0 commit comments

Comments
 (0)