diff --git a/packages/apps/job-launcher/server/src/common/constants/errors.ts b/packages/apps/job-launcher/server/src/common/constants/errors.ts index 7fc4b30b40..a183022864 100644 --- a/packages/apps/job-launcher/server/src/common/constants/errors.ts +++ b/packages/apps/job-launcher/server/src/common/constants/errors.ts @@ -171,3 +171,10 @@ export enum ErrorQualification { FailedToFetchQualifications = 'Failed to fetch qualifications', InvalidQualification = `Invalid qualification`, } + +/** + * Represents error messages associated with encryption. + */ +export enum ErrorEncryption { + MissingPrivateKey = 'Encryption private key cannot be empty, when it is enabled', +} diff --git a/packages/apps/job-launcher/server/src/modules/encryption/encryption.module.ts b/packages/apps/job-launcher/server/src/modules/encryption/encryption.module.ts index 43d5e961f6..805c2e1d3c 100644 --- a/packages/apps/job-launcher/server/src/modules/encryption/encryption.module.ts +++ b/packages/apps/job-launcher/server/src/modules/encryption/encryption.module.ts @@ -2,16 +2,20 @@ import { Module, Global, Provider } from '@nestjs/common'; import { Encryption } from '@human-protocol/sdk'; import { ConfigModule } from '@nestjs/config'; import { PGPConfigService } from '../../common/config/pgp-config.service'; +import { ErrorEncryption } from '../../common/constants/errors'; const encryptionProvider: Provider = { provide: Encryption, useFactory: async (pgpConfigService: PGPConfigService) => { - if (!pgpConfigService.encrypt) { + if (!pgpConfigService.encrypt && !pgpConfigService.privateKey) { return null; } const privateKey = pgpConfigService.privateKey; const passPhrase = pgpConfigService.passphrase; - return await Encryption.build(privateKey, passPhrase); + + if (privateKey) return await Encryption.build(privateKey, passPhrase); + + throw new Error(ErrorEncryption.MissingPrivateKey); }, inject: [PGPConfigService], };