@@ -158,6 +158,46 @@ Examples:
158
158
$ lncli --macaroonpath=/safe/location/admin.macaroon getinfo
159
159
```
160
160
161
+ ## Using deterministic/pre-generated macaroons
162
+
163
+ All macaroons are derived from a secret root key (by default from the root key
164
+ with the ID ` "0" ` ). That root key is randomly generated when the macaroon store
165
+ is first initialized (when the wallet is created) and is therefore not
166
+ deterministic by default.
167
+
168
+ It can be useful to use a deterministic (or pre-generated) root key, which is
169
+ why the ` InitWallet ` RPC (or the ` lncli create ` or ` lncli createwatchonly `
170
+ counterparts) allows a root key to be specified.
171
+
172
+ Using a pre-generated root key can be useful for scenarios like:
173
+ * Testing: If a node is always initialized with the same root key for each test
174
+ run, then macaroons generated in one test run can be re-used in another run
175
+ and don't need to be re-derived.
176
+ * Remote signing setup: When using a remote signing setup where there are two
177
+ related ` lnd ` nodes (e.g. a watch-only and a signer pair), it can be useful
178
+ to generate a valid macaroon _ before_ any of the nodes are even started up.
179
+
180
+ ** Example** :
181
+
182
+ The following example shows how a valid macaroon can be generated before even
183
+ starting a node:
184
+
185
+ ``` shell
186
+ # Randomly generate a 32-byte long secret root key and encode it as hex.
187
+ ROOT_KEY=$( cat /dev/urandom | head -c32 | xxd -p -c32)
188
+
189
+ # Derive a read-only macaroon from that root key.
190
+ # NOTE: When using the --root_key flag, the `lncli bakemacaroon` command is
191
+ # fully offline and does not need to connect to any lnd node.
192
+ lncli bakemacaroon --root_key $ROOT_KEY --save_to /tmp/info.macaroon info:read
193
+
194
+ # Create the lnd node now, using the same root key.
195
+ lncli create --mac_root_key $ROOT_KEY
196
+
197
+ # Use the pre-generated macaroon for a call.
198
+ lncli --macaroonpath /tmp/info.macaroon getinfo
199
+ ```
200
+
161
201
## Using Macaroons with GRPC clients
162
202
163
203
When interacting with ` lnd ` using the GRPC interface, the macaroons are encoded
0 commit comments