lndclient: expose SignMessage RPC

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

@ -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
}

@ -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()

@ -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
}

Loading…
Cancel
Save