diff --git a/lndclient/signer_client.go b/lndclient/signer_client.go index c4d5f3c..e587e05 100644 --- a/lndclient/signer_client.go +++ b/lndclient/signer_client.go @@ -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 +} diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index ee51c10..a40aa66 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -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() diff --git a/test/signer_mock.go b/test/signer_mock.go index 4e2055f..e0d008f 100644 --- a/test/signer_mock.go +++ b/test/signer_mock.go @@ -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 +}