Skip to content

Commit 86b49c3

Browse files
committed
Add CheckMacaroonPermissions command to client
1 parent c4a8c75 commit 86b49c3

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

lightning_client.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ 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) (bool, error)
184189
}
185190

186191
// Info contains info about the connected lnd node.
@@ -3469,3 +3474,30 @@ func (s *lightningClient) QueryRoutes(ctx context.Context,
34693474
TotalAmtMsat: lnwire.MilliSatoshi(route.TotalAmtMsat),
34703475
}, nil
34713476
}
3477+
3478+
func (s *lightningClient) CheckMacaroonPermissions(ctx context.Context,
3479+
macaroon []byte, permissions []MacaroonPermission) (bool, error) {
3480+
3481+
rpcPermissions := make([]*lnrpc.MacaroonPermission, 0)
3482+
for _, perm := range permissions {
3483+
permission := &lnrpc.MacaroonPermission{
3484+
Entity: perm.Entity,
3485+
Action: perm.Action,
3486+
}
3487+
3488+
rpcPermissions = append(rpcPermissions, permission)
3489+
}
3490+
3491+
rpcCtx := s.adminMac.WithMacaroonAuth(ctx)
3492+
res, err := s.client.CheckMacaroonPermissions(
3493+
rpcCtx, &lnrpc.CheckMacPermRequest{
3494+
Macaroon: macaroon,
3495+
Permissions: rpcPermissions,
3496+
},
3497+
)
3498+
if err != nil {
3499+
return false, err
3500+
}
3501+
3502+
return res.Valid, nil
3503+
}

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)