diff --git a/src/dtos/generic/generic.dto.ts b/src/dtos/generic/generic.dto.ts index 5fcfcb7..ef0393b 100644 --- a/src/dtos/generic/generic.dto.ts +++ b/src/dtos/generic/generic.dto.ts @@ -10,6 +10,10 @@ export enum AttestationResponseStatus { * Attestation request is invalid. */ INVALID = 'INVALID', + /** + * Attestation request malformed. + */ + MALFORMED = 'MALFORMED', /** * Attestation request cannot be confirmed neither rejected by the verifier at the moment. */ diff --git a/src/services/address-validity-verifier.service.ts b/src/services/address-validity-verifier.service.ts index c916c2f..731316b 100644 --- a/src/services/address-validity-verifier.service.ts +++ b/src/services/address-validity-verifier.service.ts @@ -1,5 +1,5 @@ import { ChainType } from '@flarenetwork/mcc'; -import { Injectable, Logger } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { IConfig } from '../config/configuration'; import { @@ -9,8 +9,7 @@ import { AttestationResponseDTO_AddressValidity_Response, } from '../dtos/attestation-types/AddressValidity.dto'; import { - AttestationResponse, - AttestationResponseStatus, + AttestationResponseStatus } from '../dtos/generic/generic.dto'; import { serializeBigInts } from '../external-libs/utils'; import { verifyAddressBTC } from '../verification/address-validity/address-validity-btc'; diff --git a/src/services/balance-decreasing-transaction-verifier.service.ts b/src/services/balance-decreasing-transaction-verifier.service.ts index 6ad199d..5e22ada 100644 --- a/src/services/balance-decreasing-transaction-verifier.service.ts +++ b/src/services/balance-decreasing-transaction-verifier.service.ts @@ -14,7 +14,6 @@ import { BalanceDecreasingTransaction_Request, BalanceDecreasingTransaction_Response, } from '../dtos/attestation-types/BalanceDecreasingTransaction.dto'; -import { AttestationResponse } from '../dtos/generic/generic.dto'; import { serializeBigInts } from '../external-libs/utils'; import { BtcIndexerQueryManager, diff --git a/src/services/common/verifier-base.service.ts b/src/services/common/verifier-base.service.ts index 83473e9..c796dbb 100644 --- a/src/services/common/verifier-base.service.ts +++ b/src/services/common/verifier-base.service.ts @@ -1,5 +1,5 @@ import { ChainType, ZERO_BYTES_32 } from '@flarenetwork/mcc'; -import { HttpException, HttpStatus } from '@nestjs/common'; +import { HttpException, HttpStatus, Logger } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { AttestationTypeOptions, @@ -9,7 +9,10 @@ import { } from '../../config/configuration'; import { EntityManager } from 'typeorm'; -import { AttestationTypeBase_Request, AttestationTypeBase_Response } from '../../dtos/attestation-types/AttestationTypeBase.dto'; +import { + AttestationTypeBase_Request, + AttestationTypeBase_Response, +} from '../../dtos/attestation-types/AttestationTypeBase.dto'; import { AttestationResponse, AttestationResponseEncoded, @@ -35,13 +38,13 @@ interface IVerificationServiceConfig { interface IVerificationServiceWithIndexerConfig extends IVerificationServiceConfig { indexerQueryManager: - | typeof DogeIndexerQueryManager - | typeof BtcIndexerQueryManager - | typeof XrpIndexerQueryManager; + | typeof DogeIndexerQueryManager + | typeof BtcIndexerQueryManager + | typeof XrpIndexerQueryManager; } export interface ITypeSpecificVerificationServiceConfig - extends Omit { } + extends Omit {} export abstract class BaseVerifierService< Req extends AttestationTypeBase_Request, @@ -73,17 +76,20 @@ export abstract class BaseVerifierService< if ( request.attestationType !== encodeAttestationName(this.attestationName) || request.sourceId !== - encodeAttestationName((this.isTestnet ? 'test' : '') + this.source) + encodeAttestationName((this.isTestnet ? 'test' : '') + this.source) ) { throw new HttpException( { status: HttpStatus.BAD_REQUEST, - error: `Attestation type and source id combination not supported: (${request.attestationType - }, ${request.sourceId}). This source supports attestation type '${this.attestationName - }' (${encodeAttestationName(this.attestationName)}) and source id '${(this.isTestnet ? 'test' : '') + this.source - }' (${encodeAttestationName( - (this.isTestnet ? 'test' : '') + this.source, - )}).`, + error: `Attestation type and source id combination not supported: (${ + request.attestationType + }, ${request.sourceId}). This source supports attestation type '${ + this.attestationName + }' (${encodeAttestationName(this.attestationName)}) and source id '${ + (this.isTestnet ? 'test' : '') + this.source + }' (${encodeAttestationName( + (this.isTestnet ? 'test' : '') + this.source, + )}).`, }, HttpStatus.BAD_REQUEST, ); @@ -112,12 +118,21 @@ export abstract class BaseVerifierService< public async verifyEncodedRequestFDC( abiEncodedRequest: string, ): Promise { - const requestJSON = this.store.parseRequest< - { - messageIntegrityCode: string; - } & Req - >(abiEncodedRequest); - const response = await this.verifyRequestInternal(requestJSON); + let response: AttestationResponse; + try { + const requestJSON = this.store.parseRequest< + { + messageIntegrityCode: string; + } & Req + >(abiEncodedRequest); + response = await this.verifyRequestInternal(requestJSON); + } catch (error) { + Logger.debug(`Error parsing request: ${abiEncodedRequest}`); + Logger.error(`Error parsing request: ${error}`); + return { + status: AttestationResponseStatus.MALFORMED, + }; + } if ( response.status !== AttestationResponseStatus.VALID || !response.response