@tdxvolt/volt-client-grpc 0.18.8 → 0.18.10
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 +33 -15
- package/package.json +2 -3
- package/src/volt-client-internal.js +25 -10
- package/src/volt-client.js +1 -3
- package/src/volt-credential.js +7 -1
- package/src/volt-proto-literals.js +0 -1
package/lib/index.cjs
CHANGED
|
@@ -9,12 +9,12 @@ var debug = require('debug');
|
|
|
9
9
|
var EventEmitter = require('events');
|
|
10
10
|
var fs = require('fs');
|
|
11
11
|
var path = require('path');
|
|
12
|
-
var bent = require('bent');
|
|
13
12
|
var uuid = require('uuid');
|
|
14
13
|
var Protobuf = require('protobufjs');
|
|
15
14
|
var camelCase = require('lodash.camelcase');
|
|
16
15
|
var descriptor = require('protobufjs/ext/descriptor/index.js');
|
|
17
16
|
var jwt = require('jsonwebtoken');
|
|
17
|
+
var crypto = require('crypto');
|
|
18
18
|
|
|
19
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
20
|
|
|
@@ -24,11 +24,11 @@ var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
|
|
|
24
24
|
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
25
25
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
26
26
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
27
|
-
var bent__default = /*#__PURE__*/_interopDefaultLegacy(bent);
|
|
28
27
|
var Protobuf__default = /*#__PURE__*/_interopDefaultLegacy(Protobuf);
|
|
29
28
|
var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
|
|
30
29
|
var descriptor__default = /*#__PURE__*/_interopDefaultLegacy(descriptor);
|
|
31
30
|
var jwt__default = /*#__PURE__*/_interopDefaultLegacy(jwt);
|
|
31
|
+
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
32
32
|
|
|
33
33
|
const constants = {
|
|
34
34
|
authTokenName: "volt-token",
|
|
@@ -3789,7 +3789,6 @@ message InvokeResponse {
|
|
|
3789
3789
|
// The invocation id to match the originating request.
|
|
3790
3790
|
uint64 invoke_id = 1;
|
|
3791
3791
|
|
|
3792
|
-
// Key exchange details for the response payload encryption. Only necessary for the first response.
|
|
3793
3792
|
InvokeRequestKeyExchange key_exchange = 2;
|
|
3794
3793
|
|
|
3795
3794
|
// The initialisation vector for the response payload encryption. This will be a random 16 byte value, that is different for each response.
|
|
@@ -4875,10 +4874,10 @@ async function authenticateInternal(
|
|
|
4875
4874
|
host: this._credential.cache.bindIp
|
|
4876
4875
|
};
|
|
4877
4876
|
|
|
4878
|
-
if (this.
|
|
4877
|
+
if (this._credential.cache.challenge_code) {
|
|
4879
4878
|
authenticateRequest.challenge = signBase64(
|
|
4880
4879
|
this._credential.cache.key,
|
|
4881
|
-
this.
|
|
4880
|
+
this._credential.cache.challenge_code
|
|
4882
4881
|
);
|
|
4883
4882
|
} else {
|
|
4884
4883
|
log$2(
|
|
@@ -5175,8 +5174,15 @@ function streamingCallInternal(methodType, method, request, service) {
|
|
|
5175
5174
|
|
|
5176
5175
|
async function fetchVoltConfig(discovery_url) {
|
|
5177
5176
|
try {
|
|
5178
|
-
const
|
|
5179
|
-
|
|
5177
|
+
const response = await fetch(discovery_url, {
|
|
5178
|
+
headers: { Accept: "application/json" }
|
|
5179
|
+
});
|
|
5180
|
+
|
|
5181
|
+
if (!response.ok) {
|
|
5182
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
5183
|
+
}
|
|
5184
|
+
|
|
5185
|
+
const fullVoltConfig = await response.json();
|
|
5180
5186
|
|
|
5181
5187
|
if (!fullVoltConfig || typeof fullVoltConfig !== "object") {
|
|
5182
5188
|
throw new Error(`invalid config resolved from: ${discovery_url}`);
|
|
@@ -5191,8 +5197,6 @@ async function fetchVoltConfig(discovery_url) {
|
|
|
5191
5197
|
"address",
|
|
5192
5198
|
"http_address",
|
|
5193
5199
|
"ca_pem",
|
|
5194
|
-
"challenge_code",
|
|
5195
|
-
"cloud",
|
|
5196
5200
|
"relay"
|
|
5197
5201
|
);
|
|
5198
5202
|
|
|
@@ -5211,8 +5215,15 @@ async function fetchVoltConfigFromDIDInternal(volt_did, registryUrl) {
|
|
|
5211
5215
|
throw new Error(`Invalid Volt DID: ${volt_did}`);
|
|
5212
5216
|
}
|
|
5213
5217
|
|
|
5214
|
-
const
|
|
5215
|
-
|
|
5218
|
+
const response = await fetch(didResolution, {
|
|
5219
|
+
headers: { Accept: "application/json" }
|
|
5220
|
+
});
|
|
5221
|
+
|
|
5222
|
+
if (!response.ok) {
|
|
5223
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
5224
|
+
}
|
|
5225
|
+
|
|
5226
|
+
const didDocument = await response.json();
|
|
5216
5227
|
const voltConfigServices = findDIDDocumentService(
|
|
5217
5228
|
didDocument,
|
|
5218
5229
|
constants.didServiceType.voltConfig
|
|
@@ -5252,7 +5263,11 @@ async function fetchVoltConfigFromDID(
|
|
|
5252
5263
|
}
|
|
5253
5264
|
}
|
|
5254
5265
|
|
|
5255
|
-
throw new Error(
|
|
5266
|
+
throw new Error(
|
|
5267
|
+
`Failed to fetch Volt config from any of these registries: ${registryList.join(
|
|
5268
|
+
", "
|
|
5269
|
+
)}`
|
|
5270
|
+
);
|
|
5256
5271
|
}
|
|
5257
5272
|
|
|
5258
5273
|
/* eslint-disable no-underscore-dangle */
|
|
@@ -5307,6 +5322,11 @@ class VoltCredential {
|
|
|
5307
5322
|
|
|
5308
5323
|
// Extract Volt public key.
|
|
5309
5324
|
this._voltPublicKey = this._voltConfig.public_key;
|
|
5325
|
+
if (!this._voltPublicKey) {
|
|
5326
|
+
// Extract the public key from the Volt CA cert.
|
|
5327
|
+
const voltCA = new crypto__default["default"].X509Certificate(this._voltConfig.ca_pem);
|
|
5328
|
+
this._voltPublicKey = voltCA.publicKey.export({ type: 'spki', format: 'pem' });
|
|
5329
|
+
}
|
|
5310
5330
|
|
|
5311
5331
|
const voltKey = keyFromPem(this._voltPublicKey).publicKey;
|
|
5312
5332
|
this._voltFingerprint = fingerprintFromPem(voltKey);
|
|
@@ -5515,9 +5535,7 @@ class VoltClient extends EventEmitter__default["default"] {
|
|
|
5515
5535
|
log("Attempt to load config from file %s", configPath);
|
|
5516
5536
|
try {
|
|
5517
5537
|
if (fs__default["default"].existsSync(configPath)) {
|
|
5518
|
-
const configContents = await readFile(
|
|
5519
|
-
new URL(configPath, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href)))
|
|
5520
|
-
);
|
|
5538
|
+
const configContents = await readFile(configPath);
|
|
5521
5539
|
configJSON = JSON.parse(configContents);
|
|
5522
5540
|
} else {
|
|
5523
5541
|
// There is currently no file at the given configuration path.
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.18.
|
|
6
|
+
"version": "0.18.10",
|
|
7
7
|
"description": "tdx Volt library for nodejs clients",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"license": "ISC",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@tdxvolt/volt-client-web": "^0.18.2",
|
|
41
|
-
"bent": "^7.3.12",
|
|
42
41
|
"builtin-modules": "^3.3.0",
|
|
43
42
|
"debug": "^4.1.1",
|
|
44
43
|
"ip": "^1.1.5",
|
|
@@ -48,4 +47,4 @@
|
|
|
48
47
|
"protobufjs": "^7.4.0",
|
|
49
48
|
"uuid": "^8.1.0"
|
|
50
49
|
}
|
|
51
|
-
}
|
|
50
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
import { voltUtils as voltClientUtils } from "@tdxvolt/volt-client-web/js";
|
|
3
|
-
import bent from "bent";
|
|
4
3
|
import debug from "debug";
|
|
5
4
|
import ip from "ip";
|
|
6
5
|
import lodash from "lodash";
|
|
@@ -159,10 +158,10 @@ export async function authenticateInternal(
|
|
|
159
158
|
host: this._credential.cache.bindIp
|
|
160
159
|
};
|
|
161
160
|
|
|
162
|
-
if (this.
|
|
161
|
+
if (this._credential.cache.challenge_code) {
|
|
163
162
|
authenticateRequest.challenge = signBase64(
|
|
164
163
|
this._credential.cache.key,
|
|
165
|
-
this.
|
|
164
|
+
this._credential.cache.challenge_code
|
|
166
165
|
);
|
|
167
166
|
} else {
|
|
168
167
|
log(
|
|
@@ -459,8 +458,15 @@ export function streamingCallInternal(methodType, method, request, service) {
|
|
|
459
458
|
|
|
460
459
|
export async function fetchVoltConfig(discovery_url) {
|
|
461
460
|
try {
|
|
462
|
-
const
|
|
463
|
-
|
|
461
|
+
const response = await fetch(discovery_url, {
|
|
462
|
+
headers: { Accept: "application/json" }
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
if (!response.ok) {
|
|
466
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const fullVoltConfig = await response.json();
|
|
464
470
|
|
|
465
471
|
if (!fullVoltConfig || typeof fullVoltConfig !== "object") {
|
|
466
472
|
throw new Error(`invalid config resolved from: ${discovery_url}`);
|
|
@@ -475,8 +481,6 @@ export async function fetchVoltConfig(discovery_url) {
|
|
|
475
481
|
"address",
|
|
476
482
|
"http_address",
|
|
477
483
|
"ca_pem",
|
|
478
|
-
"challenge_code",
|
|
479
|
-
"cloud",
|
|
480
484
|
"relay"
|
|
481
485
|
);
|
|
482
486
|
|
|
@@ -495,8 +499,15 @@ async function fetchVoltConfigFromDIDInternal(volt_did, registryUrl) {
|
|
|
495
499
|
throw new Error(`Invalid Volt DID: ${volt_did}`);
|
|
496
500
|
}
|
|
497
501
|
|
|
498
|
-
const
|
|
499
|
-
|
|
502
|
+
const response = await fetch(didResolution, {
|
|
503
|
+
headers: { Accept: "application/json" }
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
if (!response.ok) {
|
|
507
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const didDocument = await response.json();
|
|
500
511
|
const voltConfigServices = findDIDDocumentService(
|
|
501
512
|
didDocument,
|
|
502
513
|
constants.didServiceType.voltConfig
|
|
@@ -536,5 +547,9 @@ export async function fetchVoltConfigFromDID(
|
|
|
536
547
|
}
|
|
537
548
|
}
|
|
538
549
|
|
|
539
|
-
throw new Error(
|
|
550
|
+
throw new Error(
|
|
551
|
+
`Failed to fetch Volt config from any of these registries: ${registryList.join(
|
|
552
|
+
", "
|
|
553
|
+
)}`
|
|
554
|
+
);
|
|
540
555
|
}
|
package/src/volt-client.js
CHANGED
|
@@ -97,9 +97,7 @@ export class VoltClient extends EventEmitter {
|
|
|
97
97
|
log("Attempt to load config from file %s", configPath);
|
|
98
98
|
try {
|
|
99
99
|
if (fs.existsSync(configPath)) {
|
|
100
|
-
const configContents = await readFile(
|
|
101
|
-
new URL(configPath, import.meta.url)
|
|
102
|
-
);
|
|
100
|
+
const configContents = await readFile(configPath);
|
|
103
101
|
configJSON = JSON.parse(configContents);
|
|
104
102
|
} else {
|
|
105
103
|
// There is currently no file at the given configuration path.
|
package/src/volt-credential.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { voltUtils as voltClientUtils } from "@tdxvolt/volt-client-web/js";
|
|
3
|
+
import crypto from "crypto";
|
|
2
4
|
import debug from "debug";
|
|
3
5
|
import fs from "fs";
|
|
4
6
|
import { constants } from "./constants.js";
|
|
5
|
-
import { voltUtils as voltClientUtils } from "@tdxvolt/volt-client-web/js";
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
createSigningKey,
|
|
@@ -54,6 +55,11 @@ export class VoltCredential {
|
|
|
54
55
|
|
|
55
56
|
// Extract Volt public key.
|
|
56
57
|
this._voltPublicKey = this._voltConfig.public_key;
|
|
58
|
+
if (!this._voltPublicKey) {
|
|
59
|
+
// Extract the public key from the Volt CA cert.
|
|
60
|
+
const voltCA = new crypto.X509Certificate(this._voltConfig.ca_pem);
|
|
61
|
+
this._voltPublicKey = voltCA.publicKey.export({ type: 'spki', format: 'pem' });
|
|
62
|
+
}
|
|
57
63
|
|
|
58
64
|
const voltKey = keyFromPem(this._voltPublicKey).publicKey;
|
|
59
65
|
this._voltFingerprint = fingerprintFromPem(voltKey);
|
|
@@ -2747,7 +2747,6 @@ message InvokeResponse {
|
|
|
2747
2747
|
// The invocation id to match the originating request.
|
|
2748
2748
|
uint64 invoke_id = 1;
|
|
2749
2749
|
|
|
2750
|
-
// Key exchange details for the response payload encryption. Only necessary for the first response.
|
|
2751
2750
|
InvokeRequestKeyExchange key_exchange = 2;
|
|
2752
2751
|
|
|
2753
2752
|
// The initialisation vector for the response payload encryption. This will be a random 16 byte value, that is different for each response.
|