add TLS support

This commit is contained in:
Maksim Fomenkov
2022-10-17 10:49:57 +03:00
parent 07d97029a5
commit 4d3826d29b
5 changed files with 44 additions and 12 deletions

View File

@@ -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);
}