Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented main rpc signature verification #173

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading