From 51ff07956b3c249d9badfccf3c1edca38943ac63 Mon Sep 17 00:00:00 2001 From: ardevd Date: Sun, 14 Jan 2024 22:39:46 +0100 Subject: [PATCH] client: implemented messaging signing. added support for the main RPC implementation of message signing. --- lightning_client.go | 24 ++++++++++++++++++++++++ macaroon_recipes_test.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lightning_client.go b/lightning_client.go index d6c1316..f326c05 100644 --- a/lightning_client.go +++ b/lightning_client.go @@ -271,6 +271,13 @@ type LightningClient interface { // relevant to the wallet are sent over. SubscribeTransactions(ctx context.Context) (<-chan Transaction, <-chan error, error) + + // SignMessage signs a message with this node's private key. + // The returned signature string is zbase32 encoded and pubkey + // recoverable, meaning that only the message digest and signature + // are needed for verification. + SignMessage(ctx context.Context, data []byte) (string, + error) } // Info contains info about the connected lnd node. @@ -4132,6 +4139,23 @@ func (s *lightningClient) SendCustomMessage(ctx context.Context, return err } +// SignMessage signs a message with this node's private key. +// The returned signature string is zbase32 encoded and pubkey +// recoverable, meaning that only the message digest and signature +// are needed for verification. +func (s *lightningClient) SignMessage(ctx context.Context, + data []byte) (string, error) { + + rpcCtx := s.adminMac.WithMacaroonAuth(ctx) + rpcReq := &lnrpc.SignMessageRequest{Msg: data} + rpcRes, err := s.client.SignMessage(rpcCtx, rpcReq) + if err != nil { + return "", err + } + + return rpcRes.Signature, nil +} + // SubscribeCustomMessages subscribes to a stream of custom messages, optionally // filtering by peer and message type. The channels returned will be closed // when the subscription exits. diff --git a/macaroon_recipes_test.go b/macaroon_recipes_test.go index 95e033d..ab1a2d3 100644 --- a/macaroon_recipes_test.go +++ b/macaroon_recipes_test.go @@ -12,7 +12,7 @@ import ( var ( expectedPermissions = map[string]int{ - "lnrpc": 11, + "lnrpc": 12, "chainrpc": 1, "invoicesrpc": 2, "routerrpc": 2,