diff --git a/src/commands/network.ts b/src/commands/network.ts index a965cb2f1..465d9751d 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -263,15 +263,19 @@ export class NetworkCommand extends BaseCommand { constants.SOLO_DEPLOYMENT_CHART, ); - config.genesisNetworkData = new GenesisNetworkDataConstructor(config.nodeAliases, this.keyManager, config.keysDir); - - config.valuesArg = await this.prepareValuesArg(config); - // compute other config parameters config.keysDir = path.join(validatePath(config.cacheDir), 'keys'); config.stagingDir = Templates.renderStagingDir(config.cacheDir, config.releaseTag); config.stagingKeysDir = path.join(validatePath(config.stagingDir), 'keys'); + config.genesisNetworkData = await GenesisNetworkDataConstructor.initialize( + config.nodeAliases, + this.keyManager, + config.keysDir, + ); + + config.valuesArg = await this.prepareValuesArg(config); + if (!(await this.k8.hasNamespace(config.namespace))) { await this.k8.createNamespace(config.namespace); } diff --git a/src/core/helpers.ts b/src/core/helpers.ts index 1a8f16b4a..7c06ebdb8 100644 --- a/src/core/helpers.ts +++ b/src/core/helpers.ts @@ -323,16 +323,14 @@ export function prepareEndpoints(endpointType: string, endpoints: string[], defa if (endpointType.toUpperCase() === constants.ENDPOINT_TYPE_IP) { ret.push( new ServiceEndpoint({ - // @ts-ignore - port, + port: +port, ipAddressV4: parseIpAddressToUint8Array(url), }), ); } else { ret.push( new ServiceEndpoint({ - // @ts-ignore - port, + port: +port, domainName: url, }), ); diff --git a/src/core/models/genesisNetworkDataConstructor.ts b/src/core/models/genesisNetworkDataConstructor.ts index 0455a30be..f8c9a245a 100644 --- a/src/core/models/genesisNetworkDataConstructor.ts +++ b/src/core/models/genesisNetworkDataConstructor.ts @@ -29,9 +29,9 @@ import type {NodeAlias, NodeAliases} from '../../types/aliases.js'; * Used to construct the nodes data and convert them to JSON */ export class GenesisNetworkDataConstructor implements ToJSON { - public readonly nodes: Record; + public readonly nodes: Record = {}; - public constructor( + private constructor( private readonly nodeAliases: NodeAliases, private readonly keyManager: KeyManager, private readonly keysDir: string, @@ -45,23 +45,37 @@ export class GenesisNetworkDataConstructor implements ToJSON { }); } + public static async initialize( + nodeAliases: NodeAliases, + keyManager: KeyManager, + keysDir: string, + ): Promise { + const instance = new GenesisNetworkDataConstructor(nodeAliases, keyManager, keysDir); + + await instance.load(); + + return instance; + } + /** * Loads the gossipCaCertificate and grpcCertificateHash */ - public async load() { + private async load() { await Promise.all( this.nodeAliases.map(async nodeAlias => { const nodeKeys = await this.keyManager.loadSigningKey(nodeAlias, this.keysDir); + //* Convert the certificate to PEM format const certPem = nodeKeys.certificate.toString(); + //* Assign the PEM certificate this.nodes[nodeAlias].gossipCaCertificate = certPem; + //* Decode the PEM to DER format const tlsCertDer = new Uint8Array(x509.PemConverter.decode(certPem)[0]); - const grpcCertificateHash = crypto.createHash('sha384').update(tlsCertDer).digest(); - - this.nodes[nodeAlias].grpcCertificateHash = grpcCertificateHash.toString(); + //* Generate the SHA-384 hash + this.nodes[nodeAlias].grpcCertificateHash = crypto.createHash('sha384').update(tlsCertDer).digest('hex'); }), ); } diff --git a/src/core/models/genesisNetworkNodeDataWrapper.ts b/src/core/models/genesisNetworkNodeDataWrapper.ts index dd1fa84b5..7e18e3fa8 100644 --- a/src/core/models/genesisNetworkNodeDataWrapper.ts +++ b/src/core/models/genesisNetworkNodeDataWrapper.ts @@ -14,9 +14,8 @@ * limitations under the License. * */ -import {parseIpAddressToUint8Array} from '../helpers.js'; import type {AccountId} from '@hashgraph/sdk'; -import {type GenesisNetworkNodeStructure, type ServiceEndpoint, type ToObject} from '../../types/index.js'; +import type {GenesisNetworkNodeStructure, ServiceEndpoint, ToObject} from '../../types/index.js'; export class GenesisNetworkNodeDataWrapper implements GenesisNetworkNodeStructure, ToObject<{node: GenesisNetworkNodeStructure}> @@ -40,11 +39,7 @@ export class GenesisNetworkNodeDataWrapper * @param port */ public addServiceEndpoint(domainName: string, port: number): void { - this.serviceEndpoint.push({ - ipAddressV4: parseIpAddressToUint8Array(domainName), - domainName, - port, - }); + this.serviceEndpoint.push({domainName, port}); } /** @@ -52,11 +47,7 @@ export class GenesisNetworkNodeDataWrapper * @param port */ public addGossipEndpoint(domainName: string, port: number): void { - this.gossipEndpoint.push({ - ipAddressV4: parseIpAddressToUint8Array(domainName), - domainName, - port, - }); + this.gossipEndpoint.push({domainName, port}); } public toObject() { diff --git a/src/types/index.ts b/src/types/index.ts index 687c8c813..e0f97ba2b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -98,7 +98,7 @@ export type EmptyContextConfig = object; export type SoloListrTaskWrapper = ListrTaskWrapper; export interface ServiceEndpoint { - ipAddressV4: Uint8Array; + ipAddressV4?: Uint8Array; port: number; domainName: string; }