aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/createLnrpc.js40
-rw-r--r--lib/lnd.js36
2 files changed, 36 insertions, 40 deletions
diff --git a/lib/createLnrpc.js b/lib/createLnrpc.js
deleted file mode 100644
index 083ad961..00000000
--- a/lib/createLnrpc.js
+++ /dev/null
@@ -1,40 +0,0 @@
-const fs = require("fs");
-const grpc = require("grpc");
-const createLnrpc = require("lnrpc");
-const { promisify } = require("util");
-
-module.exports = async ({ server, tls, macaroon }) => {
- const lnrpc = await createLnrpc({ server, tls, macaroonPath: macaroon });
-
- // Resolve proxy instance
- return new Proxy(lnrpc, {
- /**
- * Promisify each lightning RPC method
- * @param {lnrpc.Lightning} target
- * @param {String} key
- * @return {Promise} {Any}
- */
- get(target, key) {
- const method = target[key];
-
- if (typeof key === "string" && typeof method === "function") {
- const streaming = key.match(/openChannel$|sendPayment|subscribe.*/);
- let fn;
-
- if (streaming) {
- if (key === "sendPayment" || key === "sendToRoute") {
- fn = params => method.call(lnrpc, target.meta, params);
- } else {
- fn = params => method.call(lnrpc, params, target.meta);
- }
- } else {
- fn = params => promisify(method).call(lnrpc, params, target.meta);
- }
-
- return fn;
- }
-
- return target[key]; // forward
- }
- });
-};
diff --git a/lib/lnd.js b/lib/lnd.js
new file mode 100644
index 00000000..8bb2df48
--- /dev/null
+++ b/lib/lnd.js
@@ -0,0 +1,36 @@
+const fs = require('fs');
+const path = require('path');
+const grpc = require('grpc');
+const protoLoader = require('@grpc/proto-loader');
+const { promisify } = require('util');
+
+
+module.exports = ({ tls, macaroon, server }) => {
+ const packageDefinition = protoLoader.loadSync('config/rpc.proto', {
+ keepCase: true,
+ longs: String,
+ enums: String,
+ defaults: true,
+ oneofs: true
+ });
+ const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
+ process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
+ const lndCert = fs.readFileSync(tls);
+ const sslCreds = grpc.credentials.createSsl(lndCert);
+ const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
+ const macaroonFile = fs.readFileSync(macaroon).toString('hex');
+ const metadata = new grpc.Metadata()
+ metadata.add('macaroon', macaroonFile);
+ callback(null, metadata);
+ });
+ const creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
+ const lnd = new lnrpc.Lightning(server, creds);
+
+ return new Proxy(lnd, {
+ get(target, key) {
+ const method = target[key];
+ if (typeof method === 'function' && !key.startsWith('sub')) return promisify(method);
+ return target[key];
+ },
+ });
+}