diff --git a/src/domain/email/email.repository.interface.ts b/src/domain/email/email.repository.interface.ts index 94f5dad954..aa42a5caf5 100644 --- a/src/domain/email/email.repository.interface.ts +++ b/src/domain/email/email.repository.interface.ts @@ -77,14 +77,14 @@ export interface IEmailRepository { }): Promise; /** - * Updates an email entry. + * Edits an email entry. * * @param args.chainId - the chain id of where the Safe is deployed * @param args.safeAddress - the Safe address to which we should store the email address * @param args.emailAddress - the email address to store * @param args.account - the owner address to which we should link the email address to */ - updateEmail(args: { + editEmail(args: { chainId: string; safeAddress: string; emailAddress: string; diff --git a/src/domain/email/email.repository.ts b/src/domain/email/email.repository.ts index f354a0b429..683ccf3d89 100644 --- a/src/domain/email/email.repository.ts +++ b/src/domain/email/email.repository.ts @@ -8,7 +8,7 @@ import { ResendVerificationTimespanError } from '@/domain/email/errors/verificat import { IConfigurationService } from '@/config/configuration.service.interface'; import { EmailAlreadyVerifiedError } from '@/domain/email/errors/email-already-verified.error'; import { InvalidVerificationCodeError } from '@/domain/email/errors/invalid-verification-code.error'; -import { EmailUpdateMatchesError } from '@/domain/email/errors/email-update-matches.error'; +import { EmailEditMatchesError } from '@/domain/email/errors/email-edit-matches.error'; import { IEmailApi } from '@/domain/interfaces/email-api.interface'; @Injectable() @@ -161,7 +161,7 @@ export class EmailRepository implements IEmailRepository { await this.emailDataSource.deleteEmail(args); } - async updateEmail(args: { + async editEmail(args: { chainId: string; safeAddress: string; emailAddress: string; @@ -171,7 +171,7 @@ export class EmailRepository implements IEmailRepository { const currentEmail = await this.emailDataSource.getEmail(args); if (newEmail.value === currentEmail.emailAddress.value) { - throw new EmailUpdateMatchesError(args); + throw new EmailEditMatchesError(args); } const verificationCode = this._generateCode(); diff --git a/src/domain/email/errors/email-update-matches.error.ts b/src/domain/email/errors/email-edit-matches.error.ts similarity index 83% rename from src/domain/email/errors/email-update-matches.error.ts rename to src/domain/email/errors/email-edit-matches.error.ts index f97b308d5c..51691921ac 100644 --- a/src/domain/email/errors/email-update-matches.error.ts +++ b/src/domain/email/errors/email-edit-matches.error.ts @@ -1,4 +1,4 @@ -export class EmailUpdateMatchesError extends Error { +export class EmailEditMatchesError extends Error { constructor(args: { chainId: string; safeAddress: string; account: string }) { super( `The provided email address matches that set for the Safe owner. chainId=${args.chainId}, safeAddress=${args.safeAddress}, account=${args.account}`, diff --git a/src/routes/email/email.controller.ts b/src/routes/email/email.controller.ts index 8ece930edb..be0ef4dcb4 100644 --- a/src/routes/email/email.controller.ts +++ b/src/routes/email/email.controller.ts @@ -24,9 +24,9 @@ import { VerifyEmailDto } from '@/routes/email/entities/verify-email-dto.entity' import { InvalidVerificationCodeExceptionFilter } from '@/routes/email/exception-filters/invalid-verification-code.exception-filter'; import { DeleteEmailDto } from '@/routes/email/entities/delete-email-dto.entity'; import { EmailAddressDoesNotExistExceptionFilter } from '@/routes/email/exception-filters/email-does-not-exist.exception-filter'; -import { UpdateEmailDto } from '@/routes/email/entities/update-email-dto.entity'; -import { EmailUpdateGuard } from '@/routes/email/guards/email-update.guard'; -import { EmailUpdateMatchesExceptionFilter } from '@/routes/email/exception-filters/email-update-matches.exception-filter'; +import { EditEmailDto } from '@/routes/email/entities/edit-email-dto.entity'; +import { EmailEditGuard } from '@/routes/email/guards/email-edit.guard'; +import { EmailEditMatchesExceptionFilter } from '@/routes/email/exception-filters/email-edit-matches.exception-filter'; @ApiTags('email') @Controller({ @@ -112,25 +112,25 @@ export class EmailController { @Put('') @UseGuards( - EmailUpdateGuard, + EmailEditGuard, TimestampGuard(5 * 60 * 1000), // 5 minutes OnlySafeOwnerGuard, ) @UseFilters( - EmailUpdateMatchesExceptionFilter, + EmailEditMatchesExceptionFilter, EmailAddressDoesNotExistExceptionFilter, ) @HttpCode(HttpStatus.ACCEPTED) - async updateEmail( + async editEmail( @Param('chainId') chainId: string, @Param('safeAddress') safeAddress: string, - @Body() updateEmailDto: UpdateEmailDto, + @Body() editEmailDto: EditEmailDto, ): Promise { - await this.service.updateEmail({ + await this.service.editEmail({ chainId, safeAddress, - account: updateEmailDto.account, - emailAddress: updateEmailDto.emailAddress, + account: editEmailDto.account, + emailAddress: editEmailDto.emailAddress, }); } } diff --git a/src/routes/email/email.controller.update-email.spec.ts b/src/routes/email/email.controller.update-email.spec.ts index 0bf8160dbf..413881a831 100644 --- a/src/routes/email/email.controller.update-email.spec.ts +++ b/src/routes/email/email.controller.update-email.spec.ts @@ -77,7 +77,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); networkService.get.mockImplementation((url) => { switch (url) { @@ -119,7 +119,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); networkService.get.mockImplementation((url) => { switch (url) { @@ -164,7 +164,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); networkService.get.mockImplementation((url) => { switch (url) { @@ -214,7 +214,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); networkService.get.mockImplementation((url) => { switch (url) { @@ -259,7 +259,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); jest.advanceTimersByTime(5 * 60 * 1000); @@ -324,7 +324,7 @@ describe('Email controller update email tests', () => { // Faker generates non-checksum addresses only .with('address', getAddress(faker.finance.ethereumAddress())) .build(); - const message = `email-update-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chain.chainId}-${safe.address}-${emailAddress}-${accountAddress}-${timestamp}`; const signature = await account.signMessage({ message }); networkService.get.mockImplementation((url) => { switch (url) { diff --git a/src/routes/email/email.service.ts b/src/routes/email/email.service.ts index 6805720ef7..9fa3cea9d1 100644 --- a/src/routes/email/email.service.ts +++ b/src/routes/email/email.service.ts @@ -41,12 +41,12 @@ export class EmailService { return this.repository.deleteEmail(args); } - async updateEmail(args: { + async editEmail(args: { chainId: string; safeAddress: string; account: string; emailAddress: string; }): Promise { - return this.repository.updateEmail(args); + return this.repository.editEmail(args); } } diff --git a/src/routes/email/entities/update-email-dto.entity.ts b/src/routes/email/entities/edit-email-dto.entity.ts similarity index 87% rename from src/routes/email/entities/update-email-dto.entity.ts rename to src/routes/email/entities/edit-email-dto.entity.ts index 7eee930f3f..0a31b86a90 100644 --- a/src/routes/email/entities/update-email-dto.entity.ts +++ b/src/routes/email/entities/edit-email-dto.entity.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -export class UpdateEmailDto { +export class EditEmailDto { @ApiProperty() emailAddress: string; diff --git a/src/routes/email/exception-filters/email-update-matches.exception-filter.ts b/src/routes/email/exception-filters/email-edit-matches.exception-filter.ts similarity index 58% rename from src/routes/email/exception-filters/email-update-matches.exception-filter.ts rename to src/routes/email/exception-filters/email-edit-matches.exception-filter.ts index c4ddf97e24..2faba729ac 100644 --- a/src/routes/email/exception-filters/email-update-matches.exception-filter.ts +++ b/src/routes/email/exception-filters/email-edit-matches.exception-filter.ts @@ -5,11 +5,11 @@ import { HttpStatus, } from '@nestjs/common'; import { Response } from 'express'; -import { EmailUpdateMatchesError } from '@/domain/email/errors/email-update-matches.error'; +import { EmailEditMatchesError } from '@/domain/email/errors/email-edit-matches.error'; -@Catch(EmailUpdateMatchesError) -export class EmailUpdateMatchesExceptionFilter implements ExceptionFilter { - catch(exception: EmailUpdateMatchesError, host: ArgumentsHost) { +@Catch(EmailEditMatchesError) +export class EmailEditMatchesExceptionFilter implements ExceptionFilter { + catch(exception: EmailEditMatchesError, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); diff --git a/src/routes/email/guards/email-update.guard.spec.ts b/src/routes/email/guards/email-edit.guard.spec.ts similarity index 94% rename from src/routes/email/guards/email-update.guard.spec.ts rename to src/routes/email/guards/email-edit.guard.spec.ts index 05c1dacbbd..c76e4ccb0e 100644 --- a/src/routes/email/guards/email-update.guard.spec.ts +++ b/src/routes/email/guards/email-edit.guard.spec.ts @@ -8,27 +8,27 @@ import * as request from 'supertest'; import { faker } from '@faker-js/faker'; import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; import { Hash } from 'viem'; -import { EmailUpdateGuard } from '@/routes/email/guards/email-update.guard'; +import { EmailEditGuard } from '@/routes/email/guards/email-edit.guard'; @Controller() class TestController { @Post('test/:chainId/:safeAddress') @HttpCode(200) - @UseGuards(EmailUpdateGuard) + @UseGuards(EmailEditGuard) async validRoute() {} @Post('test/invalid/chains/:chainId') @HttpCode(200) - @UseGuards(EmailUpdateGuard) + @UseGuards(EmailEditGuard) async invalidRouteWithChainId() {} @Post('test/invalid/safes/:safeAddress') @HttpCode(200) - @UseGuards(EmailUpdateGuard) + @UseGuards(EmailEditGuard) async invalidRouteWithSafeAddress() {} } -describe('EmailUpdate guard tests', () => { +describe('EmailEdit guard tests', () => { let app; const chainId = faker.string.numeric(); @@ -41,7 +41,7 @@ describe('EmailUpdate guard tests', () => { let signature: Hash; beforeAll(async () => { - const message = `email-update-${chainId}-${safe}-${emailAddress}-${accountAddress}-${timestamp}`; + const message = `email-edit-${chainId}-${safe}-${emailAddress}-${accountAddress}-${timestamp}`; signature = await account.signMessage({ message }); }); diff --git a/src/routes/email/guards/email-update.guard.ts b/src/routes/email/guards/email-edit.guard.ts similarity index 82% rename from src/routes/email/guards/email-update.guard.ts rename to src/routes/email/guards/email-edit.guard.ts index 43f92ab956..cee7926c1f 100644 --- a/src/routes/email/guards/email-update.guard.ts +++ b/src/routes/email/guards/email-edit.guard.ts @@ -8,13 +8,13 @@ import { ILoggingService, LoggingService } from '@/logging/logging.interface'; import { verifyMessage } from 'viem'; /** - * The EmailUpdateGuard guard should be used on routes that require + * The EmailEditGuard guard should be used on routes that require * authenticated actions on updating email addresses. * * This guard therefore validates if the message came from the specified account. * * The following message should be signed: - * email-update-${chainId}-${safe}-${emailAddress}-${account}-${timestamp} + * email-edit-${chainId}-${safe}-${emailAddress}-${account}-${timestamp} * * (where ${} represents placeholder values for the respective data) * @@ -27,12 +27,12 @@ import { verifyMessage } from 'viem'; * - the 'timestamp' as part of the JSON body (top level) */ @Injectable() -export class EmailUpdateGuard implements CanActivate { +export class EmailEditGuard implements CanActivate { constructor( @Inject(LoggingService) private readonly loggingService: ILoggingService, ) {} - private static readonly ACTION_PREFIX = 'email-update'; + private static readonly ACTION_PREFIX = 'email-edit'; async canActivate(context: ExecutionContext): Promise { const request = context.switchToHttp().getRequest(); @@ -55,7 +55,7 @@ export class EmailUpdateGuard implements CanActivate { ) return false; - const message = `${EmailUpdateGuard.ACTION_PREFIX}-${chainId}-${safe}-${emailAddress}-${account}-${timestamp}`; + const message = `${EmailEditGuard.ACTION_PREFIX}-${chainId}-${safe}-${emailAddress}-${account}-${timestamp}`; try { return await verifyMessage({