@@ -15,24 +15,107 @@ underlying LDK Node documentation.
1515
1616## Authentication
1717
18- Every gRPC request must include an ` x-auth ` metadata header with an HMAC-SHA256 signature :
18+ Each request needs a hex-encoded v2 macaroon in the ` macaroon ` header :
1919
20+ ``` text
21+ macaroon: <hex-encoded-request-macaroon>
2022```
21- x-auth: HMAC <unix_timestamp>:<hmac_hex>
23+
24+ Keep your original macaroon private. The client uses it to make a token for each request,
25+ as described below. All requests use TLS.
26+
27+ You can add caveats to make a restricted copy of your macaroon without contacting the server.
28+ A caveat limits its permissions, allowed methods, or expiry time. Added caveats can only reduce
29+ access. See [ Restrictions] ( #restrictions ) for examples.
30+
31+ ### Request binding
32+
33+ The Rust client, CLI, and MCP handle request binding automatically. They keep your macaroon
34+ private and send a copy tied to the request's method, body, and time.
35+
36+ Custom clients must add one final caveat:
37+
38+ ``` text
39+ request = <unix-seconds> <RpcMethod> <body-sha256>
2240```
2341
24- Where:
42+ Use Unix time in seconds, a method name such as ` OnchainSend ` , and the lowercase SHA-256 hash
43+ of the exact gRPC body, including its five-byte frame header. Rust clients can use
44+ ` macaroon::bind_macaroon_to_request ` .
45+
46+ Client and server clocks must be within 60 seconds. The token cannot authorize a different
47+ request, but the same request can still be replayed while the token is valid.
48+
49+ See [ Request proof format] ( request-binding.md ) for exact encoding rules and an example.
50+
51+ ### Restrictions
2552
26- - ` unix_timestamp ` is the current time in seconds since the Unix epoch
27- - ` hmac_hex ` is the hex-encoded result of
28- ` HMAC-SHA256(api_key_bytes, timestamp_be_bytes || grpc_request_body_bytes) `
29- - ` api_key_bytes ` is the API key string encoded as UTF-8 bytes
30- - ` timestamp_be_bytes ` is the timestamp as a big-endian 8-byte unsigned integer
31- - ` grpc_request_body_bytes ` is the raw gRPC request body sent over HTTP/2, including
32- the 5-byte gRPC message frame
53+ A caveat is a condition that limits what a macaroon can do. All caveats must pass:
3354
34- The server rejects requests where the timestamp differs from the server's clock by more than
35- ** 60 seconds** .
55+ | Caveat | Meaning |
56+ | --------| ---------|
57+ | ` permissions = node:read,payments:read ` | Allow only these permissions |
58+ | ` method = GetNodeInfo ` | Allow this RPC method and ` GetPermissions ` |
59+ | ` time-before = 1800000000 ` | Expire at this Unix time in seconds |
60+
61+ Added caveats can only reduce access. They cannot restore permissions or extend the expiry time.
62+ ` GetPermissions ` ignores method restrictions, but still requires a valid, unexpired macaroon.
63+
64+ Derive a restricted copy without contacting the server:
65+
66+ ``` bash
67+ ldk-server-cli derive-macaroon " $MACAROON " \
68+ --caveat ' permissions = node:read' \
69+ --caveat ' method = GetNodeInfo' \
70+ --caveat " time-before = $EXPIRY_UNIX_SECONDS "
71+ ```
72+
73+ The command prints a hex token. Rust clients can use ` macaroon::derive_macaroon ` .
74+ Give the copy to the application and keep the original private.
75+
76+ ### Create and revoke tokens
77+
78+ Use ` CreateMacaroon ` to give each client a token you can revoke separately. New tokens keep
79+ all the caller's restrictions. Revoking the caller's token does not revoke these new tokens.
80+
81+ Copies made with ` derive-macaroon ` share the original token's ID. Revoking that ID blocks
82+ all those copies. The server cannot list copies made locally.
83+
84+ Revocation and expiry block new requests. Existing event streams stay open until the client
85+ disconnects or the server stops. Reconnecting requires a valid token.
86+
87+ See [ Macaroon Management] ( #macaroon-management ) for the RPCs and
88+ [ Operations] ( operations.md#macaroons ) for storage and recovery.
89+
90+ ### Macaroon Permissions
91+
92+ Choose the permissions each client needs, or use ` admin ` by itself for full access.
93+ The CLI also has ` readonly ` , ` invoice ` , and ` admin ` presets.
94+ RPCs with no permission mapping return ` UNIMPLEMENTED ` , even for admin tokens.
95+
96+ | Permission | Access |
97+ | ---------- | ------ |
98+ | ` node:read ` | Node information, balances, and pathfinding scores |
99+ | ` onchain:receive ` | Create on-chain receive addresses |
100+ | ` onchain:send ` | Send on-chain funds |
101+ | ` invoices:create ` | Create BOLT11/BOLT12 invoices and incoming refund requests |
102+ | ` payments:read ` | Read payments, forwarded payments, and forwarding statistics |
103+ | ` payments:claim ` | Claim or fail held BOLT11 payments |
104+ | ` payments:send ` | Send BOLT11, BOLT12, spontaneous, unified, and refund payments; splice out |
105+ | ` channels:read ` | List channels |
106+ | ` channels:manage ` | Open, configure, cooperatively close, or splice funds into channels |
107+ | ` channels:force_close ` | Force-close channels |
108+ | ` peers:read ` | List peers |
109+ | ` peers:manage ` | Connect or disconnect peers |
110+ | ` messages:sign ` | Sign messages and create BOLT12 payer proofs |
111+ | ` messages:verify ` | Verify message signatures |
112+ | ` graph:read ` | Read network graph data |
113+ | ` utilities:read ` | Decode invoices and offers |
114+ | ` events:read ` | Subscribe to the event stream |
115+ | ` macaroons:manage ` | Create, list, and revoke macaroons within your permissions |
116+
117+ MCP provides token management through ` create_macaroon ` , ` list_macaroons ` , ` revoke_macaroon ` ,
118+ and ` get_permissions ` .
36119
37120## TLS
38121
@@ -67,9 +150,10 @@ Errors are returned as standard gRPC status codes:
67150| gRPC Code | Meaning |
68151| ---------------------------| ------------------------------------------------------------------|
69152| ` INVALID_ARGUMENT ` (3) | Malformed request or invalid parameters |
153+ | ` PERMISSION_DENIED ` (7) | Missing permission or a caveat that does not pass |
70154| ` FAILED_PRECONDITION ` (9) | Lightning operation error (e.g., insufficient balance, no route) |
71155| ` INTERNAL ` (13) | Server-side bug |
72- | ` UNAUTHENTICATED ` (16) | Missing or invalid ` x-auth ` header |
156+ | ` UNAUTHENTICATED ` (16) | Missing, invalid, or revoked macaroon |
73157
74158The ` grpc-message ` trailer contains a human-readable error description.
75159
@@ -237,6 +321,18 @@ Use events as notifications. After reconnecting, reconcile recoverable state wit
237321` GetPaymentDetails ` , ` ListPayments ` , ` ListForwardedPayments ` , and ` ListChannels ` . Some event fields
238322cannot be recovered through these APIs.
239323
324+ ### Macaroon Management
325+
326+ | RPC | Description |
327+ | -----| -------------|
328+ | ` CreateMacaroon ` | Create a macaroon and return its private hex token in ` token ` |
329+ | ` ListMacaroons ` | List IDs, names, permissions, and caveats, without secrets |
330+ | ` RevokeMacaroon ` | Revoke a macaroon by ID |
331+ | ` GetPermissions ` | Show the caller's ID, name, usable permissions, and caveats |
332+
333+ The first three RPCs require ` macaroons:manage ` or ` admin ` . You can only create or revoke
334+ tokens whose permissions you have. The last unrestricted admin token cannot be revoked.
335+
240336### Metrics
241337
242338Metrics are served as a plain HTTP GET endpoint (not gRPC):
0 commit comments