diff --git a/packages/apps/reputation-oracle/server/src/common/constants/errors.ts b/packages/apps/reputation-oracle/server/src/common/constants/errors.ts index cee20b71b5..1fdc726ac7 100644 --- a/packages/apps/reputation-oracle/server/src/common/constants/errors.ts +++ b/packages/apps/reputation-oracle/server/src/common/constants/errors.ts @@ -36,22 +36,6 @@ export enum ErrorSignature { InvalidSignature = 'Invalid signature', } -/** - * Represents error messages related to user. - */ -export enum ErrorUser { - NotFound = 'User not found.', - AccountCannotBeRegistered = 'Account cannot be registered.', - BalanceCouldNotBeRetreived = 'User balance could not be retrieved.', - InvalidCredentials = 'Invalid credentials.', - AlreadyAssigned = 'User already has an address assigned.', - NoWalletAddresRegistered = 'No wallet address registered on your account.', - KycNotApproved = 'KYC not approved.', - LabelingEnableFailed = 'Failed to enable labeling for this account.', - InvalidType = 'User has invalid type.', - DuplicatedAddress = 'The address you are trying to use already exists. Please check that the address is correct or use a different address.', -} - /** * Represents error messages related to send grid. */ @@ -77,11 +61,3 @@ export enum ErrorWeb3 { InvalidChainId = 'Invalid chain id provided for the configured environment', GasPriceError = 'Error calculating gas price', } - -/** - * Represents error messages related to operator. - */ -export enum ErrorOperator { - OperatorAlreadyActive = 'Operator is already active', - OperatorNotActive = 'Operator not active', -} diff --git a/packages/apps/reputation-oracle/server/src/common/enums/web3.ts b/packages/apps/reputation-oracle/server/src/common/enums/web3.ts index e3fee4c9fc..d99650b26e 100644 --- a/packages/apps/reputation-oracle/server/src/common/enums/web3.ts +++ b/packages/apps/reputation-oracle/server/src/common/enums/web3.ts @@ -9,6 +9,5 @@ export enum SignatureType { SIGNIN = 'signin', ENABLE_OPERATOR = 'enable_operator', DISABLE_OPERATOR = 'disable_operator', - CERTIFICATE_AUTHENTICATION = 'certificate_authentication', REGISTER_ADDRESS = 'register_address', } diff --git a/packages/apps/reputation-oracle/server/src/common/utils/signature.ts b/packages/apps/reputation-oracle/server/src/common/utils/signature.ts index cec11ad4bc..f0f180b48b 100644 --- a/packages/apps/reputation-oracle/server/src/common/utils/signature.ts +++ b/packages/apps/reputation-oracle/server/src/common/utils/signature.ts @@ -57,3 +57,23 @@ export function recoverSigner( export function generateNonce(): string { return Buffer.from(ethers.randomBytes(16)).toString('hex'); } + +type SignatureBody = { + from: string; + to: string; + contents: string; + nonce?: string; +}; +export function prepareSignatureBody({ + from, + to, + contents, + nonce, +}: SignatureBody): SignatureBody { + return { + from: from.toLowerCase(), + to: to.toLowerCase(), + contents, + nonce: nonce ?? undefined, + }; +} diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.error-filter.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.error-filter.ts index 8be962b18b..7cca82959c 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.error-filter.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.error-filter.ts @@ -9,16 +9,16 @@ import { Request, Response } from 'express'; import { AuthError, - DuplicatedUserError, + DuplicatedUserEmailError, InvalidOperatorSignupDataError, } from './auth.errors'; type AuthControllerError = | AuthError - | DuplicatedUserError + | DuplicatedUserEmailError | InvalidOperatorSignupDataError; -@Catch(AuthError, DuplicatedUserError, InvalidOperatorSignupDataError) +@Catch(AuthError, DuplicatedUserEmailError, InvalidOperatorSignupDataError) export class AuthControllerErrorsFilter implements ExceptionFilter { private logger = new Logger(AuthControllerErrorsFilter.name); catch(exception: AuthControllerError, host: ArgumentsHost) { @@ -28,7 +28,7 @@ export class AuthControllerErrorsFilter implements ExceptionFilter { let status = HttpStatus.UNAUTHORIZED; let logContext: string | undefined; - if (exception instanceof DuplicatedUserError) { + if (exception instanceof DuplicatedUserEmailError) { status = HttpStatus.CONFLICT; logContext = exception.email; } else if (exception instanceof InvalidOperatorSignupDataError) { diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts index 120c9b9594..f9c643dd5a 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts @@ -5,6 +5,7 @@ export enum AuthErrorMessage { INVALID_REFRESH_TOKEN = 'Refresh token is not valid', REFRESH_TOKEN_EXPIRED = 'Refresh token expired', INVALID_WEB3_SIGNATURE = 'Invalid signature', + INVALID_ADDRESS = 'Invalid address', } export class AuthError extends BaseError { @@ -43,10 +44,18 @@ export class InvalidOperatorJobTypesError extends InvalidOperatorSignupDataError } } -export class DuplicatedUserError extends BaseError { +export class DuplicatedUserEmailError extends BaseError { constructor(public readonly email: string) { super( 'The email you are trying to use already exists. Please check that the email is correct or use a different email.', ); } } + +export class DuplicatedUserAddressError extends BaseError { + constructor(public readonly address: string) { + super( + 'The address you are trying to use already exists. Please, use a different address.', + ); + } +} diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts index e6b71665d1..24efafab10 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts @@ -34,6 +34,7 @@ import { Role, } from '@human-protocol/sdk'; import { SignatureType, Web3Env } from '../../common/enums/web3'; +import { prepareSignatureBody } from '../../common/utils/signature'; import { UserRepository } from '../user/user.repository'; import { AuthConfigService } from '../../common/config/auth-config.service'; import { ServerConfigService } from '../../common/config/server-config.service'; @@ -43,7 +44,8 @@ import { SiteKeyType } from '../../common/enums'; import { AuthError, AuthErrorMessage, - DuplicatedUserError, + DuplicatedUserAddressError, + DuplicatedUserEmailError, InvalidOperatorFeeError, InvalidOperatorJobTypesError, InvalidOperatorRoleError, @@ -82,7 +84,7 @@ export class AuthService { public async signup(data: UserCreateDto): Promise { const storedUser = await this.userRepository.findOneByEmail(data.email); if (storedUser) { - throw new DuplicatedUserError(data.email); + throw new DuplicatedUserEmailError(data.email); } const userEntity = await this.userService.create(data); @@ -337,10 +339,11 @@ export class AuthService { } public async web3Signup(data: Web3SignUpDto): Promise { - const preSignUpData = await this.userService.prepareSignatureBody( - SignatureType.SIGNUP, - data.address, - ); + const preSignUpData = prepareSignatureBody({ + from: data.address, + to: this.web3Service.getOperatorAddress(), + contents: SignatureType.SIGNUP, + }); const verified = verifySignature(preSignUpData, data.signature, [ data.address, @@ -409,6 +412,11 @@ export class AuthService { throw new InvalidOperatorJobTypesError(jobTypes); } + const user = await this.userRepository.findOneByAddress(data.address); + + if (user) { + throw new DuplicatedUserAddressError(data.address); + } const userEntity = await this.userService.createWeb3User(data.address); await kvstore.set(data.address.toLowerCase(), OperatorStatus.ACTIVE); @@ -417,16 +425,21 @@ export class AuthService { } public async web3Signin(data: Web3SignInDto): Promise { - const userEntity = await this.userService.getByAddress(data.address); + const userEntity = await this.userRepository.findOneByAddress(data.address); - const verified = verifySignature( - await this.userService.prepareSignatureBody( - SignatureType.SIGNIN, - data.address, - ), - data.signature, - [data.address], - ); + if (!userEntity) { + throw new AuthError(AuthErrorMessage.INVALID_ADDRESS); + } + + const preSigninData = prepareSignatureBody({ + from: data.address, + to: this.web3Service.getOperatorAddress(), + contents: SignatureType.SIGNIN, + nonce: (await this.userRepository.findOneByAddress(data.address))?.nonce, + }); + const verified = verifySignature(preSigninData, data.signature, [ + data.address, + ]); if (!verified) { throw new AuthError(AuthErrorMessage.INVALID_WEB3_SIGNATURE); diff --git a/packages/apps/reputation-oracle/server/src/modules/credentials/credential.service.ts b/packages/apps/reputation-oracle/server/src/modules/credentials/credential.service.ts index 829369808e..b97103405e 100644 --- a/packages/apps/reputation-oracle/server/src/modules/credentials/credential.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/credentials/credential.service.ts @@ -4,12 +4,7 @@ import { CredentialRepository } from './credential.repository'; import { CredentialEntity } from './credential.entity'; import { CredentialStatus } from '../../common/enums/credential'; import { Web3Service } from '../web3/web3.service'; -import { verifySignature } from '../../common/utils/signature'; -import { ErrorSignature } from '../../common/constants/errors'; -import { ChainId, KVStoreClient } from '@human-protocol/sdk'; -import { SignatureType, Web3Env } from '../../common/enums/web3'; import { Web3ConfigService } from '../../common/config/web3-config.service'; -import { EscrowClient } from '@human-protocol/sdk'; import { UserService } from '../user/user.service'; import { ControlledError } from '../../common/errors/controlled'; @@ -17,12 +12,7 @@ import { ControlledError } from '../../common/errors/controlled'; export class CredentialService { private readonly logger = new Logger(CredentialService.name); - constructor( - private readonly credentialRepository: CredentialRepository, - private readonly web3Service: Web3Service, - private readonly userService: UserService, - private readonly web3ConfigService: Web3ConfigService, - ) {} + constructor(private readonly credentialRepository: CredentialRepository) {} /** * Create a new credential based on provided data. @@ -117,55 +107,4 @@ export class CredentialService { this.logger.log(`Credential ${reference} validated successfully.`); } - - public async addCredentialOnChain( - reference: string, - workerAddress: string, - signature: string, - chainId: ChainId, - escrowAddress: string, - ): Promise { - let signer = this.web3Service.getSigner(chainId); - const escrowClient = await EscrowClient.build(signer); - - const reputationOracleAddress = - await escrowClient.getReputationOracleAddress(escrowAddress); - - const signatureBody = await this.userService.prepareSignatureBody( - SignatureType.CERTIFICATE_AUTHENTICATION, - reputationOracleAddress, - { - reference: reference, - workerAddress: workerAddress, - }, - ); - - if (!verifySignature(signatureBody.contents, signature, [workerAddress])) { - throw new ControlledError( - ErrorSignature.InvalidSignature, - HttpStatus.UNAUTHORIZED, - ); - } - - const currentWeb3Env = this.web3ConfigService.env; - if (currentWeb3Env === Web3Env.MAINNET) { - signer = this.web3Service.getSigner(ChainId.POLYGON); - } else if (currentWeb3Env === Web3Env.TESTNET) { - signer = this.web3Service.getSigner(ChainId.POLYGON_AMOY); - } else { - signer = this.web3Service.getSigner(ChainId.LOCALHOST); - } - const kvstore = await KVStoreClient.build(signer); - const key = `${reference}-${reputationOracleAddress}`; - const value = JSON.stringify({ - signature, - contents: signatureBody.contents, - }); - - await kvstore.set(key, value); - - this.logger.log( - `Credential added to the blockchain for reference: ${reference}`, - ); - } } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts index b8c08a7d33..eaf9171cc6 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts @@ -29,15 +29,23 @@ import { import { JwtAuthGuard } from '../../common/guards'; import { HCaptchaGuard } from '../../common/guards/hcaptcha'; import { RequestWithUser } from '../../common/types'; +import { prepareSignatureBody } from '../../common/utils/signature'; import { UserService } from './user.service'; import { Public } from '../../common/decorators'; import { KycSignedAddressDto } from '../kyc/kyc.dto'; +import { Web3Service } from '../web3/web3.service'; +import { UserRepository } from './user.repository'; +import { SignatureType } from 'src/common/enums/web3'; @ApiTags('User') @Controller('/user') @ApiBearerAuth() export class UserController { - constructor(private readonly userService: UserService) {} + constructor( + private readonly userService: UserService, + private readonly web3Service: Web3Service, + private readonly userRepository: UserRepository, + ) {} @Post('/register-labeler') @HttpCode(200) @@ -170,7 +178,16 @@ export class UserController { public async prepareSignature( @Body() data: PrepareSignatureDto, ): Promise { - return await this.userService.prepareSignatureBody(data.type, data.address); + let nonce; + if (data.type === SignatureType.SIGNIN) { + nonce = (await this.userRepository.findOneByAddress(data.address))?.nonce; + } + return prepareSignatureBody({ + from: data.address, + to: this.web3Service.getOperatorAddress(), + contents: data.type, + nonce, + }); } @Post('/exchange-oracle-registration') diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts index 1db6ffc89e..f282b53f3e 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.dto.ts @@ -93,8 +93,9 @@ export class SignatureBodyDto { public contents: string; @ApiProperty() + @IsOptional() @IsString() - public nonce: string | undefined; + public nonce?: string | undefined; } export class PrepareSignatureDto { diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts new file mode 100644 index 0000000000..fcb62ecd5a --- /dev/null +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts @@ -0,0 +1,35 @@ +import { + ExceptionFilter, + Catch, + ArgumentsHost, + HttpStatus, + Logger, +} from '@nestjs/common'; +import { Request, Response } from 'express'; + +import { UserError, DuplicatedWalletAddressError } from './user.error'; + +type UserControllerError = UserError | DuplicatedWalletAddressError; + +@Catch(UserError, DuplicatedWalletAddressError) +export class UserErrorFilter implements ExceptionFilter { + private logger = new Logger(UserErrorFilter.name); + catch(exception: UserControllerError, host: ArgumentsHost) { + const ctx = host.switchToHttp(); + const response = ctx.getResponse(); + const request = ctx.getRequest(); + let status = HttpStatus.BAD_REQUEST; + + if (exception instanceof DuplicatedWalletAddressError) { + status = HttpStatus.CONFLICT; + } + + this.logger.error(exception.message, exception.stack, exception.userId); + + return response.status(status).json({ + message: exception.message, + timestamp: new Date().toISOString(), + path: request.url, + }); + } +} diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts new file mode 100644 index 0000000000..b38540d9f4 --- /dev/null +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts @@ -0,0 +1,27 @@ +import { BaseError } from '../../common/errors/base'; + +export enum UserErrorMessage { + INVALID_ROLE = 'Invalid user role', + MISSING_ADDRESS = 'Wallet address is missing', + ADDRESS_EXISTS = 'Wallet address is already assigned', + KYC_NOT_APPROVED = 'KYC not approved', + LABELING_ENABLE_FAILED = 'Failed to enable hCaptcha labeling', + OPERATOR_ALREADY_ACTIVE = 'Operator status is already active', + OPERATOR_NOT_ACTIVE = 'Operator status is not active', +} + +export class UserError extends BaseError { + userId: number; + constructor(message: UserErrorMessage, userId: number) { + super(message); + this.userId = userId; + } +} + +export class DuplicatedWalletAddressError extends BaseError { + userId: number; + constructor(userId: number, address: string) { + super(`Wallet address already exists: ${address}`); + this.userId = userId; + } +} diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts index 8da0e63bac..33098b12d8 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts @@ -1,11 +1,5 @@ -import { - BadRequestException, - HttpStatus, - Injectable, - Logger, -} from '@nestjs/common'; +import { Injectable, Logger } from '@nestjs/common'; import * as bcrypt from 'bcrypt'; -import { ErrorOperator, ErrorUser } from '../../common/constants/errors'; import { KycStatus, OperatorStatus, @@ -14,12 +8,7 @@ import { } from '../../common/enums/user'; import { generateNonce, verifySignature } from '../../common/utils/signature'; import { UserEntity } from './user.entity'; -import { - RegistrationInExchangeOracleDto, - RegisterAddressRequestDto, - SignatureBodyDto, - UserCreateDto, -} from './user.dto'; +import { RegisterAddressRequestDto, UserCreateDto } from './user.dto'; import { UserRepository } from './user.repository'; import { ValidatePasswordDto } from '../auth/auth.dto'; import { Web3Service } from '../web3/web3.service'; @@ -30,11 +19,16 @@ import { SiteKeyEntity } from './site-key.entity'; import { SiteKeyRepository } from './site-key.repository'; import { SiteKeyType } from '../../common/enums'; import { HCaptchaService } from '../../integrations/hcaptcha/hcaptcha.service'; -import { ControlledError } from '../../common/errors/controlled'; import { HCaptchaConfigService } from '../../common/config/hcaptcha-config.service'; import { NetworkConfigService } from '../../common/config/network-config.service'; +import { prepareSignatureBody } from '../../common/utils/signature'; import { KycSignedAddressDto } from '../kyc/kyc.dto'; import { ethers } from 'ethers'; +import { + UserError, + DuplicatedWalletAddressError, + UserErrorMessage, +} from './user.error'; @Injectable() export class UserService { @@ -81,8 +75,6 @@ export class UserService { } public async createWeb3User(address: string): Promise { - await this.checkEvmAddress(address); - const newUser = new UserEntity(); newUser.evmAddress = address.toLowerCase(); newUser.nonce = generateNonce(); @@ -93,28 +85,6 @@ export class UserService { return newUser; } - public async checkEvmAddress(address: string): Promise { - const userEntity = await this.userRepository.findOneByAddress(address); - - if (userEntity) { - this.logger.log(ErrorUser.AccountCannotBeRegistered, UserService.name); - throw new ControlledError( - ErrorUser.AccountCannotBeRegistered, - HttpStatus.CONFLICT, - ); - } - } - - public async getByAddress(address: string): Promise { - const userEntity = await this.userRepository.findOneByAddress(address); - - if (!userEntity) { - throw new ControlledError(ErrorUser.NotFound, HttpStatus.NOT_FOUND); - } - - return userEntity; - } - public async updateNonce(userEntity: UserEntity): Promise { userEntity.nonce = generateNonce(); return this.userRepository.updateOne(userEntity); @@ -122,18 +92,15 @@ export class UserService { public async registerLabeler(user: UserEntity): Promise { if (user.role !== Role.WORKER) { - throw new BadRequestException(ErrorUser.InvalidType); + throw new UserError(UserErrorMessage.INVALID_ROLE, user.id); } if (!user.evmAddress) { - throw new ControlledError( - ErrorUser.NoWalletAddresRegistered, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.MISSING_ADDRESS, user.id); } if (user.kyc?.status !== KycStatus.APPROVED) { - throw new BadRequestException(ErrorUser.KycNotApproved); + throw new UserError(UserErrorMessage.KYC_NOT_APPROVED, user.id); } if (user.siteKeys && user.siteKeys.length > 0) { @@ -154,10 +121,7 @@ export class UserService { }); if (!registeredLabeler) { - throw new ControlledError( - ErrorUser.LabelingEnableFailed, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.LABELING_ENABLE_FAILED, user.id); } // Retrieve labeler site key from hcaptcha foundation @@ -165,10 +129,7 @@ export class UserService { email: user.email, }); if (!labelerData || !labelerData.sitekeys.length) { - throw new ControlledError( - ErrorUser.LabelingEnableFailed, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.LABELING_ENABLE_FAILED, user.id); } const siteKey = labelerData.sitekeys[0].sitekey; @@ -189,32 +150,24 @@ export class UserService { data.address = data.address.toLowerCase(); if (user.evmAddress) { - throw new ControlledError( - ErrorUser.AlreadyAssigned, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.ADDRESS_EXISTS, user.id); } if (user.kyc?.status !== KycStatus.APPROVED) { - throw new ControlledError( - ErrorUser.KycNotApproved, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.KYC_NOT_APPROVED, user.id); } const dbUser = await this.userRepository.findOneByAddress(data.address); if (dbUser) { - throw new ControlledError( - ErrorUser.DuplicatedAddress, - HttpStatus.BAD_REQUEST, - ); + throw new DuplicatedWalletAddressError(user.id, data.address); } // Prepare signed data and verify the signature - const signedData = await this.prepareSignatureBody( - SignatureType.REGISTER_ADDRESS, - data.address, - ); + const signedData = prepareSignatureBody({ + from: data.address, + to: this.web3Service.getOperatorAddress(), + contents: SignatureType.REGISTER_ADDRESS, + }); verifySignature(signedData, data.signature, [data.address]); user.evmAddress = data.address.toLowerCase(); @@ -234,10 +187,11 @@ export class UserService { user: UserEntity, signature: string, ): Promise { - const signedData = await this.prepareSignatureBody( - SignatureType.ENABLE_OPERATOR, - user.evmAddress, - ); + const signedData = prepareSignatureBody({ + from: user.evmAddress, + to: this.web3Service.getOperatorAddress(), + contents: SignatureType.ENABLE_OPERATOR, + }); verifySignature(signedData, signature, [user.evmAddress]); @@ -260,10 +214,7 @@ export class UserService { } catch {} if (status === OperatorStatus.ACTIVE) { - throw new ControlledError( - ErrorOperator.OperatorAlreadyActive, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.OPERATOR_ALREADY_ACTIVE, user.id); } await kvstore.set(user.evmAddress.toLowerCase(), OperatorStatus.ACTIVE); @@ -273,10 +224,11 @@ export class UserService { user: UserEntity, signature: string, ): Promise { - const signedData = await this.prepareSignatureBody( - SignatureType.DISABLE_OPERATOR, - user.evmAddress, - ); + const signedData = prepareSignatureBody({ + from: user.evmAddress, + to: this.web3Service.getOperatorAddress(), + contents: SignatureType.DISABLE_OPERATOR, + }); verifySignature(signedData, signature, [user.evmAddress]); @@ -301,67 +253,12 @@ export class UserService { ); if (status === OperatorStatus.INACTIVE) { - throw new ControlledError( - ErrorOperator.OperatorNotActive, - HttpStatus.BAD_REQUEST, - ); + throw new UserError(UserErrorMessage.OPERATOR_NOT_ACTIVE, user.id); } await kvstore.set(user.evmAddress.toLowerCase(), OperatorStatus.INACTIVE); } - public async prepareSignatureBody( - type: SignatureType, - address: string, - additionalData?: { reference?: string; workerAddress?: string }, - ): Promise { - let content: string; - let nonce: string | undefined; - switch (type) { - case SignatureType.SIGNUP: - content = 'signup'; - break; - case SignatureType.SIGNIN: - content = 'signin'; - nonce = (await this.userRepository.findOneByAddress(address))?.nonce; - break; - case SignatureType.ENABLE_OPERATOR: - content = 'enable-operator'; - break; - case SignatureType.DISABLE_OPERATOR: - content = 'disable-operator'; - break; - case SignatureType.CERTIFICATE_AUTHENTICATION: - if ( - !additionalData || - !additionalData.reference || - !additionalData.workerAddress - ) { - throw new ControlledError( - 'Missing necessary credential data', - HttpStatus.BAD_REQUEST, - ); - } - content = JSON.stringify({ - reference: additionalData.reference, - workerJson: additionalData.workerAddress.toLowerCase(), - }); - break; - case SignatureType.REGISTER_ADDRESS: - content = 'register-address'; - break; - default: - throw new ControlledError('Type not allowed', HttpStatus.BAD_REQUEST); - } - - return { - from: address.toLowerCase(), - to: this.web3Service.getOperatorAddress().toLowerCase(), - contents: content, - nonce: nonce ?? undefined, - }; - } - public async registrationInExchangeOracle( user: UserEntity, oracleAddress: string,