Skip to content

Commit

Permalink
finishing up, and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: instamenta <[email protected]>
  • Loading branch information
instamenta committed Dec 12, 2024
1 parent dac6d6d commit 75964fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
12 changes: 8 additions & 4 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
);
Expand Down
26 changes: 20 additions & 6 deletions src/core/models/genesisNetworkDataConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeAlias, GenesisNetworkNodeDataWrapper>;
public readonly nodes: Record<NodeAlias, GenesisNetworkNodeDataWrapper> = {};

public constructor(
private constructor(
private readonly nodeAliases: NodeAliases,
private readonly keyManager: KeyManager,
private readonly keysDir: string,
Expand All @@ -45,23 +45,37 @@ export class GenesisNetworkDataConstructor implements ToJSON {
});
}

public static async initialize(
nodeAliases: NodeAliases,
keyManager: KeyManager,
keysDir: string,
): Promise<GenesisNetworkDataConstructor> {
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');
}),
);
}
Expand Down
15 changes: 3 additions & 12 deletions src/core/models/genesisNetworkNodeDataWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand All @@ -40,23 +39,15 @@ 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});
}

/**
* @param domainName - a fully qualified domain name
* @param port
*/
public addGossipEndpoint(domainName: string, port: number): void {
this.gossipEndpoint.push({
ipAddressV4: parseIpAddressToUint8Array(domainName),
domainName,
port,
});
this.gossipEndpoint.push({domainName, port});
}

public toObject() {
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type EmptyContextConfig = object;
export type SoloListrTaskWrapper<T> = ListrTaskWrapper<T, any, any>;

export interface ServiceEndpoint {
ipAddressV4: Uint8Array;
ipAddressV4?: Uint8Array;
port: number;
domainName: string;
}
Expand Down

0 comments on commit 75964fc

Please sign in to comment.