@tdxvolt/volt-client-grpc 0.18.9 → 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 +32 -11
- package/package.json +3 -4
- package/src/volt-client-internal.js +25 -10
- package/src/volt-credential.js +7 -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",
|
|
@@ -4874,10 +4874,10 @@ async function authenticateInternal(
|
|
|
4874
4874
|
host: this._credential.cache.bindIp
|
|
4875
4875
|
};
|
|
4876
4876
|
|
|
4877
|
-
if (this.
|
|
4877
|
+
if (this._credential.cache.challenge_code) {
|
|
4878
4878
|
authenticateRequest.challenge = signBase64(
|
|
4879
4879
|
this._credential.cache.key,
|
|
4880
|
-
this.
|
|
4880
|
+
this._credential.cache.challenge_code
|
|
4881
4881
|
);
|
|
4882
4882
|
} else {
|
|
4883
4883
|
log$2(
|
|
@@ -5174,8 +5174,15 @@ function streamingCallInternal(methodType, method, request, service) {
|
|
|
5174
5174
|
|
|
5175
5175
|
async function fetchVoltConfig(discovery_url) {
|
|
5176
5176
|
try {
|
|
5177
|
-
const
|
|
5178
|
-
|
|
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();
|
|
5179
5186
|
|
|
5180
5187
|
if (!fullVoltConfig || typeof fullVoltConfig !== "object") {
|
|
5181
5188
|
throw new Error(`invalid config resolved from: ${discovery_url}`);
|
|
@@ -5190,8 +5197,6 @@ async function fetchVoltConfig(discovery_url) {
|
|
|
5190
5197
|
"address",
|
|
5191
5198
|
"http_address",
|
|
5192
5199
|
"ca_pem",
|
|
5193
|
-
"challenge_code",
|
|
5194
|
-
"cloud",
|
|
5195
5200
|
"relay"
|
|
5196
5201
|
);
|
|
5197
5202
|
|
|
@@ -5210,8 +5215,15 @@ async function fetchVoltConfigFromDIDInternal(volt_did, registryUrl) {
|
|
|
5210
5215
|
throw new Error(`Invalid Volt DID: ${volt_did}`);
|
|
5211
5216
|
}
|
|
5212
5217
|
|
|
5213
|
-
const
|
|
5214
|
-
|
|
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();
|
|
5215
5227
|
const voltConfigServices = findDIDDocumentService(
|
|
5216
5228
|
didDocument,
|
|
5217
5229
|
constants.didServiceType.voltConfig
|
|
@@ -5251,7 +5263,11 @@ async function fetchVoltConfigFromDID(
|
|
|
5251
5263
|
}
|
|
5252
5264
|
}
|
|
5253
5265
|
|
|
5254
|
-
throw new Error(
|
|
5266
|
+
throw new Error(
|
|
5267
|
+
`Failed to fetch Volt config from any of these registries: ${registryList.join(
|
|
5268
|
+
", "
|
|
5269
|
+
)}`
|
|
5270
|
+
);
|
|
5255
5271
|
}
|
|
5256
5272
|
|
|
5257
5273
|
/* eslint-disable no-underscore-dangle */
|
|
@@ -5306,6 +5322,11 @@ class VoltCredential {
|
|
|
5306
5322
|
|
|
5307
5323
|
// Extract Volt public key.
|
|
5308
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
|
+
}
|
|
5309
5330
|
|
|
5310
5331
|
const voltKey = keyFromPem(this._voltPublicKey).publicKey;
|
|
5311
5332
|
this._voltFingerprint = fingerprintFromPem(voltKey);
|
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": {
|
|
@@ -37,8 +37,7 @@
|
|
|
37
37
|
"author": "toby.ealden@gmail.com",
|
|
38
38
|
"license": "ISC",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tdxvolt/volt-client-web": "^0.18.
|
|
41
|
-
"bent": "^7.3.12",
|
|
40
|
+
"@tdxvolt/volt-client-web": "^0.18.2",
|
|
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-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);
|