diff --git a/src/common/enums.ts b/src/common/enums.ts index dd66bea4f..0ef1c289c 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -35,6 +35,18 @@ export enum SchemaType { INDY = 'indy', W3C = 'w3c' } + +export enum CredentialType { + indy = 'indy', + anoncreds = 'anoncreds', + jsonld = 'jsonld' +} + +export enum ProtocolVersion { + v1 = 'v1', + v2 = 'v2' +} + export enum IssueCredentialUserText { offerSent = 'Offered', done = 'Accepted', diff --git a/src/components/Issuance/EmailIssuance.tsx b/src/components/Issuance/EmailIssuance.tsx index 6352e22ab..e697ccca1 100644 --- a/src/components/Issuance/EmailIssuance.tsx +++ b/src/components/Issuance/EmailIssuance.tsx @@ -12,7 +12,7 @@ import type { AxiosResponse } from 'axios'; import { getFromLocalStorage } from '../../api/Auth'; import { getSchemaCredDef } from '../../api/BulkIssuance'; import { storageKeys, apiStatusCodes } from '../../config/CommonConstant'; -import type { IAttributes, ICredentials, IValues } from './interface'; +import type { IAttributes, ICredentials, IValues, ICredentialFormats } from './interface'; import { Field, FieldArray, Form, Formik } from 'formik'; import CustomSpinner from '../CustomSpinner'; import { issueOobEmailCredential } from '../../api/issuance'; @@ -24,7 +24,7 @@ import { checkEcosystem } from '../../config/ecosystem'; import type { ICheckEcosystem} from '../../config/ecosystem'; import { Features } from '../../utils/enums/features'; import { Create, SchemaEndorsement } from './Constant'; -import { SchemaType } from '../../common/enums'; +import { SchemaType, CredentialType, ProtocolVersion } from '../../common/enums'; const EmailIssuance = () => { const [formData, setFormData] = useState(); @@ -104,24 +104,27 @@ const EmailIssuance = () => { setIssueLoader(true); const existingData = userData; - let transformedData = { credentialOffer: [] }; + let transformedData = { credentialType: CredentialType.indy, protocolVersion: ProtocolVersion.v2, credentialOffer: [] }; if (existingData && existingData.formData) { existingData?.formData?.forEach( (entry: { email: any; attributes: any[] }) => { - const transformedEntry = { emailId: entry.email, attributes: [] }; + const transformedEntry = { emailId: entry.email, credentialFormats: { + [CredentialType.indy]: { + credentialDefinitionId: credentialSelected, + attributes: [] + } + } }; entry.attributes.forEach((attribute) => { const transformedAttribute = { value: String(attribute.value || ''), - name: attribute.name || '', - isRequired: attribute.isRequired, + name: attribute.name || '' }; - transformedEntry?.attributes?.push(transformedAttribute); + transformedEntry?.credentialFormats[CredentialType.indy].attributes.push(transformedAttribute); }); transformedData.credentialOffer.push(transformedEntry); }, ); - transformedData.credentialDefinitionId = credentialSelected; const transformedJson = JSON.stringify(transformedData, null, 2); const response = await issueOobEmailCredential(transformedJson); const { data } = response as AxiosResponse; diff --git a/src/components/Issuance/Issuance.tsx b/src/components/Issuance/Issuance.tsx index 6d0af1b68..4c5f946ce 100644 --- a/src/components/Issuance/Issuance.tsx +++ b/src/components/Issuance/Issuance.tsx @@ -21,6 +21,7 @@ import type { SelectedUsers, } from './interface'; import SummaryCard from '../../commonComponents/SummaryCard'; +import { CredentialType, ProtocolVersion } from '../../common/enums'; const IssueCred = () => { const [schemaLoader, setSchemaLoader] = useState(true); @@ -163,16 +164,22 @@ const IssueCred = () => { const handleSubmit = async (values: IssuanceFormPayload) => { const issuancePayload = { + credentialType: CredentialType.indy, + protocolVersion: ProtocolVersion.v2, credentialData: values.credentialData.map((item) => { return { - ...item, - attributes: item.attributes.map((attr) => ({ - name: attr.name, - value: attr.value.toString(), - })), + connectionId: item.connectionId, + credentialFormats: { + [CredentialType.indy]: { + credentialDefinitionId: values.credentialDefinitionId, + attributes: item.attributes?.map((attr) => ({ + name: attr.name, + value: attr.value.toString(), + })), + } + } }; }), - credentialDefinitionId: values.credentialDefinitionId, orgId: values.orgId, }; diff --git a/src/components/Issuance/interface.ts b/src/components/Issuance/interface.ts index 923810aff..865919d1b 100644 --- a/src/components/Issuance/interface.ts +++ b/src/components/Issuance/interface.ts @@ -82,9 +82,26 @@ export interface Attributes { dataType: string; } +export interface IIssuanceAttribute { + name: string; + value: string; + mimeType?: string; +} + +export interface IIndy { + credentialDefinitionId: string; + attributes: IAttributes[]; +} + +export interface ICredentialFormats { + 'indy': IIndy; +} + export interface ICredentialdata { connectionId: string; - attributes: Attributes[]; + credentialFormats?: ICredentialFormats; + // To do: should remove attributes later + attributes?: Attributes[]; } export interface IssuanceFormPayload { userName?: string; diff --git a/src/components/Verification/Verification.tsx b/src/components/Verification/Verification.tsx index 7f85f7af6..96aa730cc 100644 --- a/src/components/Verification/Verification.tsx +++ b/src/components/Verification/Verification.tsx @@ -19,6 +19,7 @@ import type { VerifyCredentialPayload, } from './interface'; import SummaryCard from '../../commonComponents/SummaryCard'; +import { CredentialType, ProtocolVersion } from '../../common/enums'; const VerificationCred = () => { const [attributeList, setAttributeList] = useState([]); @@ -160,13 +161,44 @@ const VerificationCred = () => { schemaId: schemaId, })); + // Separate attributes into requested_attributes and requested_predicates + const requested_attributes = {}; + const requested_predicates = {}; + + attributes.forEach(attr => { + const restrictions = [ + { + schema_id: attr.schemaId, + ...(attr.credDefId ? { cred_def_id: attr.credDefId } : {}) + } + ] + if (attr.condition && attr.value !== undefined) { + requested_predicates[attr.attributeName] = { + name: attr.attributeName, + p_type: attr.condition, + p_value: attr.value, + restrictions: restrictions + }; + } else { + requested_attributes[attr.attributeName] = { + name: attr.attributeName, + restrictions: restrictions + }; + } + }); + const verifyCredentialPayload = { connectionId: JSON.parse(userData)[0]?.connectionId, + type: CredentialType.indy , + protocolVersion: ProtocolVersion.v2, comment: 'string', orgId: orgId, proofFormats: { - indy: { - attributes: attributes, + [CredentialType.indy]: { + name: 'proof request', + version: 'v1', + requested_attributes: requested_attributes, + requested_predicates: requested_predicates } } };