Skip to content

Commit 67d851a

Browse files
authored
Merge pull request #173 from ardevd/feat-message-verification
feat: implemented main rpc signature verification
2 parents d286b88 + 466133e commit 67d851a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lightning_client.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ type LightningClient interface {
278278
// are needed for verification.
279279
SignMessage(ctx context.Context, data []byte) (string,
280280
error)
281+
282+
// VerifyMessage verifies a signature over a msg. The signature must
283+
// be zbase32 encoded and signed by an active node in the resident
284+
// node's channel database. In addition to returning the validity of
285+
// the signature, VerifyMessage also returns the recovered pubkey
286+
// from the signature.
287+
VerifyMessage(ctx context.Context, data []byte, signature string) (bool,
288+
string, error)
281289
}
282290

283291
// Info contains info about the connected lnd node.
@@ -4156,6 +4164,24 @@ func (s *lightningClient) SignMessage(ctx context.Context,
41564164
return rpcRes.Signature, nil
41574165
}
41584166

4167+
// VerifyMessage verifies a signature over a msg. The signature must
4168+
// be zbase32 encoded and signed by an active node in the resident
4169+
// node's channel database. In addition to returning the validity of
4170+
// the signature, VerifyMessage also returns the recovered pubkey
4171+
// from the signature.
4172+
func (s *lightningClient) VerifyMessage(ctx context.Context,
4173+
data []byte, signature string) (bool, string, error) {
4174+
4175+
rpcCtx := s.adminMac.WithMacaroonAuth(ctx)
4176+
rpcReq := &lnrpc.VerifyMessageRequest{Msg: data, Signature: signature}
4177+
rpcRes, err := s.client.VerifyMessage(rpcCtx, rpcReq)
4178+
if err != nil {
4179+
return false, "", err
4180+
}
4181+
4182+
return rpcRes.Valid, rpcRes.Pubkey, nil
4183+
}
4184+
41594185
// SubscribeCustomMessages subscribes to a stream of custom messages, optionally
41604186
// filtering by peer and message type. The channels returned will be closed
41614187
// 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": 12,
15+
"lnrpc": 13,
1616
"chainrpc": 1,
1717
"invoicesrpc": 2,
1818
"routerrpc": 2,

0 commit comments

Comments
 (0)