Replace deprecated request/request-promise with axios
request has been deprecated since 2020 with an unfixed SSRF advisory and
pins vulnerable copies of form-data (critical), qs, tough-cookie and
uuid - 8 of the 13 remaining production audit findings, none fixable by
version bumps (issue #1634, item 1).
All 36 backend files that imported request-promise now use a small
compatibility wrapper (server/utils/request.ts) backed by axios, which
is already a production dependency. The wrapper accepts the existing
options shape (qs, form - object or pre-encoded string, body,
baseUrl/uri, rejectUnauthorized, json), resolves with the response body
directly, and rejects with a plain object mirroring request-promise's
StatusCodeError/RequestError shape, so CommonService.handleError works
unchanged (ECONNREFUSED -> 503, Eclair StatusCodeError -> 500, nested
error body extraction). Auth headers are excluded from rejected errors
so they cannot leak into logs. Callers without json: true (block
explorer, currency rates) still get raw text bodies, and LND's
line-delimited /v2/router/send stream still surfaces as a string for
the existing parser.
Only behavioral code change: CLN verifyMessage used request-promise's
callback style and was ported to the same promise style as signMessage;
four Eclair handlers gained explicit returns to satisfy
noImplicitReturns once the import became typed.
Production npm audit drops from 13 findings (2 critical) to 6 low, all
in the crypto-browserify/elliptic chain tracked in #1634.
Verified against the docker regtest fixture with 43 API checks across
LND, Core Lightning and Eclair: reads, invoice creation, a routed LND
payment over the streaming endpoint, cross-implementation payments from
CLN and Eclair, message sign/verify, channel backup to disk, and
bad-invoice/node-unreachable error mapping. Lint and both production
builds are clean.
2026-07-19 12:08:05 -07:00
|
|
|
import request from '../../utils/request.js';
|
2021-12-29 18:08:41 -05:00
|
|
|
import { Logger, LoggerService } from '../../utils/logger.js';
|
|
|
|
|
import { Common, CommonService } from '../../utils/common.js';
|
2024-06-10 12:40:37 -07:00
|
|
|
import { SelectedNode } from '../../models/config.model.js';
|
2021-12-29 18:08:41 -05:00
|
|
|
let options = null;
|
|
|
|
|
const logger: LoggerService = Logger;
|
|
|
|
|
const common: CommonService = Common;
|
|
|
|
|
|
2024-06-10 12:40:37 -07:00
|
|
|
export const getAliasFromPubkey = (selNode: SelectedNode, pubkey) => {
|
|
|
|
|
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + pubkey;
|
2021-12-29 18:08:41 -05:00
|
|
|
return request(options).then((res) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Graph', msg: 'Alias Received', data: res.node.alias });
|
2021-12-29 18:08:41 -05:00
|
|
|
return res.node.alias;
|
|
|
|
|
}).
|
2022-11-21 13:44:43 -08:00
|
|
|
catch((err) => pubkey.substring(0, 20));
|
2021-12-29 18:08:41 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getDescribeGraph = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Network Graph..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph';
|
2021-12-29 18:08:41 -05:00
|
|
|
request.get(options).then((body) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Network Graph Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Describe Graph Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getGraphInfo = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Information..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/info';
|
2021-12-29 18:08:41 -05:00
|
|
|
request.get(options).then((body) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Information Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Graph Information Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getGraphNode = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Node Information..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/node/' + req.params.pubKey;
|
2021-12-29 18:08:41 -05:00
|
|
|
request(options).then((body) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Node Information Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Get Node Info Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getGraphEdge = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Edge Information..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
2021-12-29 18:08:41 -05:00
|
|
|
request(options).then((body) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Edge Information Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Get Edge Info Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getQueryRoutes = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Routes..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/routes/' + req.params.destPubkey + '/' + req.params.amount;
|
2021-12-29 18:08:41 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes URL', data: options.url });
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes Received', data: body });
|
|
|
|
|
if (body.routes && body.routes.length && body.routes.length > 0 && body.routes[0].hops && body.routes[0].hops.length && body.routes[0].hops.length > 0) {
|
2022-08-17 15:48:04 -07:00
|
|
|
return Promise.all(body.routes[0].hops?.map((hop) => getAliasFromPubkey(req.session.selectedNode, hop.pub_key))).
|
2021-12-29 18:08:41 -05:00
|
|
|
then((values) => {
|
2022-08-17 15:48:04 -07:00
|
|
|
body.routes[0].hops?.map((hop, i) => {
|
2021-12-29 18:08:41 -05:00
|
|
|
hop.hop_sequence = i + 1;
|
|
|
|
|
hop.pubkey_alias = values[i];
|
|
|
|
|
return hop;
|
|
|
|
|
});
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Routes with Alias Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).
|
|
|
|
|
catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Get Query Routes Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Routes Received', data: body });
|
2021-12-29 18:08:41 -05:00
|
|
|
return res.status(200).json(body);
|
|
|
|
|
}
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Get Query Routes Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getRemoteFeePolicy = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Remote Fee Policy..' });
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 12:40:37 -07:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
2021-12-29 18:08:41 -05:00
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Edge Info Received', data: body });
|
|
|
|
|
let remoteNodeFee = {};
|
|
|
|
|
if (body.node1_pub === req.params.localPubkey) {
|
|
|
|
|
remoteNodeFee = {
|
|
|
|
|
time_lock_delta: body.node2_policy.time_lock_delta,
|
|
|
|
|
fee_base_msat: body.node2_policy.fee_base_msat,
|
|
|
|
|
fee_rate_milli_msat: body.node2_policy.fee_rate_milli_msat
|
|
|
|
|
};
|
|
|
|
|
} else if (body.node2_pub === req.params.localPubkey) {
|
|
|
|
|
remoteNodeFee = {
|
|
|
|
|
time_lock_delta: body.node1_policy.time_lock_delta,
|
|
|
|
|
fee_base_msat: body.node1_policy.fee_base_msat,
|
|
|
|
|
fee_rate_milli_msat: body.node1_policy.fee_rate_milli_msat
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Remote Fee Policy Received', data: remoteNodeFee });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(remoteNodeFee);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Remote Fee Policy Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getAliasesForPubkeys = (req, res, next) => {
|
|
|
|
|
options = common.getOptions(req);
|
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
|
|
|
|
if (req.query.pubkeys) {
|
|
|
|
|
const pubkeyArr = req.query.pubkeys.split(',');
|
2022-08-17 15:48:04 -07:00
|
|
|
return Promise.all(pubkeyArr?.map((pubkey) => getAliasFromPubkey(req.session.selectedNode, pubkey))).
|
2021-12-29 18:08:41 -05:00
|
|
|
then((values) => {
|
2022-01-16 15:55:50 -05:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Node Alias', data: values });
|
2021-12-29 18:08:41 -05:00
|
|
|
res.status(200).json(values);
|
|
|
|
|
}).
|
|
|
|
|
catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Graph', 'Get Aliases for Pubkeys Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return res.status(200).json([]);
|
|
|
|
|
}
|
|
|
|
|
};
|