add TLS support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const grpc = require("@grpc/grpc-js");
|
||||
const path = require('path')
|
||||
const protoLoader = require("@grpc/proto-loader");
|
||||
const fs = require('fs');
|
||||
|
||||
const PROTO_PATH = path.join(__dirname, "../grpc/proto/blockchain.proto");
|
||||
|
||||
@@ -15,11 +16,21 @@ const options = {
|
||||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
||||
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
||||
|
||||
export function describe(url, handler) {
|
||||
export function describe(url, ca, cert, key, handler) {
|
||||
let credentials = grpc.credentials.createInsecure()
|
||||
if (ca || cert || key) {
|
||||
console.log("Using TLS")
|
||||
credentials = grpc.credentials.createSsl(
|
||||
ca ? fs.readFileSync(ca) : null,
|
||||
key ? fs.readFileSync(key) : null,
|
||||
cert ? fs.readFileSync(cert) : null
|
||||
);
|
||||
}
|
||||
const client = new emerald.Blockchain(
|
||||
url,
|
||||
grpc.credentials.createInsecure()
|
||||
credentials
|
||||
);
|
||||
|
||||
console.log('Connecting to: ' + url + '...')
|
||||
client.Describe({}, handler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user