@@ -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 only this RPC method |
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+
63+ Derive a restricted copy without contacting the server:
64+
65+ ``` bash
66+ ldk-server-cli derive-macaroon " $MACAROON " \
67+ --caveat ' permissions = node:read' \
68+ --caveat ' method = GetNodeInfo' \
69+ --caveat " time-before = $EXPIRY_UNIX_SECONDS "
70+ ```
71+
72+ The command prints a hex token. Rust clients can use ` macaroon::derive_macaroon ` .
73+ Give the copy to the application and keep the original private.
74+
75+ ### Create and revoke tokens
76+
77+ Use ` CreateMacaroon ` to give each client a token you can revoke separately. New tokens keep
78+ all the caller's restrictions. Revoking the caller's token does not revoke these new tokens.
79+
80+ Copies made with ` derive-macaroon ` share the original token's ID. Revoking that ID blocks
81+ all those copies. The server cannot list copies made locally.
82+
83+ Revocation and expiry block new requests. Existing event streams stay open until the client
84+ disconnects or the server stops. Reconnecting requires a valid token.
85+
86+ See [ Macaroon Management] ( #macaroon-management ) for the RPCs and
87+ [ Operations] ( operations.md#macaroons ) for storage and recovery.
88+
89+ ### Macaroon Permissions
90+
91+ Choose the permissions each client needs, or use ` admin ` by itself for full access.
92+ The CLI also has ` readonly ` , ` invoice ` , and ` admin ` presets.
93+ RPCs with no permission mapping return ` UNIMPLEMENTED ` , even for admin tokens.
94+
95+ | Permission | Access |
96+ | ---------- | ------ |
97+ | ` node:read ` | Node information, balances, and pathfinding scores |
98+ | ` onchain:receive ` | Create on-chain receive addresses |
99+ | ` onchain:send ` | Send on-chain funds |
100+ | ` invoices:create ` | Create BOLT11/BOLT12 invoices and incoming refund requests |
101+ | ` payments:read ` | Read payments and forwarded payments |
102+ | ` payments:claim ` | Claim or fail held BOLT11 payments |
103+ | ` payments:send ` | Send BOLT11, BOLT12, spontaneous, unified, and refund payments |
104+ | ` channels:read ` | List channels |
105+ | ` channels:manage ` | Open, configure, or cooperatively close channels |
106+ | ` channels:splice ` | Splice funds in or out, including to an external address |
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
@@ -232,6 +316,18 @@ Use events as notifications. After reconnecting, reconcile recoverable state wit
232316` GetPaymentDetails ` , ` ListPayments ` , ` ListForwardedPayments ` , and ` ListChannels ` . Some event fields
233317cannot be recovered through these APIs.
234318
319+ ### Macaroon Management
320+
321+ | RPC | Description |
322+ | -----| -------------|
323+ | ` CreateMacaroon ` | Create a macaroon and return its private hex token in ` token ` |
324+ | ` ListMacaroons ` | List IDs, names, permissions, and caveats, without secrets |
325+ | ` RevokeMacaroon ` | Revoke a macaroon by ID |
326+ | ` GetPermissions ` | Show the caller's ID, name, usable permissions, and caveats |
327+
328+ The first three RPCs require ` macaroons:manage ` or ` admin ` . You can only create or revoke
329+ tokens whose permissions you have. The last unrestricted admin token cannot be revoked.
330+
235331### Metrics
236332
237333Metrics are served as a plain HTTP GET endpoint (not gRPC):
0 commit comments