-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vc-api): change the verify records api request + add dto to _ver…
…ifyRecords function + unit tests fixes
- Loading branch information
1 parent
ae935e3
commit 8ba0d17
Showing
17 changed files
with
114 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
apps/vc-api/src/api/filters/web3-provider/web3-provider.filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ArgumentsHost, Catch, HttpStatus } from '@nestjs/common'; | ||
import { BaseExceptionFilter } from '@nestjs/core'; | ||
import { Web3ProviderException } from '../../../core/domain/exceptions/Web3Provider.exception'; | ||
|
||
@Catch(Web3ProviderException) | ||
export class Web3ProviderExceptionFilter extends BaseExceptionFilter { | ||
catch(exception: Web3ProviderException, host: ArgumentsHost) { | ||
const context = host.switchToHttp(); | ||
const response = context.getResponse(); | ||
const httpStatus = HttpStatus.BAD_REQUEST; | ||
|
||
response.status(httpStatus).json({ | ||
message: exception.message, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 6 additions & 8 deletions
14
apps/vc-api/src/api/verify-records/requests/verify-records.api.request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
apps/vc-api/src/core/applications/provider-services/ifetch-chain-id.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const FETCH_CHAIN_ID_SERVICE = 'FETCH_CHAIN_ID_SERVICE'; | ||
|
||
export interface IFetchChainIdService { | ||
getChainId(providerUrl: string): Promise<number>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/vc-api/src/core/applications/verify-records/requests/verify-records.request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export class VerifyRecordsRequest { | ||
providerUrl: string; | ||
ens: string[]; | ||
issuer: string; | ||
chainId: number; | ||
credentials: string[]; | ||
matchStandard?: boolean; | ||
} |
3 changes: 3 additions & 0 deletions
3
.../vc-api/src/core/applications/verify-records/response/record-verifier-checker.response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class RecordVerifierCheckerResponse { | ||
[key: string]: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/vc-api/src/core/domain/exceptions/Web3Provider.exception.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class Web3ProviderException extends Error { | ||
private constructor(message: string) { | ||
super(message); | ||
} | ||
|
||
static withMessage(providerUrl: string): Web3ProviderException { | ||
const message = `Web3ProviderException: Provider Url ${providerUrl} threw an error`; | ||
return new Web3ProviderException(message); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/vc-api/src/external/provider-services/fetch-chain-id.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ethers } from 'ethers'; | ||
import { IFetchChainIdService } from '../../core/applications/provider-services/ifetch-chain-id.service'; | ||
import { Web3ProviderException } from '../../core/domain/exceptions/Web3Provider.exception'; | ||
|
||
@Injectable() | ||
export class FetchChainIdService implements IFetchChainIdService { | ||
providerChainIdMap: Map<string, number> = new Map(); | ||
|
||
|
||
async getChainId(providerUrl: string): Promise<number> { | ||
try { | ||
if (this.providerChainIdMap.has(providerUrl)) { | ||
return this.providerChainIdMap.get(providerUrl) as number; | ||
} | ||
|
||
const provider = new ethers.JsonRpcProvider(providerUrl); | ||
const network = await provider.getNetwork(); | ||
|
||
this.providerChainIdMap.set(providerUrl, Number(network.chainId)); | ||
|
||
return Number(network.chainId) | ||
} catch (e) { | ||
throw Web3ProviderException.withMessage(providerUrl); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.