lndclient: expose VerifyMessage RPC

pull/123/head
Oliver Gugger 4 years ago
parent 2a7c5182a4
commit 304c8f580f
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -20,6 +20,12 @@ type SignerClient interface {
// locator. The returned signature is fixed-size LN wire format encoded.
SignMessage(ctx context.Context, msg []byte,
locator keychain.KeyLocator) ([]byte, error)
// VerifyMessage verifies a signature over a message using the public
// key provided. The signature must be fixed-size LN wire format
// encoded.
VerifyMessage(ctx context.Context, msg, sig []byte, pubkey [33]byte) (
bool, error)
}
type signerClient struct {
@ -124,3 +130,25 @@ func (s *signerClient) SignMessage(ctx context.Context, msg []byte,
return resp.Signature, nil
}
// VerifyMessage verifies a signature over a message using the public key
// provided. The signature must be fixed-size LN wire format encoded.
func (s *signerClient) VerifyMessage(ctx context.Context, msg, sig []byte,
pubkey [33]byte) (bool, error) {
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
defer cancel()
rpcIn := &signrpc.VerifyMessageReq{
Msg: msg,
Signature: sig,
Pubkey: pubkey[:],
}
rpcCtx = s.signerMac.WithMacaroonAuth(rpcCtx)
resp, err := s.client.VerifyMessage(rpcCtx, rpcIn)
if err != nil {
return false, err
}
return resp.Valid, nil
}

@ -18,7 +18,8 @@ var (
testStartingHeight = int32(600)
testNodePubkey = "03f5374b16f0b1f1b49101de1b9d89e0b460bc57ce9c2f9" +
"132b73dfc76d3704daa"
testSignature = []byte{55, 66, 77, 88, 99}
testSignature = []byte{55, 66, 77, 88, 99}
testSignatureMsg = "test"
)
// NewMockLnd returns a new instance of LndMockServices that can be used in unit
@ -61,6 +62,7 @@ func NewMockLnd() *LndMockServices {
Height: testStartingHeight,
NodePubkey: testNodePubkey,
Signature: testSignature,
SignatureMsg: testSignatureMsg,
}
lightningClient.lnd = &lnd
@ -128,9 +130,10 @@ type LndMockServices struct {
RouterSendPaymentChannel chan RouterPaymentChannelMessage
TrackPaymentChannel chan TrackPaymentMessage
Height int32
NodePubkey string
Signature []byte
Height int32
NodePubkey string
Signature []byte
SignatureMsg string
WaitForFinished func()

@ -1,6 +1,7 @@
package test
import (
"bytes"
"context"
"github.com/btcsuite/btcd/wire"
@ -25,3 +26,14 @@ func (s *mockSigner) SignMessage(ctx context.Context, msg []byte,
return s.lnd.Signature, nil
}
func (s *mockSigner) VerifyMessage(ctx context.Context, msg, sig []byte,
pubkey [33]byte) (bool, error) {
// Make the mock somewhat functional by asserting that the message and
// signature is what we expect from the mock parameters.
mockAssertion := bytes.Equal(msg, []byte(s.lnd.SignatureMsg)) &&
bytes.Equal(sig, s.lnd.Signature)
return mockAssertion, nil
}

Loading…
Cancel
Save