Skip to content

Commit 05065f4

Browse files
authored
Merge pull request #171 from ardevd/feat-message-sign
client: implemented messaging signing.
2 parents b84be43 + 51ff079 commit 05065f4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lightning_client.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ type LightningClient interface {
271271
// relevant to the wallet are sent over.
272272
SubscribeTransactions(ctx context.Context) (<-chan Transaction,
273273
<-chan error, error)
274+
275+
// SignMessage signs a message with this node's private key.
276+
// The returned signature string is zbase32 encoded and pubkey
277+
// recoverable, meaning that only the message digest and signature
278+
// are needed for verification.
279+
SignMessage(ctx context.Context, data []byte) (string,
280+
error)
274281
}
275282

276283
// Info contains info about the connected lnd node.
@@ -4132,6 +4139,23 @@ func (s *lightningClient) SendCustomMessage(ctx context.Context,
41324139
return err
41334140
}
41344141

4142+
// SignMessage signs a message with this node's private key.
4143+
// The returned signature string is zbase32 encoded and pubkey
4144+
// recoverable, meaning that only the message digest and signature
4145+
// are needed for verification.
4146+
func (s *lightningClient) SignMessage(ctx context.Context,
4147+
data []byte) (string, error) {
4148+
4149+
rpcCtx := s.adminMac.WithMacaroonAuth(ctx)
4150+
rpcReq := &lnrpc.SignMessageRequest{Msg: data}
4151+
rpcRes, err := s.client.SignMessage(rpcCtx, rpcReq)
4152+
if err != nil {
4153+
return "", err
4154+
}
4155+
4156+
return rpcRes.Signature, nil
4157+
}
4158+
41354159
// SubscribeCustomMessages subscribes to a stream of custom messages, optionally
41364160
// filtering by peer and message type. The channels returned will be closed
41374161
// when the subscription exits.

macaroon_recipes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
var (
1414
expectedPermissions = map[string]int{
15-
"lnrpc": 11,
15+
"lnrpc": 12,
1616
"chainrpc": 1,
1717
"invoicesrpc": 2,
1818
"routerrpc": 2,

0 commit comments

Comments
 (0)