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 7 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. // Wait for the gRPC connection to be established.
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.service.waitForReady(getDeadline(5), err => { this.service.waitForReady(getDeadline(10), err => {
if (err) { if (err) {
return reject(err) return reject(err)
} }

23
app/lib/lnd/util.js

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

16
app/lib/lnd/walletUnlocker.js

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

Loading…
Cancel
Save