Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 78b7279

Browse files
committed
auth: add support for macaroons
Previously, the app was running lnd with the —no-macaroons option. This commit adds the ability for the app to send macaroons to lnd with each gRPC call.
1 parent fa4a401 commit 78b7279

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

apps/desktop/main.dev.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const processes = [
7171
isDev ? '' : '--neutrino.connect=127.0.0.1:18333',
7272
isDev ? '' : '--debuglevel=info',
7373
isDev ? '' : '--autopilot.active',
74-
'--no-macaroons',
7574
'--noencryptwallet',
7675
],
7776
},
@@ -81,17 +80,21 @@ runProcesses(processes, logs)
8180

8281
let intervalId
8382
let certPath
83+
let macaroonPath
8484
const homedir = os.homedir()
8585

8686
switch (os.platform()) {
8787
case 'darwin':
8888
certPath = path.join(homedir, 'Library/Application\ Support/Lnd/tls.cert')
89+
macaroonPath = path.join(homedir, 'Library/Application\ Support/Lnd/admin.macaroon')
8990
break
9091
case 'linux':
9192
certPath = path.join(homedir, '.lnd/tls.cert')
93+
macaroonPath = path.join(homedir, '.lnd/admin.macaroon')
9294
break
9395
case 'win32':
9496
certPath = path.join(homedir, 'AppData', 'Local', 'Lnd', 'tls.cert')
97+
macaroonPath = path.join(homedir, 'AppData', 'Local', 'Lnd', 'admin.macaroon')
9598
break
9699
default:
97100
break
@@ -190,9 +193,13 @@ const createWindow = () => {
190193
const credentials = grpc.credentials.createSsl(lndCert)
191194
const { lnrpc } = grpc.load(path.join(__dirname, 'rpc.proto'))
192195
const connection = new lnrpc.Lightning('localhost:10009', credentials)
196+
let metadata = new grpc.Metadata()
197+
const macaroonHex = fs.readFileSync(macaroonPath).toString("hex")
198+
metadata.add('macaroon', macaroonHex)
193199
const serverReady = cb =>
194200
grpc.waitForClientReady(connection, Infinity, cb)
195201
global.connection = connection
202+
global.metadata = metadata
196203
global.serverReady = serverReady
197204
finishCreateWindow()
198205
}

packages/redux-grpc-middleware/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { remote } from 'electron'
66
const defaults = {
77
global: {
88
connection: 'connection',
9+
metadata: 'metadata',
910
serverReady: 'serverReady',
1011
},
1112
selector: 'default',
@@ -18,6 +19,7 @@ export const SERVER_RUNNING = 'GRPC/SERVER_RUNNING'
1819
export default (opts = {}) => {
1920
const options = { ...defaults, ...opts }
2021
const serverReady = remote.getGlobal(options.global.serverReady)
22+
const metadata = remote.getGlobal(options.global.metadata)
2123

2224
let client
2325
let ready = false
@@ -67,7 +69,11 @@ export default (opts = {}) => {
6769
if (client[method]) {
6870
let streamCall
6971
try {
70-
streamCall = client[method](body ? { body } : params)
72+
if (method === "sendPayment") {
73+
streamCall = client[method](metadata, { body })
74+
} else {
75+
streamCall = client[method](params, metadata)
76+
}
7177
} catch (err) {
7278
console.log('Error From Stream Method', method, err)
7379
} finally {
@@ -83,7 +89,8 @@ export default (opts = {}) => {
8389

8490
return new Promise((resolve, reject) => {
8591
try {
86-
client[method] && client[method](body, { deadline }, (error, res) => {
92+
client[method] && client[method](body, metadata, { deadline },
93+
(error, res) => {
8794
if (error) {
8895
ERROR && next({ type: ERROR, error })
8996
reject({ ...error })

0 commit comments

Comments
 (0)