-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverificationServer.js
85 lines (72 loc) · 3.91 KB
/
verificationServer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var express = require("express");
var bodyParser = require("body-parser");
// var routes = require("./routes/routes.js");
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// routes(app);
//define util function.
const util = require('util');
const exec = util.promisify(require('child_process').exec);
var server = app.listen(3001, function () {
console.log("app running on port.", server.address().port);
});
//setting up JS rpc
var grpc = require('grpc');
var fs = require("fs");
// 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'
// Lnd cert is at ~/.lnd/tls.cert on Linux and
// ~/Library/Application Support/Lnd/tls.cert on Mac
var lndCert = fs.readFileSync("~/.lnd/tls.cert");
var credentials = grpc.credentials.createSsl(lndCert);
console.log('1')
var lnrpcDescriptor = grpc.load("rpc.proto");
var lnrpc = lnrpcDescriptor.lnrpc;
var lightning = new lnrpc.Lightning('localhost:10009', credentials);
console.log('2')
let base64EncodedCert = 'LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUI5ekNDQVoyZ0F3SUJBZ0lSQVArajUvcU9XVmV2d0FoU2tTRnRjYTR3Q2dZSUtvWkl6ajBFQXdJd05URWYKTUIwR0ExVUVDaE1XYkc1a0lHRjFkRzluWlc1bGNtRjBaV1FnWTJWeWRERVNNQkFHQTFVRUF4TUpZbTlzZEdGMAphRzl1TUI0WERURTVNRFF3TkRFNU1qYzFOMW9YRFRJd01EVXlPVEU1TWpjMU4xb3dOVEV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HwqmGu';
const lnService = require('ln-service');
console.log('3')
const lnd = lnService.lightningDaemon({
cert: base64EncodedCert,
macaroon: base64EncodedMacaroon,
socket: '127.0.0.1:10009',
});
console.log('4')
lnService.getWalletInfo({lnd}, (error, result) => {
console.log(result);
console.log(error);
});
console.log('5')
// var lightning = require("bitcoin-lightning-nodejs");
// var request = {
// msg: 'message1'
// };
// lightning.ln.signMessage(request, function(err, response) {
// console.log(response);
// console.log(err);
// });
async function sendChallenge(credential) {
let nodeId = credential.id;
const { stdout, stderr } = await exec('lncli --network=testnet listchannels');
console.log('stdout:', stdout);
console.log('stderr:', stderr);
return stdout;
}
//verifying node gets the DID document from provider
app.post('/verifyCredential', async function(request, response){
let unverifiedCredential = request.body;
// verifying node challenges provider of document to prove they are the subject (id) in the document : "987638276 sign this message"
let challengeResults = sendChallenge(request.body)
let signedCredential = request.body;
if (isChannelVerified) {
response.send(signedCredential);
} else {
response.status(500).send('Channel not found');
}
response.send(channelList); // echo the result back but signed
});