-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (43 loc) · 1.53 KB
/
index.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
const proofs = require("./utils/proofs");
const digest = require("./utils/digest");
module.exports.inclusionVerify = function (path, at, i, root, leaf) {
return proofs.inclusionVerify(path, at, i, root, leaf)
};
module.exports.consistencyVerify = function (path, at, i, root, leaf) {
return proofs.consistencyVerify(path, at, i, root, leaf)
};
module.exports.digest = function (index, key, value) {
return digest(index, key, value);
};
module.exports.client = function (immudbUrl) {
return _client(immudbUrl)
};
function _client(immudbUrl) {
if (!immudbUrl)
return null;
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const path = require("path");
const safeGet = require('./handler/safeGet');
const safeSet = require('./handler/safeSet');
const rootService = require('./client/rootService');
const PROTO_PATH = path.resolve(__dirname + "/schema.proto");
const packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
});
const immudbSchema = grpc.loadPackageDefinition(packageDefinition).immudb.schema;
const client = new immudbSchema.ImmuService(immudbUrl, grpc.credentials.createInsecure());
const rs = new rootService(client);
rs.init();
client._safeGet = client.safeGet;
client._safeSet = client.safeSet;
client.safeGet = (request, callback) => safeGet.call(client, rs, request, callback);
client.safeSet = (request, callback) => safeSet.call(client, rs, request, callback);
return client;
}