Skip to content

Commit 75964fc

Browse files
committed
finishing up, and fixes
Signed-off-by: instamenta <instamenta@abv.bg>
1 parent dac6d6d commit 75964fc

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

src/commands/network.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,19 @@ export class NetworkCommand extends BaseCommand {
263263
constants.SOLO_DEPLOYMENT_CHART,
264264
);
265265

266-
config.genesisNetworkData = new GenesisNetworkDataConstructor(config.nodeAliases, this.keyManager, config.keysDir);
267-
268-
config.valuesArg = await this.prepareValuesArg(config);
269-
270266
// compute other config parameters
271267
config.keysDir = path.join(validatePath(config.cacheDir), 'keys');
272268
config.stagingDir = Templates.renderStagingDir(config.cacheDir, config.releaseTag);
273269
config.stagingKeysDir = path.join(validatePath(config.stagingDir), 'keys');
274270

271+
config.genesisNetworkData = await GenesisNetworkDataConstructor.initialize(
272+
config.nodeAliases,
273+
this.keyManager,
274+
config.keysDir,
275+
);
276+
277+
config.valuesArg = await this.prepareValuesArg(config);
278+
275279
if (!(await this.k8.hasNamespace(config.namespace))) {
276280
await this.k8.createNamespace(config.namespace);
277281
}

src/core/helpers.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,14 @@ export function prepareEndpoints(endpointType: string, endpoints: string[], defa
323323
if (endpointType.toUpperCase() === constants.ENDPOINT_TYPE_IP) {
324324
ret.push(
325325
new ServiceEndpoint({
326-
// @ts-ignore
327-
port,
326+
port: +port,
328327
ipAddressV4: parseIpAddressToUint8Array(url),
329328
}),
330329
);
331330
} else {
332331
ret.push(
333332
new ServiceEndpoint({
334-
// @ts-ignore
335-
port,
333+
port: +port,
336334
domainName: url,
337335
}),
338336
);

src/core/models/genesisNetworkDataConstructor.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import type {NodeAlias, NodeAliases} from '../../types/aliases.js';
2929
* Used to construct the nodes data and convert them to JSON
3030
*/
3131
export class GenesisNetworkDataConstructor implements ToJSON {
32-
public readonly nodes: Record<NodeAlias, GenesisNetworkNodeDataWrapper>;
32+
public readonly nodes: Record<NodeAlias, GenesisNetworkNodeDataWrapper> = {};
3333

34-
public constructor(
34+
private constructor(
3535
private readonly nodeAliases: NodeAliases,
3636
private readonly keyManager: KeyManager,
3737
private readonly keysDir: string,
@@ -45,23 +45,37 @@ export class GenesisNetworkDataConstructor implements ToJSON {
4545
});
4646
}
4747

48+
public static async initialize(
49+
nodeAliases: NodeAliases,
50+
keyManager: KeyManager,
51+
keysDir: string,
52+
): Promise<GenesisNetworkDataConstructor> {
53+
const instance = new GenesisNetworkDataConstructor(nodeAliases, keyManager, keysDir);
54+
55+
await instance.load();
56+
57+
return instance;
58+
}
59+
4860
/**
4961
* Loads the gossipCaCertificate and grpcCertificateHash
5062
*/
51-
public async load() {
63+
private async load() {
5264
await Promise.all(
5365
this.nodeAliases.map(async nodeAlias => {
5466
const nodeKeys = await this.keyManager.loadSigningKey(nodeAlias, this.keysDir);
5567

68+
//* Convert the certificate to PEM format
5669
const certPem = nodeKeys.certificate.toString();
5770

71+
//* Assign the PEM certificate
5872
this.nodes[nodeAlias].gossipCaCertificate = certPem;
5973

74+
//* Decode the PEM to DER format
6075
const tlsCertDer = new Uint8Array(x509.PemConverter.decode(certPem)[0]);
6176

62-
const grpcCertificateHash = crypto.createHash('sha384').update(tlsCertDer).digest();
63-
64-
this.nodes[nodeAlias].grpcCertificateHash = grpcCertificateHash.toString();
77+
//* Generate the SHA-384 hash
78+
this.nodes[nodeAlias].grpcCertificateHash = crypto.createHash('sha384').update(tlsCertDer).digest('hex');
6579
}),
6680
);
6781
}

src/core/models/genesisNetworkNodeDataWrapper.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import {parseIpAddressToUint8Array} from '../helpers.js';
1817
import type {AccountId} from '@hashgraph/sdk';
19-
import {type GenesisNetworkNodeStructure, type ServiceEndpoint, type ToObject} from '../../types/index.js';
18+
import type {GenesisNetworkNodeStructure, ServiceEndpoint, ToObject} from '../../types/index.js';
2019

2120
export class GenesisNetworkNodeDataWrapper
2221
implements GenesisNetworkNodeStructure, ToObject<{node: GenesisNetworkNodeStructure}>
@@ -40,23 +39,15 @@ export class GenesisNetworkNodeDataWrapper
4039
* @param port
4140
*/
4241
public addServiceEndpoint(domainName: string, port: number): void {
43-
this.serviceEndpoint.push({
44-
ipAddressV4: parseIpAddressToUint8Array(domainName),
45-
domainName,
46-
port,
47-
});
42+
this.serviceEndpoint.push({domainName, port});
4843
}
4944

5045
/**
5146
* @param domainName - a fully qualified domain name
5247
* @param port
5348
*/
5449
public addGossipEndpoint(domainName: string, port: number): void {
55-
this.gossipEndpoint.push({
56-
ipAddressV4: parseIpAddressToUint8Array(domainName),
57-
domainName,
58-
port,
59-
});
50+
this.gossipEndpoint.push({domainName, port});
6051
}
6152

6253
public toObject() {

src/types/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type EmptyContextConfig = object;
9898
export type SoloListrTaskWrapper<T> = ListrTaskWrapper<T, any, any>;
9999

100100
export interface ServiceEndpoint {
101-
ipAddressV4: Uint8Array;
101+
ipAddressV4?: Uint8Array;
102102
port: number;
103103
domainName: string;
104104
}

0 commit comments

Comments
 (0)