diff --git a/lndclient/signer_client.go b/lndclient/signer_client.go index a5cad28..c4d5f3c 100644 --- a/lndclient/signer_client.go +++ b/lndclient/signer_client.go @@ -6,6 +6,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightninglabs/loop/swap" "github.com/lightningnetwork/lnd/input" + "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnrpc/signrpc" "google.golang.org/grpc" ) @@ -14,6 +15,11 @@ import ( type SignerClient interface { SignOutputRaw(ctx context.Context, tx *wire.MsgTx, signDescriptors []*input.SignDescriptor) ([][]byte, error) + + // SignMessage signs a message with the key specified in the key + // locator. The returned signature is fixed-size LN wire format encoded. + SignMessage(ctx context.Context, msg []byte, + locator keychain.KeyLocator) ([]byte, error) } type signerClient struct { @@ -93,3 +99,28 @@ func (s *signerClient) SignOutputRaw(ctx context.Context, tx *wire.MsgTx, return resp.RawSigs, nil } + +// SignMessage signs a message with the key specified in the key locator. The +// returned signature is fixed-size LN wire format encoded. +func (s *signerClient) SignMessage(ctx context.Context, msg []byte, + locator keychain.KeyLocator) ([]byte, error) { + + rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout) + defer cancel() + + rpcIn := &signrpc.SignMessageReq{ + Msg: msg, + KeyLoc: &signrpc.KeyLocator{ + KeyFamily: int32(locator.Family), + KeyIndex: int32(locator.Index), + }, + } + + rpcCtx = s.signerMac.WithMacaroonAuth(rpcCtx) + resp, err := s.client.SignMessage(rpcCtx, rpcIn) + if err != nil { + return nil, err + } + + return resp.Signature, nil +} diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index 0cef215..ee51c10 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -18,6 +18,7 @@ var ( testStartingHeight = int32(600) testNodePubkey = "03f5374b16f0b1f1b49101de1b9d89e0b460bc57ce9c2f9" + "132b73dfc76d3704daa" + testSignature = []byte{55, 66, 77, 88, 99} ) // NewMockLnd returns a new instance of LndMockServices that can be used in unit @@ -59,6 +60,7 @@ func NewMockLnd() *LndMockServices { epochChannel: make(chan int32), Height: testStartingHeight, NodePubkey: testNodePubkey, + Signature: testSignature, } lightningClient.lnd = &lnd @@ -66,6 +68,7 @@ func NewMockLnd() *LndMockServices { walletKit.lnd = &lnd invoices.lnd = &lnd router.lnd = &lnd + signer.lnd = &lnd lnd.WaitForFinished = func() { chainNotifier.WaitForFinished() @@ -127,6 +130,7 @@ type LndMockServices struct { Height int32 NodePubkey string + Signature []byte WaitForFinished func() diff --git a/test/signer_mock.go b/test/signer_mock.go index 8bc86f9..4e2055f 100644 --- a/test/signer_mock.go +++ b/test/signer_mock.go @@ -5,9 +5,11 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/input" + "github.com/lightningnetwork/lnd/keychain" ) type mockSigner struct { + lnd *LndMockServices } func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx, @@ -17,3 +19,9 @@ func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx, return rawSigs, nil } + +func (s *mockSigner) SignMessage(ctx context.Context, msg []byte, + locator keychain.KeyLocator) ([]byte, error) { + + return s.lnd.Signature, nil +}