|
1 |
| -import { Injectable, Inject} from '@nestjs/common'; |
2 |
| -import { ClientProxy} from '@nestjs/microservices'; |
| 1 | +import { Injectable, Inject } from '@nestjs/common'; |
| 2 | +import { ClientProxy } from '@nestjs/microservices'; |
3 | 3 | import { BaseService } from 'libs/service/base.service';
|
4 | 4 | import { SendProofRequestPayload, RequestProofDtoV1, RequestProofDtoV2 } from './dto/request-proof.dto';
|
5 | 5 | import { IUserRequest } from '@credebl/user-request/user-request.interface';
|
6 | 6 | import { WebhookPresentationProofDto } from './dto/webhook-proof.dto';
|
7 |
| -import { IProofPresentationDetails, IProofPresentationList, IVerificationRecords } from '@credebl/common/interfaces/verification.interface'; |
| 7 | +import { |
| 8 | + IProofPresentationDetails, |
| 9 | + IProofPresentationList, |
| 10 | + IVerificationRecords |
| 11 | +} from '@credebl/common/interfaces/verification.interface'; |
8 | 12 | import { IPresentation, IProofRequest, IProofRequestSearchCriteria } from './interfaces/verification.interface';
|
9 | 13 | import { IProofPresentation } from './interfaces/verification.interface';
|
10 | 14 | // To do make a similar interface in API-gateway
|
11 | 15 | import { user } from '@prisma/client';
|
12 | 16 | import { NATSClient } from '@credebl/common/NATSClient';
|
13 | 17 |
|
14 |
| - |
15 | 18 | @Injectable()
|
16 | 19 | export class VerificationService extends BaseService {
|
17 |
| - constructor( |
18 |
| - @Inject('NATS_CLIENT') private readonly verificationServiceProxy: ClientProxy, |
19 |
| - private readonly natsClient : NATSClient |
20 |
| - ) { |
21 |
| - super('VerificationService'); |
22 |
| - } |
| 20 | + constructor( |
| 21 | + @Inject('NATS_CLIENT') private readonly verificationServiceProxy: ClientProxy, |
| 22 | + private readonly natsClient: NATSClient |
| 23 | + ) { |
| 24 | + super('VerificationService'); |
| 25 | + } |
23 | 26 |
|
24 |
| - /** |
25 |
| - * Get all proof presentations |
26 |
| - * @param orgId |
27 |
| - * @returns All proof presentations details |
28 |
| - */ |
29 |
| - getProofPresentations(proofRequestsSearchCriteria: IProofRequestSearchCriteria, user: IUserRequest, orgId: string): Promise<IProofPresentationList> { |
30 |
| - const payload = { proofRequestsSearchCriteria, user, orgId }; |
31 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'get-all-proof-presentations', payload); |
32 |
| - } |
| 27 | + /** |
| 28 | + * Get all proof presentations |
| 29 | + * @param orgId |
| 30 | + * @returns All proof presentations details |
| 31 | + */ |
| 32 | + getProofPresentations( |
| 33 | + proofRequestsSearchCriteria: IProofRequestSearchCriteria, |
| 34 | + user: IUserRequest, |
| 35 | + orgId: string |
| 36 | + ): Promise<IProofPresentationList> { |
| 37 | + const payload = { proofRequestsSearchCriteria, user, orgId }; |
| 38 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'get-all-proof-presentations', payload); |
| 39 | + } |
33 | 40 |
|
34 |
| - /** |
35 |
| - * Get proof presentation by proofId |
36 |
| - * @param proofId |
37 |
| - * @param orgId |
38 |
| - * @returns Proof presentation details by proofId |
39 |
| - */ |
40 |
| - getProofPresentationById(proofId: string, orgId: string, user: IUserRequest): Promise<IProofPresentation> { |
41 |
| - const payload = { proofId, orgId, user }; |
42 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'get-proof-presentations-by-proofId', payload); |
43 |
| - } |
| 41 | + /** |
| 42 | + * Get proof presentation by proofId |
| 43 | + * @param proofId |
| 44 | + * @param orgId |
| 45 | + * @returns Proof presentation details by proofId |
| 46 | + */ |
| 47 | + getProofPresentationById(proofId: string, orgId: string, user: IUserRequest): Promise<IProofPresentation> { |
| 48 | + const payload = { proofId, orgId, user }; |
| 49 | + return this.natsClient.sendNatsMessage( |
| 50 | + this.verificationServiceProxy, |
| 51 | + 'get-proof-presentations-by-proofId', |
| 52 | + payload |
| 53 | + ); |
| 54 | + } |
44 | 55 |
|
45 |
| - /** |
46 |
| - * Send proof request |
47 |
| - * @param orgId |
48 |
| - * @returns Requested proof presentation details |
49 |
| - */ |
50 |
| - sendProofRequest(requestProofDto: RequestProofDtoV1 | RequestProofDtoV2, user: IUserRequest): Promise<IProofRequest> { |
51 |
| - const payload = { requestProofDto, user }; |
52 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'send-proof-request', payload); |
53 |
| - } |
| 56 | + /** |
| 57 | + * Get verifier proof presentation by issuerId |
| 58 | + * @param issuerId |
| 59 | + * @returns Proof presentation details by issuerId |
| 60 | + */ |
| 61 | + getPresentationDetailsByIssuerId(issuerId: string, user: IUserRequest): Promise<number> { |
| 62 | + const payload = { issuerId, user }; |
| 63 | + return this.natsClient.sendNatsMessage( |
| 64 | + this.verificationServiceProxy, |
| 65 | + 'get-proof-presentation-details-by-issuerId', |
| 66 | + payload |
| 67 | + ); |
| 68 | + } |
54 | 69 |
|
55 |
| - /** |
56 |
| - * Verify proof presentation |
57 |
| - * @param proofId |
58 |
| - * @param orgId |
59 |
| - * @returns Verified proof presentation details |
60 |
| - */ |
61 |
| - verifyPresentation(proofId: string, orgId: string, user: IUserRequest): Promise<IPresentation> { |
62 |
| - const payload = { proofId, orgId, user }; |
63 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'verify-presentation', payload); |
64 |
| - } |
| 70 | + /** |
| 71 | + * Send proof request |
| 72 | + * @param orgId |
| 73 | + * @returns Requested proof presentation details |
| 74 | + */ |
| 75 | + sendProofRequest(requestProofDto: RequestProofDtoV1 | RequestProofDtoV2, user: IUserRequest): Promise<IProofRequest> { |
| 76 | + const payload = { requestProofDto, user }; |
| 77 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'send-proof-request', payload); |
| 78 | + } |
65 | 79 |
|
66 |
| - webhookProofPresentation(orgId: string, proofPresentationPayload: WebhookPresentationProofDto): Promise<object> { |
67 |
| - const payload = { orgId, proofPresentationPayload }; |
68 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'webhook-proof-presentation', payload); |
69 |
| - } |
| 80 | + /** |
| 81 | + * Verify proof presentation |
| 82 | + * @param proofId |
| 83 | + * @param orgId |
| 84 | + * @returns Verified proof presentation details |
| 85 | + */ |
| 86 | + verifyPresentation(proofId: string, orgId: string, user: IUserRequest): Promise<IPresentation> { |
| 87 | + const payload = { proofId, orgId, user }; |
| 88 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'verify-presentation', payload); |
| 89 | + } |
70 | 90 |
|
71 |
| - /** |
72 |
| - * Out-Of-Band Proof Presentation |
73 |
| - * @param user |
74 |
| - * @param outOfBandRequestProof |
75 |
| - * @returns Get out-of-band requested proof presentation details |
76 |
| - */ |
77 |
| - sendOutOfBandPresentationRequest(outOfBandRequestProof: SendProofRequestPayload, user: IUserRequest): Promise<object> { |
78 |
| - const payload = { outOfBandRequestProof, user }; |
79 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'send-out-of-band-proof-request', payload); |
80 |
| - } |
81 |
| - |
82 |
| - getVerifiedProofDetails(proofId: string, orgId: string, user: IUserRequest): Promise<IProofPresentationDetails[]> { |
83 |
| - const payload = { proofId, orgId, user }; |
84 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'get-verified-proof-details', payload); |
85 |
| - } |
| 91 | + webhookProofPresentation(orgId: string, proofPresentationPayload: WebhookPresentationProofDto): Promise<object> { |
| 92 | + const payload = { orgId, proofPresentationPayload }; |
| 93 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'webhook-proof-presentation', payload); |
| 94 | + } |
86 | 95 |
|
87 |
| - async _getWebhookUrl(tenantId?: string, orgId?: string): Promise<string> { |
88 |
| - const pattern = { cmd: 'get-webhookurl' }; |
89 |
| - const payload = { tenantId, orgId }; |
90 |
| - |
91 |
| - try { |
92 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
93 |
| - const message = await this.verificationServiceProxy.send<any>(pattern, payload).toPromise(); |
94 |
| - return message; |
95 |
| - } catch (error) { |
96 |
| - this.logger.error(`catch: ${JSON.stringify(error)}`); |
97 |
| - throw error; |
98 |
| - } |
99 |
| - } |
100 |
| - |
101 |
| - async _postWebhookResponse(webhookUrl: string, data:object): Promise<string> { |
102 |
| - const pattern = { cmd: 'post-webhook-response-to-webhook-url' }; |
103 |
| - const payload = { webhookUrl, data }; |
| 96 | + /** |
| 97 | + * Out-Of-Band Proof Presentation |
| 98 | + * @param user |
| 99 | + * @param outOfBandRequestProof |
| 100 | + * @returns Get out-of-band requested proof presentation details |
| 101 | + */ |
| 102 | + sendOutOfBandPresentationRequest( |
| 103 | + outOfBandRequestProof: SendProofRequestPayload, |
| 104 | + user: IUserRequest |
| 105 | + ): Promise<object> { |
| 106 | + const payload = { outOfBandRequestProof, user }; |
| 107 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'send-out-of-band-proof-request', payload); |
| 108 | + } |
104 | 109 |
|
105 |
| - try { |
106 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
107 |
| - const message = await this.verificationServiceProxy.send<any>(pattern, payload).toPromise(); |
108 |
| - return message; |
109 |
| - } catch (error) { |
110 |
| - this.logger.error(`catch: ${JSON.stringify(error)}`); |
111 |
| - throw error; |
112 |
| - } |
113 |
| - } |
| 110 | + getVerifiedProofDetails(proofId: string, orgId: string, user: IUserRequest): Promise<IProofPresentationDetails[]> { |
| 111 | + const payload = { proofId, orgId, user }; |
| 112 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'get-verified-proof-details', payload); |
| 113 | + } |
114 | 114 |
|
115 |
| - async deleteVerificationRecords(orgId: string, userDetails: user): Promise<IVerificationRecords> { |
116 |
| - const payload = { orgId, userDetails }; |
117 |
| - return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'delete-verification-records', payload); |
| 115 | + async _getWebhookUrl(tenantId?: string, orgId?: string): Promise<string> { |
| 116 | + const pattern = { cmd: 'get-webhookurl' }; |
| 117 | + const payload = { tenantId, orgId }; |
| 118 | + |
| 119 | + try { |
| 120 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 121 | + const message = await this.verificationServiceProxy.send<any>(pattern, payload).toPromise(); |
| 122 | + return message; |
| 123 | + } catch (error) { |
| 124 | + this.logger.error(`catch: ${JSON.stringify(error)}`); |
| 125 | + throw error; |
118 | 126 | }
|
| 127 | + } |
| 128 | + |
| 129 | + async _postWebhookResponse(webhookUrl: string, data: object): Promise<string> { |
| 130 | + const pattern = { cmd: 'post-webhook-response-to-webhook-url' }; |
| 131 | + const payload = { webhookUrl, data }; |
| 132 | + |
| 133 | + try { |
| 134 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 135 | + const message = await this.verificationServiceProxy.send<any>(pattern, payload).toPromise(); |
| 136 | + return message; |
| 137 | + } catch (error) { |
| 138 | + this.logger.error(`catch: ${JSON.stringify(error)}`); |
| 139 | + throw error; |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + async deleteVerificationRecords(orgId: string, userDetails: user): Promise<IVerificationRecords> { |
| 144 | + const payload = { orgId, userDetails }; |
| 145 | + return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'delete-verification-records', payload); |
| 146 | + } |
119 | 147 | }
|
0 commit comments