Skip to content

Commit

Permalink
client: implemented messaging signing.
Browse files Browse the repository at this point in the history
added support for the main RPC implementation of message signing.
  • Loading branch information
ardevd committed Jan 15, 2024
1 parent b84be43 commit 51ff079
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lightning_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion macaroon_recipes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var (
expectedPermissions = map[string]int{
"lnrpc": 11,
"lnrpc": 12,
"chainrpc": 1,
"invoicesrpc": 2,
"routerrpc": 2,
Expand Down

0 comments on commit 51ff079

Please sign in to comment.