@tdxvolt/volt-client-grpc 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +257 -107
- package/package.json +2 -2
- package/src/constants.js +1 -1
- package/src/grpc-call.js +105 -54
- package/src/grpc-utils.js +3 -3
- package/src/rpc-invocation.js +47 -11
- package/src/volt-client-internal.js +36 -21
- package/src/volt-client.js +43 -13
- package/src/volt-connection.js +16 -2
- package/src/volt-credential.js +6 -2
package/src/volt-client.js
CHANGED
|
@@ -31,7 +31,6 @@ export class VoltClient extends EventEmitter {
|
|
|
31
31
|
}
|
|
32
32
|
this._grpc = grpc;
|
|
33
33
|
this._cachedClient = null;
|
|
34
|
-
this._cachedRemoteClient = null;
|
|
35
34
|
this._session = null;
|
|
36
35
|
this._config = null;
|
|
37
36
|
this._voltConfig = null;
|
|
@@ -56,12 +55,36 @@ export class VoltClient extends EventEmitter {
|
|
|
56
55
|
return this._voltConfig;
|
|
57
56
|
}
|
|
58
57
|
|
|
58
|
+
get connection() {
|
|
59
|
+
return this._voltConnection;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
close() {
|
|
63
|
+
if (this._cachedClient) {
|
|
64
|
+
this._grpc.closeClient(this._cachedClient);
|
|
65
|
+
this._cachedClient = null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (let serviceKey in Object.keys(this._cachedService)) {
|
|
69
|
+
if (this._cachedService[serviceKey]) {
|
|
70
|
+
this._grpc.closeClient(this._cachedService[serviceKey]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this._cachedService = {};
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
/**
|
|
60
78
|
* Initialises a binding and connection to the volt.
|
|
61
79
|
* @param {string} [config] - the location of the Volt configuration file, or a configuration object
|
|
62
80
|
* @param {object} [extras] - additional configuration properties
|
|
63
81
|
*/
|
|
64
|
-
async initialise(
|
|
82
|
+
async initialise(
|
|
83
|
+
config,
|
|
84
|
+
extras = {},
|
|
85
|
+
ownDID = false,
|
|
86
|
+
didRegistryList = undefined
|
|
87
|
+
) {
|
|
65
88
|
try {
|
|
66
89
|
if (!config) {
|
|
67
90
|
throw new Error(
|
|
@@ -126,7 +149,15 @@ export class VoltClient extends EventEmitter {
|
|
|
126
149
|
}
|
|
127
150
|
|
|
128
151
|
if (voltDID) {
|
|
129
|
-
const didConfig = await fetchVoltConfigFromDID.call(
|
|
152
|
+
const didConfig = await fetchVoltConfigFromDID.call(
|
|
153
|
+
this,
|
|
154
|
+
voltDID,
|
|
155
|
+
didRegistryList
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// Remove the relay list from the DID config, as it would overwrite the relay in the supplied config.
|
|
159
|
+
delete didConfig.relay;
|
|
160
|
+
|
|
130
161
|
this._config = { ...this._config, volt: didConfig };
|
|
131
162
|
log("resolved config from DID: %s", JSON.stringify(didConfig, null, 2));
|
|
132
163
|
} else if (voltHttpAddress && !this._config?.volt?.id) {
|
|
@@ -156,7 +187,7 @@ export class VoltClient extends EventEmitter {
|
|
|
156
187
|
|
|
157
188
|
await this._credential.initialise();
|
|
158
189
|
|
|
159
|
-
if (!this.
|
|
190
|
+
if (!this.isRelayed) {
|
|
160
191
|
// If we're not connecting via a Relay, we must have the address and CA.
|
|
161
192
|
if (
|
|
162
193
|
!this._voltConfig.address ||
|
|
@@ -179,15 +210,15 @@ export class VoltClient extends EventEmitter {
|
|
|
179
210
|
} else {
|
|
180
211
|
// No certificate present in the cache yet => we need to authenticate.
|
|
181
212
|
try {
|
|
182
|
-
isBound = await authenticateInternal.call(this);
|
|
213
|
+
isBound = await authenticateInternal.call(this, false, ownDID);
|
|
183
214
|
} catch (bindErr) {
|
|
184
215
|
if (bindErr.message === "invalid arguments") {
|
|
185
216
|
// This is usually the result of a missing challenge signature or credential.
|
|
186
217
|
log(
|
|
187
218
|
"failure authenticating on Volt - did you supply a challenge code or verified credential?"
|
|
188
219
|
);
|
|
189
|
-
throw bindErr;
|
|
190
220
|
}
|
|
221
|
+
throw bindErr;
|
|
191
222
|
}
|
|
192
223
|
}
|
|
193
224
|
|
|
@@ -196,7 +227,7 @@ export class VoltClient extends EventEmitter {
|
|
|
196
227
|
throw new Error("Volt authentication failed");
|
|
197
228
|
} else {
|
|
198
229
|
// Perist the configuration.
|
|
199
|
-
this.
|
|
230
|
+
this._credential.saveCache();
|
|
200
231
|
}
|
|
201
232
|
|
|
202
233
|
return Promise.resolve(this._config);
|
|
@@ -247,7 +278,7 @@ export class VoltClient extends EventEmitter {
|
|
|
247
278
|
});
|
|
248
279
|
}
|
|
249
280
|
|
|
250
|
-
if (this.
|
|
281
|
+
if (this.isRelayed) {
|
|
251
282
|
if (!this._voltConfig?.relay?.address) {
|
|
252
283
|
throw new Error(
|
|
253
284
|
"Remote connection enabled but no Relay address - have you called start()?"
|
|
@@ -274,14 +305,10 @@ export class VoltClient extends EventEmitter {
|
|
|
274
305
|
}
|
|
275
306
|
}
|
|
276
307
|
|
|
277
|
-
get
|
|
308
|
+
get isRelayed() {
|
|
278
309
|
return !!(this._voltConfig?.relay && this._voltConfig.id);
|
|
279
310
|
}
|
|
280
311
|
|
|
281
|
-
get isVoltRelay() {
|
|
282
|
-
return this.isRemote && !this._voltConfig?.relay.cloud;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
312
|
connect(helloPayload) {
|
|
286
313
|
return connectInternal.call(this, helloPayload);
|
|
287
314
|
}
|
|
@@ -613,6 +640,9 @@ export class VoltClient extends EventEmitter {
|
|
|
613
640
|
*/
|
|
614
641
|
SqlExecuteJSON(request) {
|
|
615
642
|
return new Promise((resolve, reject) => {
|
|
643
|
+
if (!request.start) {
|
|
644
|
+
request = { start: request };
|
|
645
|
+
}
|
|
616
646
|
const call = this.SqlExecute(request);
|
|
617
647
|
|
|
618
648
|
let header;
|
package/src/volt-connection.js
CHANGED
|
@@ -96,8 +96,18 @@ function _doConnect(connectHello) {
|
|
|
96
96
|
break;
|
|
97
97
|
}
|
|
98
98
|
case "invoke_request": {
|
|
99
|
-
log("received invoke request");
|
|
100
|
-
|
|
99
|
+
log("received invoke request %s", response.invoke_request.invoke_id);
|
|
100
|
+
// Pause the call while we process the invoke request to avoid getting
|
|
101
|
+
// CANCELLED errors from grpc - we should perhaps leave this to the
|
|
102
|
+
// client to manage as it may be overkill in some cases.
|
|
103
|
+
this.call.pause();
|
|
104
|
+
try {
|
|
105
|
+
this.emit("invoke_request", response.invoke_request);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
log("error processing invoke request [%s]", err.message);
|
|
108
|
+
} finally {
|
|
109
|
+
this.call.resume();
|
|
110
|
+
}
|
|
101
111
|
break;
|
|
102
112
|
}
|
|
103
113
|
case "evt": {
|
|
@@ -169,6 +179,10 @@ export default class VoltConnection extends EventEmitter {
|
|
|
169
179
|
this._helloPayload = undefined;
|
|
170
180
|
}
|
|
171
181
|
|
|
182
|
+
get connectionId() {
|
|
183
|
+
return this._connectionId;
|
|
184
|
+
}
|
|
185
|
+
|
|
172
186
|
connect(helloPayload, throwOnFail) {
|
|
173
187
|
this._helloPayload = helloPayload;
|
|
174
188
|
if (throwOnFail) {
|
package/src/volt-credential.js
CHANGED
|
@@ -52,7 +52,7 @@ export class VoltCredential {
|
|
|
52
52
|
this._cryptoCache.ca = this._voltConfig.ca_pem;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// Extract Volt public key
|
|
55
|
+
// Extract Volt public key.
|
|
56
56
|
this._voltPublicKey = this._voltConfig.public_key;
|
|
57
57
|
|
|
58
58
|
const voltKey = keyFromPem(this._voltPublicKey).publicKey;
|
|
@@ -92,6 +92,10 @@ export class VoltCredential {
|
|
|
92
92
|
return this._voltFingerprint;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
get key() {
|
|
96
|
+
return this.getKey();
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
getKey() {
|
|
96
100
|
const key = keyFromPem(this._cryptoCache.key);
|
|
97
101
|
return key;
|
|
@@ -107,7 +111,7 @@ export class VoltCredential {
|
|
|
107
111
|
return Promise.resolve(this.getKey());
|
|
108
112
|
} else {
|
|
109
113
|
log("creating key");
|
|
110
|
-
this._cryptoCache.key = createSigningKey();
|
|
114
|
+
this._cryptoCache.key = JSON.parse(createSigningKey()).private_pem;
|
|
111
115
|
const key = keyFromPem(this._cryptoCache.key);
|
|
112
116
|
log("successfully created key");
|
|
113
117
|
return Promise.resolve(key);
|