Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update issuance and verification payload #684

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/common/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 11 additions & 8 deletions src/components/Issuance/EmailIssuance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions src/components/Issuance/Issuance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(true);
Expand Down Expand Up @@ -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,
};

Expand Down
19 changes: 18 additions & 1 deletion src/components/Issuance/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 34 additions & 2 deletions src/components/Verification/Verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableData[]>([]);
Expand Down Expand Up @@ -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
}
}
};
Expand Down
Loading