-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlnd.js
59 lines (48 loc) · 1.81 KB
/
lnd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// const grpc = require('@grpc/grpc-js');
const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader');
const fs = require("fs");
const path = require('path');
const config = {
macaroon: process.env.MACAROON,
tls: process.env.TLS_PATH,
lnd_host: process.env.LND_HOST,
lnd_port: process.env.LND_PORT
}
//// gRPC INITIALIZATION
// Due to updated ECDSA generated tls.cert we need to let gprc know that
// we need to use that cipher suite otherwise there will be a handhsake
// error when we communicate with the lnd rpc server.
//process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA:ECDHE-RSA-AES128-GCM-SHA256'
// We need to give the proto loader some extra options, otherwise the code won't
// fully work with lnd.
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync([ path.join(__dirname, 'lightning.proto') ],
loaderOptions);
let macaroon = config.macaroon
// Load lnd macaroon
// let m = fs.readFileSync(config.macaroon);
// let macaroon = m.toString('hex');
// Build meta data credentials
let metadata = new grpc.Metadata()
metadata.add('macaroon', macaroon)
let macaroonCreds = grpc.credentials.createFromMetadataGenerator((_args, callback) => {
callback(null, metadata);
});
// Combine credentials
let lndCert = fs.readFileSync(config.tls);
let sslCreds = grpc.credentials.createSsl(lndCert);
let credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
// Create lightning interface
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const lnClient = new lnrpc.Lightning(`${config.lnd_host}:${config.lnd_port}`, credentials);
module.exports = {
lnClient,
}