Skip to content

Commit

Permalink
feat: implemented main rpc message verification
Browse files Browse the repository at this point in the history
added support for the main RPC message verification API endpoint.
  • Loading branch information
ardevd committed Jan 15, 2024
1 parent d286b88 commit 466133e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions lightning_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ type LightningClient interface {
// are needed for verification.
SignMessage(ctx context.Context, data []byte) (string,
error)

// VerifyMessage verifies a signature over a msg. The signature must
// be zbase32 encoded and signed by an active node in the resident
// node's channel database. In addition to returning the validity of
// the signature, VerifyMessage also returns the recovered pubkey
// from the signature.
VerifyMessage(ctx context.Context, data []byte, signature string) (bool,
string, error)
}

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

// VerifyMessage verifies a signature over a msg. The signature must
// be zbase32 encoded and signed by an active node in the resident
// node's channel database. In addition to returning the validity of
// the signature, VerifyMessage also returns the recovered pubkey
// from the signature.
func (s *lightningClient) VerifyMessage(ctx context.Context,
data []byte, signature string) (bool, string, error) {

rpcCtx := s.adminMac.WithMacaroonAuth(ctx)
rpcReq := &lnrpc.VerifyMessageRequest{Msg: data, Signature: signature}
rpcRes, err := s.client.VerifyMessage(rpcCtx, rpcReq)
if err != nil {
return false, "", err
}

return rpcRes.Valid, rpcRes.Pubkey, 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": 12,
"lnrpc": 13,
"chainrpc": 1,
"invoicesrpc": 2,
"routerrpc": 2,
Expand Down

0 comments on commit 466133e

Please sign in to comment.