From 56f06936afa04039684112e52f317941987e746b Mon Sep 17 00:00:00 2001 From: Krishna Waske Date: Tue, 28 May 2024 17:45:37 +0530 Subject: [PATCH 1/3] fix: update issuance and verification payload Signed-off-by: Krishna Waske --- src/components/Issuance/EmailIssuance.tsx | 17 ++++++----- src/components/Issuance/Issuance.tsx | 18 +++++++---- src/components/Issuance/interface.ts | 19 +++++++++++- src/components/Verification/Verification.tsx | 32 +++++++++++++++++++- 4 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/components/Issuance/EmailIssuance.tsx b/src/components/Issuance/EmailIssuance.tsx index 0b6826195..036366102 100644 --- a/src/components/Issuance/EmailIssuance.tsx +++ b/src/components/Issuance/EmailIssuance.tsx @@ -11,7 +11,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'; @@ -99,24 +99,27 @@ const EmailIssuance = () => { setIssueLoader(true); const existingData = userData; - let transformedData = { credentialOffer: [] }; + let transformedData = { credentialType: 'indy', 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: { + 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.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 336968c6f..ce95fc8cb 100644 --- a/src/components/Issuance/Issuance.tsx +++ b/src/components/Issuance/Issuance.tsx @@ -164,16 +164,22 @@ const IssueCred = () => { const handleSubmit = async (values: IssuanceFormPayload) => { const issuancePayload = { + credentialType: 'indy', + 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: { + 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 d9abcb51e..d26de7c9e 100644 --- a/src/components/Verification/Verification.tsx +++ b/src/components/Verification/Verification.tsx @@ -161,13 +161,43 @@ 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: 'indy', comment: 'string', orgId: orgId, proofFormats: { indy: { - attributes: attributes, + name: 'proof request', + version: 'v1', + requested_attributes: requested_attributes, + requested_predicates: requested_predicates } } }; From a0df9f0662afbebbcdb21f7e7778fc6bc6608f85 Mon Sep 17 00:00:00 2001 From: Krishna Waske Date: Mon, 3 Jun 2024 17:15:47 +0530 Subject: [PATCH 2/3] fix: use enum instead of static values Signed-off-by: Krishna Waske --- src/common/enums.ts | 12 ++++++++++++ src/components/Issuance/EmailIssuance.tsx | 7 ++++--- src/components/Issuance/Issuance.tsx | 7 ++++--- src/components/Verification/Verification.tsx | 6 ++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/common/enums.ts b/src/common/enums.ts index dd66bea4f..5fe440b51 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, + anoncreds, + jsonld +} + +export enum ProtocolVersion { + v1, + v2 +} + export enum IssueCredentialUserText { offerSent = 'Offered', done = 'Accepted', diff --git a/src/components/Issuance/EmailIssuance.tsx b/src/components/Issuance/EmailIssuance.tsx index 036366102..e04d66a29 100644 --- a/src/components/Issuance/EmailIssuance.tsx +++ b/src/components/Issuance/EmailIssuance.tsx @@ -22,6 +22,7 @@ import RoleViewButton from '../RoleViewButton'; import { checkEcosystem, type ICheckEcosystem } from '../../config/ecosystem'; import { Features } from '../../utils/enums/features'; import { Create, SchemaEndorsement } from './Constant'; +import { CredentialType, ProtocolVersion } from '../../common/enums'; const EmailIssuance = () => { const [formData, setFormData] = useState(); @@ -99,12 +100,12 @@ const EmailIssuance = () => { setIssueLoader(true); const existingData = userData; - let transformedData = { credentialType: 'indy', protocolVersion: 'v2', 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, credentialFormats: { - indy: { + [CredentialType.indy]: { credentialDefinitionId: credentialSelected, attributes: [] } @@ -114,7 +115,7 @@ const EmailIssuance = () => { value: String(attribute.value || ''), name: attribute.name || '' }; - transformedEntry?.credentialFormats.indy.attributes.push(transformedAttribute); + transformedEntry?.credentialFormats[CredentialType.indy].attributes.push(transformedAttribute); }); transformedData.credentialOffer.push(transformedEntry); diff --git a/src/components/Issuance/Issuance.tsx b/src/components/Issuance/Issuance.tsx index ce95fc8cb..3c7021441 100644 --- a/src/components/Issuance/Issuance.tsx +++ b/src/components/Issuance/Issuance.tsx @@ -22,6 +22,7 @@ import type { SelectedUsers, } from './interface'; import SummaryCard from '../../commonComponents/SummaryCard'; +import { CredentialType, ProtocolVersion } from '../../common/enums'; const IssueCred = () => { const [schemaLoader, setSchemaLoader] = useState(true); @@ -164,13 +165,13 @@ const IssueCred = () => { const handleSubmit = async (values: IssuanceFormPayload) => { const issuancePayload = { - credentialType: 'indy', - protocolVersion: 'v2', + credentialType: CredentialType.indy, + protocolVersion: ProtocolVersion.v2, credentialData: values.credentialData.map((item) => { return { connectionId: item.connectionId, credentialFormats: { - indy: { + [CredentialType.indy]: { credentialDefinitionId: values.credentialDefinitionId, attributes: item.attributes?.map((attr) => ({ name: attr.name, diff --git a/src/components/Verification/Verification.tsx b/src/components/Verification/Verification.tsx index d26de7c9e..c9f9065fa 100644 --- a/src/components/Verification/Verification.tsx +++ b/src/components/Verification/Verification.tsx @@ -20,6 +20,7 @@ import type { VerifyCredentialPayload, } from './interface'; import SummaryCard from '../../commonComponents/SummaryCard'; +import { CredentialType, ProtocolVersion } from '../../common/enums'; const VerificationCred = () => { const [attributeList, setAttributeList] = useState([]); @@ -189,11 +190,12 @@ const VerificationCred = () => { const verifyCredentialPayload = { connectionId: JSON.parse(userData)[0]?.connectionId, - type: 'indy', + type: CredentialType.indy , + protocolVersion: ProtocolVersion.v2, comment: 'string', orgId: orgId, proofFormats: { - indy: { + [CredentialType.indy]: { name: 'proof request', version: 'v1', requested_attributes: requested_attributes, From 0c796b6671f31e0b2145def74b6ee9de469b4ded Mon Sep 17 00:00:00 2001 From: Krishna Waske Date: Wed, 5 Jun 2024 15:59:33 +0530 Subject: [PATCH 3/3] fix: enum values Signed-off-by: Krishna Waske --- src/common/enums.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/enums.ts b/src/common/enums.ts index 5fe440b51..0ef1c289c 100644 --- a/src/common/enums.ts +++ b/src/common/enums.ts @@ -37,14 +37,14 @@ export enum SchemaType { } export enum CredentialType { - indy, - anoncreds, - jsonld + indy = 'indy', + anoncreds = 'anoncreds', + jsonld = 'jsonld' } export enum ProtocolVersion { - v1, - v2 + v1 = 'v1', + v2 = 'v2' } export enum IssueCredentialUserText {