Browse Source

fix(grpc): do not use macaroon with WalletUnlocker

The WalletUnlocker service does not require the use of macaroons so do
not attempt to pass them when creating or unlocking a wallet.
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
e47eacfa8c
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 2
      app/lib/lnd/lightning.js
  2. 23
      app/lib/lnd/util.js
  3. 16
      app/lib/lnd/walletUnlocker.js

2
app/lib/lnd/lightning.js

@ -95,7 +95,7 @@ class Lightning {
// Wait for the gRPC connection to be established.
return new Promise((resolve, reject) => {
this.service.waitForReady(getDeadline(5), err => {
this.service.waitForReady(getDeadline(10), err => {
if (err) {
return reject(err)
}

23
app/lib/lnd/util.js

@ -165,18 +165,19 @@ export const createSslCreds = async certPath => {
export const createMacaroonCreds = async macaroonPath => {
const metadata = new grpc.Metadata()
// If it's not a filepath, then assume it is a hex encoded string.
if (macaroonPath === basename(macaroonPath)) {
metadata.add('macaroon', macaroonPath)
} else {
const macaroon = await fsReadFile(macaroonPath).catch(e => {
const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
error.code = 'LND_GRPC_MACAROON_ERROR'
throw error
})
metadata.add('macaroon', macaroon.toString('hex'))
if (macaroonPath) {
// If it's not a filepath, then assume it is a hex encoded string.
if (macaroonPath === basename(macaroonPath)) {
metadata.add('macaroon', macaroonPath)
} else {
const macaroon = await fsReadFile(macaroonPath).catch(e => {
const error = new Error(`Macaroon path could not be accessed: ${e.message}`)
error.code = 'LND_GRPC_MACAROON_ERROR'
throw error
})
metadata.add('macaroon', macaroon.toString('hex'))
}
}
return grpc.credentials.createFromMetadataGenerator((params, callback) =>
callback(null, metadata)
)

16
app/lib/lnd/walletUnlocker.js

@ -4,7 +4,7 @@ import grpc from 'grpc'
import { loadSync } from '@grpc/proto-loader'
import StateMachine from 'javascript-state-machine'
import LndConfig from './config'
import { getDeadline, validateHost, createSslCreds, createMacaroonCreds } from './util'
import { getDeadline, validateHost, createSslCreds } from './util'
import methods from './walletUnlockerMethods'
import { mainLog } from '../utils/log'
@ -43,7 +43,7 @@ class WalletUnlocker {
*/
async onBeforeConnect() {
mainLog.info('Connecting to WalletUnlocker gRPC service')
const { rpcProtoPath, host, cert, macaroon } = this.lndConfig
const { rpcProtoPath, host, cert } = this.lndConfig
// Verify that the host is valid before creating a gRPC client that is connected to it.
return await validateHost(host).then(async () => {
@ -62,19 +62,15 @@ class WalletUnlocker {
// Load gRPC package definition as a gRPC object hierarchy.
const rpc = grpc.loadPackageDefinition(packageDefinition)
// Create ssl and macaroon credentials to use with the gRPC client.
const [sslCreds, macaroonCreds] = await Promise.all([
createSslCreds(cert),
createMacaroonCreds(macaroon)
])
const credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds)
// Create ssl credentials to use with the gRPC client.
const sslCreds = await createSslCreds(cert)
// Create a new gRPC client instance.
this.service = new rpc.lnrpc.WalletUnlocker(host, credentials)
this.service = new rpc.lnrpc.WalletUnlocker(host, sslCreds)
// Wait for the gRPC connection to be established.
return new Promise((resolve, reject) => {
this.service.waitForReady(getDeadline(5), err => {
this.service.waitForReady(getDeadline(10), err => {
if (err) {
this.service.close()
return reject(err)

Loading…
Cancel
Save