-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscalardl-web-client-sdk.js
80 lines (73 loc) · 2.43 KB
/
scalardl-web-client-sdk.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
/* eslint-disable no-invalid-this */
const {
ClientServiceBase,
StatusCode,
ClientProperties,
} = require('@scalar-labs/scalardl-javascript-sdk-base');
const protobuf = require('./scalar_pb');
const {
LedgerClient,
LedgerPrivilegedClient,
AuditorClient,
AuditorPrivilegedClient,
} = require('./scalar_grpc_web_pb');
const {SignerFactory} = require('./signer');
const {
ClientServiceWithIndexedDb,
IndexedDbKeyNotFoundError,
IndexedDbOperationError,
} = require('./indexdb');
/**
* This class inherits ClientServiceBase.
* It needs to be constructed with LedgerClient
* and protobuf messages that are generated by gRPC tools
* @class
*/
class ClientService extends ClientServiceBase {
/**
* Inject LedgerClient and protobuf messages
* @constructor
* @param {Object} properties JSON Object used for setting client properties
*/
constructor(properties) {
const clientProperties = new ClientProperties(properties);
const host = clientProperties.getServerHost();
const auditorHost = clientProperties.getAuditorHost();
const tlsEnabled = clientProperties.getTlsEnabled();
const ledgerClientServiceURL = `${
tlsEnabled ? 'https' : 'http'
}://${host}:${clientProperties.getServerPort()}`;
const ledgerPriviledgedClientServiceURL = `${
tlsEnabled ? 'https' : 'http'
}://${host}:${clientProperties.getServerPrivilegedPort()}`;
const auditorClientServiceURL = `${
tlsEnabled ? 'https' : 'http'
}://${auditorHost}:${clientProperties.getAuditorPort()}`;
const auditorPriviledgedClientServiceURL = `${
tlsEnabled ? 'https' : 'http'
}://${auditorHost}:${clientProperties.getAuditorPrivilegedPort()}`;
const services = {
ledgerClient: new LedgerClient(ledgerClientServiceURL),
ledgerPrivileged: new LedgerPrivilegedClient(
ledgerPriviledgedClientServiceURL,
),
auditorClient: new AuditorClient(auditorClientServiceURL),
auditorPrivileged: new AuditorPrivilegedClient(
auditorPriviledgedClientServiceURL,
),
signerFactory: new SignerFactory(),
};
const metadata = {};
if (clientProperties.getAuthorizationCredential()) {
metadata.Authorization = clientProperties.getAuthorizationCredential();
}
super(services, protobuf, properties, metadata);
}
}
module.exports = {
ClientService,
ClientServiceWithIndexedDb,
IndexedDbKeyNotFoundError,
IndexedDbOperationError,
StatusCode,
};