Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function parseEnv(
req: LndRequest,
_res: Response,
next: NextFunction
): void {
try {
testEnvVars()
let { OPEN_NODE_KEY, LND_TLS_CERT, LND_MACAROON, LND_SOCKET } = getEnvVars()
// if the tests pass above and we don't have a
// OPEN_NODE_KEY then we need to setup the lnd service
if (!OPEN_NODE_KEY) {
const { lnd } = lnService.authenticatedLndGrpc({
cert: LND_TLS_CERT,
macaroon: LND_MACAROON,
socket: LND_SOCKET,
})
req.lnd = lnd
} else {
const env = process.env.ENVIRONMENT || 'dev'
const opennode = require('opennode')
opennode.setCredentials(OPEN_NODE_KEY, env)
req.opennode = opennode
}
next()
} catch (e) {
console.error(
'Problem with configs for connecting to lightning node:',
e.message
const socket = process.env[`SSS_LND_${networkName}_GRPC_HOST`];
if (!cert) {
throw new Error('ExpectedDaemonCert');
}
if (!macaroon) {
throw new Error('ExpectedDaemonMacaroon');
}
if (!socket) {
throw new Error('ExpectedDaemonHost');
}
try {
lnd = authenticatedLndGrpc({cert, macaroon, socket}).lnd;
} catch (err) {
throw new Error('FailedToInstantiateDaemon');
}
const sub = subscribeToInvoices({lnd});
daemons[network] = {lnd, sub};
// Clear daemon cache on errors or end of subscription
// This subscription allows opportunistic reconnecting on remote restarts.
daemons[network].sub.on('invoice_updated', () => {});
daemons[network].sub.on('end', () => daemons[network] = null);
daemons[network].sub.on('error', ({}) => daemons[network] = null);
daemons[network].sub.on('status', () => {});
return lnd;
lnd: ['wallet', ({wallet}, cbk) => {
try {
return cbk(null, authenticatedLndGrpc({
cert: wallet.cert,
macaroon: wallet.macaroon,
socket: wallet.host,
}).lnd);
} catch (err) {
return cbk([503, 'FailedToInstantiateWalletLnd', err]);
}
}],
lnd: ['credentials', ({credentials}, cbk) => {
return cbk(null, authenticatedLndGrpc({
cert: credentials.cert,
macaroon: credentials.macaroon,
socket: credentials.socket,
}).lnd);
}],
return asyncMap(getNodeCredentials, ({credentials, node}, cbk) => {
if (!credentials) {
return cbk([400, 'InvalidCredentialsForNode', {node}]);
}
if (!credentials.macaroon) {
return cbk(null, {
node_name: node,
locked_to_keys: credentials.encrypted_to,
});
}
const {lnd} = authenticatedLndGrpc(credentials);
return getWalletInfo({lnd}, (err, res) => {
if (!!err) {
return cbk(null, {node_name: node});
}
return cbk(null, {
node_name: node,
is_online: res.is_synced_to_chain,
});
});
},
cbk);
lnd: ['credentials', ({credentials}, cbk) => {
return cbk(null, authenticatedLndGrpc({
cert: credentials.cert,
macaroon: credentials.macaroon,
socket: credentials.socket,
}).lnd);
}],
lnd: ['credentials', ({credentials}, cbk) => {
return cbk(null, authenticatedLndGrpc({
cert: credentials.cert,
macaroon: credentials.macaroon,
socket: credentials.socket,
}));
}],
},
lnd: ['credentials', ({credentials}, cbk) => {
return cbk(null, authenticatedLndGrpc({
cert: credentials.cert,
macaroon: credentials.macaroon,
socket: credentials.socket,
}).lnd);
}],