Skip to content

Commit 446bb30

Browse files
committed
Add CheckMacaroonPermissions command to client
1 parent 3870f0f commit 446bb30

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

lightning_client.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ type LightningClient interface {
181181
// vertices.
182182
QueryRoutes(ctx context.Context, req QueryRoutesRequest) (
183183
*QueryRoutesResponse, error)
184+
185+
// CheckMacaroonPermissions allows a client to check the validity of a
186+
// macaroon.
187+
CheckMacaroonPermissions(ctx context.Context, macaroon []byte,
188+
permissions []MacaroonPermission, fullMethod string) (bool,
189+
error)
184190
}
185191

186192
// Info contains info about the connected lnd node.
@@ -3480,3 +3486,30 @@ func (s *lightningClient) QueryRoutes(ctx context.Context,
34803486
TotalAmtMsat: lnwire.MilliSatoshi(route.TotalAmtMsat),
34813487
}, nil
34823488
}
3489+
3490+
func (s *lightningClient) CheckMacaroonPermissions(ctx context.Context,
3491+
macaroon []byte, permissions []MacaroonPermission, fullMethod string) (bool,
3492+
error) {
3493+
3494+
rpcPermissions := make([]*lnrpc.MacaroonPermission, len(permissions))
3495+
for idx, perm := range permissions {
3496+
rpcPermissions[idx] = &lnrpc.MacaroonPermission{
3497+
Entity: perm.Entity,
3498+
Action: perm.Action,
3499+
}
3500+
}
3501+
3502+
rpcCtx := s.adminMac.WithMacaroonAuth(ctx)
3503+
res, err := s.client.CheckMacaroonPermissions(
3504+
rpcCtx, &lnrpc.CheckMacPermRequest{
3505+
Macaroon: macaroon,
3506+
Permissions: rpcPermissions,
3507+
FullMethod: fullMethod,
3508+
},
3509+
)
3510+
if err != nil {
3511+
return false, err
3512+
}
3513+
3514+
return res.Valid, nil
3515+
}

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": 9,
15+
"lnrpc": 10,
1616
"chainrpc": 1,
1717
"invoicesrpc": 2,
1818
"routerrpc": 2,

testdata/permissions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@
140140
}
141141
]
142142
},
143+
"/lnrpc.Lightning/CheckMacaroonPermissions": {
144+
"permissions": [
145+
{
146+
"entity": "macaroon",
147+
"action": "read"
148+
}
149+
]
150+
},
143151
"/lnrpc.Lightning/CloseChannel": {
144152
"permissions": [
145153
{

0 commit comments

Comments
 (0)