Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Original file line number Diff line number Diff line change
Expand Up @@ -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],
};
Expand Down