lnrpc: add command for baking new macaroons

This commit is contained in:
Oliver Gugger committed 2019-10-24 10:25:32 +02:00
1 parent c66c4052ec
commit 6a463de7a2
6 files changed
+944 -534

No files matched your search

+3
View File
@@ -124,6 +124,9 @@ description):
* ForwardingHistory
* ForwardingHistory allows the caller to query the htlcswitch for a
record of all HTLCs forwarded.
* BakeMacaroon
* Bakes a new macaroon with the provided list of permissions and
restrictions
## Service: WalletUnlocker
+712 -534
View File
File diff suppressed because it is too large. Load diff
+46
View File
@@ -834,6 +834,19 @@ func request_Lightning_RestoreChannelBackups_0(ctx context.Context, marshaler ru
}
func request_Lightning_BakeMacaroon_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq BakeMacaroonRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.BakeMacaroon(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
// RegisterWalletUnlockerHandlerFromEndpoint is same as RegisterWalletUnlockerHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterWalletUnlockerHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
@@ -2193,6 +2206,35 @@ func RegisterLightningHandler(ctx context.Context, mux *runtime.ServeMux, conn *
})
mux.Handle("POST", pattern_Lightning_BakeMacaroon_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Lightning_BakeMacaroon_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Lightning_BakeMacaroon_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -2276,6 +2318,8 @@ var (
pattern_Lightning_VerifyChanBackup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "channels", "backup", "verify"}, ""))
pattern_Lightning_RestoreChannelBackups_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "channels", "backup", "restore"}, ""))
pattern_Lightning_BakeMacaroon_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "macaroon"}, ""))
)
var (
@@ -2358,4 +2402,6 @@ var (
forward_Lightning_VerifyChanBackup_0 = runtime.ForwardResponseMessage
forward_Lightning_RestoreChannelBackups_0 = runtime.ForwardResponseMessage
forward_Lightning_BakeMacaroon_0 = runtime.ForwardResponseMessage
)
+28
View File
@@ -777,6 +777,18 @@ service Lightning {
*/
rpc SubscribeChannelBackups(ChannelBackupSubscription) returns (stream ChanBackupSnapshot) {
};
/** lncli: `bakemacaroon`
BakeMacaroon allows the creation of a new macaroon with custom read and
write permissions. No first-party caveats are added since this can be done
offline.
*/
rpc BakeMacaroon(BakeMacaroonRequest) returns (BakeMacaroonResponse) {
option (google.api.http) = {
post: "/v1/macaroon"
body: "*"
};
};
}
message Utxo {
@@ -2585,3 +2597,19 @@ message ChannelBackupSubscription {}
message VerifyChanBackupResponse {
}
message MacaroonPermission {
/// The entity a permission grants access to.
string entity = 1 [json_name = "entity"];
/// The action that is granted.
string action = 2 [json_name = "action"];
}
message BakeMacaroonRequest {
/// The list of permissions the new macaroon should grant.
repeated MacaroonPermission permissions = 1 [json_name = "permissions"];
}
message BakeMacaroonResponse {
/// The hex encoded macaroon, serialized in binary format.
string macaroon = 1 [json_name = "macaroon"];
}
+61
View File
@@ -917,6 +917,33 @@
]
}
},
"/v1/macaroon": {
"post": {
"summary": "* lncli: `bakemacaroon`\nBakeMacaroon allows the creation of a new macaroon with custom read and\nwrite permissions. No first-party caveats are added since this can be done\noffline.",
"operationId": "BakeMacaroon",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/lnrpcBakeMacaroonResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/lnrpcBakeMacaroonRequest"
}
}
],
"tags": [
"Lightning"
]
}
},
"/v1/newaddress": {
"get": {
"summary": "* lncli: `newaddress`\nNewAddress creates a new address under control of the local wallet.",
@@ -1512,6 +1539,27 @@
"description": "- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)\n- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)",
"title": "* \n`AddressType` has to be one of:"
},
"lnrpcBakeMacaroonRequest": {
"type": "object",
"properties": {
"permissions": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcMacaroonPermission"
},
"description": "/ The list of permissions the new macaroon should grant."
}
}
},
"lnrpcBakeMacaroonResponse": {
"type": "object",
"properties": {
"macaroon": {
"type": "string",
"description": "/ The hex encoded macaroon, serialized in binary format."
}
}
},
"lnrpcChain": {
"type": "object",
"properties": {
@@ -2746,6 +2794,19 @@
}
}
},
"lnrpcMacaroonPermission": {
"type": "object",
"properties": {
"entity": {
"type": "string",
"description": "/ The entity a permission grants access to."
},
"action": {
"type": "string",
"description": "/ The action that is granted."
}
}
},
"lnrpcMultiChanBackup": {
"type": "object",
"properties": {