diff --git a/src/api/verification.ts b/src/api/verification.ts index 05c2b481..712a7b8b 100644 --- a/src/api/verification.ts +++ b/src/api/verification.ts @@ -1,4 +1,4 @@ -import type { IssueCredential, RequestType } from '../common/enums'; +import { APIVersion, type IssueCredential, type RequestType } from '../common/enums'; import { apiRoutes } from '../config/apiRoutes'; import { storageKeys } from '../config/CommonConstant'; import { getHeaderConfigs } from '../config/GetHeaderConfigs'; @@ -23,6 +23,23 @@ export const verifyCredential = async (payload: object, requestType:RequestType) } }; +export const verifyCredentialV2 = async (payload: object, requestType:RequestType) => { + const orgId = await getFromLocalStorage(storageKeys.ORG_ID); + const url = `${APIVersion.version_v2}${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.verifyCredential}?requestType=${requestType}`; + const axiosPayload = { + url, + payload, + config: await getHeaderConfigs(), + }; + + try { + return await axiosPost(axiosPayload); + } catch (error) { + const err = error as Error; + return err?.message; + } +}; + export const createOobProofRequest = async (payload: object, requestType: RequestType) => { const orgId = await getFromLocalStorage(storageKeys.ORG_ID); const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.oobProofRequest}?requestType=${requestType}`; diff --git a/src/common/enums.ts b/src/common/enums.ts index adb652b1..fa59a664 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -156,4 +156,8 @@ export enum Environment { PROD = 'PROD', DEV = 'DEV', QA = 'QA' +} + +export enum APIVersion { + version_v2 = '/v2' } \ No newline at end of file diff --git a/src/components/Verification/Connections.tsx b/src/components/Verification/Connections.tsx index 0ab5d786..67afe93f 100644 --- a/src/components/Verification/Connections.tsx +++ b/src/components/Verification/Connections.tsx @@ -15,7 +15,7 @@ import React from "react"; import type { IConnectionList } from "./interface"; import DateTooltip from "../Tooltip"; import { dateConversion } from "../../utils/DateConversion"; -import { verifyCredential } from '../../api/verification'; +import { verifyCredential, verifyCredentialV2 } from '../../api/verification'; import type { AxiosResponse } from "axios"; import { v4 as uuidv4 } from 'uuid'; import { getOrganizationById } from "../../api/organization"; @@ -165,7 +165,7 @@ const Connections = () => { verifyCredentialPayload = { - connectionId: connectionIds, + connectionId: connectionIds.length === 1 ? connectionIds[0] : connectionIds, orgId, proofFormats: { indy: { @@ -198,7 +198,7 @@ const Connections = () => { verifyCredentialPayload = { - connectionId: connectionIds, + connectionId: connectionIds.length === 1 ? connectionIds[0] : connectionIds, comment: 'proof request', presentationDefinition: { id: uuidv4(), @@ -232,9 +232,15 @@ const Connections = () => { } } - if (attributes && verifyCredentialPayload) { + if (attributes && verifyCredentialPayload ) { const requestType = isW3cDid ? RequestType.PRESENTATION_EXCHANGE : RequestType.INDY; - const response = await verifyCredential(verifyCredentialPayload, requestType); + let response; + if (typeof verifyCredentialPayload.connectionId === 'string') { + response = await verifyCredential(verifyCredentialPayload, requestType); + } else if (Array.isArray(verifyCredentialPayload.connectionId)) { + response = await verifyCredentialV2(verifyCredentialPayload, requestType); + } + const { data } = response as AxiosResponse; if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) { await removeFromLocalStorage(storageKeys.ATTRIBUTE_DATA);