Skip to content

Commit

Permalink
Merge pull request #298 from credebl/refactor-api-issuance-verificati…
Browse files Browse the repository at this point in the history
…on-connection

refactor: api's for connection issuance and verification
  • Loading branch information
16-karan authored Sep 21, 2023
2 parents 18dbb42 + 8778b6f commit 405a50d
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/api/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getFromLocalStorage } from './Auth';

export const getConnectionsByOrg = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Issuance.getAllConnections}?orgId=${orgId}`;
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.getAllConnections}`;
const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down
9 changes: 6 additions & 3 deletions src/api/issuance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { getHeaderConfigs } from '../config/GetHeaderConfigs';
import { axiosGet, axiosPost } from '../services/apiRequests';
import { getFromLocalStorage } from './Auth';

export const getIssuedCredentials = async (schemaId: string) => {
export const getIssuedCredentials = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.getIssuedCredentials}`;

const axiosPayload = {
url,
Expand All @@ -22,6 +22,7 @@ export const getIssuedCredentials = async (schemaId: string) => {
};

export const getCredentialDefinitions = async (schemaId: string) => {

const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

Expand All @@ -40,8 +41,10 @@ export const getCredentialDefinitions = async (schemaId: string) => {


export const issueCredential = async (data: object) => {
const url = apiRoutes.Issuance.issueCredential;
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Issuance.issueCredential}`;
const payload = data;

const axiosPayload = {
url,
payload,
Expand Down
4 changes: 1 addition & 3 deletions src/api/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,8 @@ export const editOrganizationUserRole = async (userId: number, roles: number[])


export const createConnection = async (orgName: string) => {

const url = apiRoutes.connection.create

const orgId = await getFromLocalStorage(storageKeys.ORG_ID)
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.connection.create}`

const data = {
label: orgName,
Expand Down
23 changes: 11 additions & 12 deletions src/api/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { axiosGet, axiosPost } from '../services/apiRequests';
import { getFromLocalStorage } from './Auth';

export const verifyCredential = async (payload: any) => {
const url = apiRoutes.Verification.verifyCredential;
const axiosPayload = {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.verifyCredential}`; const axiosPayload = {
url,
payload,
config: await getHeaderConfigs(),
Expand All @@ -24,7 +24,6 @@ export const verifyCredential = async (payload: any) => {
export const getVerificationCredential = async (state: IssueCredential) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Issuance.getIssuedCredentials}?orgId=${orgId}&state=${state}`;

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand All @@ -40,8 +39,8 @@ export const getVerificationCredential = async (state: IssueCredential) => {

export const getVerificationList = async () => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Verification.getAllRequestList}?orgId=${orgId}`;

const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.verifyCredential}`
const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand All @@ -55,10 +54,9 @@ export const getVerificationList = async () => {
}
};

export const verifyPresentation = async (id:string) => {
export const verifyPresentation = async (proofId:string) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Verification.presentationVerification}?orgId=${orgId}&id=${id}`;

const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.presentationVerification}/${proofId}/verify`;
const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand All @@ -73,10 +71,9 @@ export const verifyPresentation = async (id:string) => {
};


export const getProofAttributes=async (id:string)=>{
export const getProofAttributes=async (proofId:string)=>{
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.Verification.proofRequestAttributesVerification}?id=${id}&orgId=${orgId}`;

const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.proofRequestAttributesVerification}/${proofId}/form`;
const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand All @@ -91,7 +88,9 @@ export const getProofAttributes=async (id:string)=>{
}

export const getCredentialDefinitionsForVerification = async (schemaId: string) => {
const url = `${apiRoutes.schema.getCredDefBySchemaId}?schemaId=${schemaId}`;
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url= `${apiRoutes.organizations.root}/${orgId}${apiRoutes.schema.getCredDefBySchemaId}/${schemaId}/cred-defs`;

const axiosPayload = {
url,
config: await getHeaderConfigs(),
Expand Down
7 changes: 4 additions & 3 deletions src/components/AlertComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert } from 'flowbite-react';
import { pathRoutes } from '../../config/pathRoutes';

export const AlertComponent = ({ message, type, viewButton, onAlertClose }: { message: string | null, type: string, viewButton?: boolean, onAlertClose: () => void }) => {
export const AlertComponent = ({ message, type, viewButton, onAlertClose, path='' }: { message: string | null, type: string, viewButton?: boolean, path?:string, onAlertClose: () => void }) => {


return message !== null ? <Alert
Expand All @@ -16,12 +17,12 @@ export const AlertComponent = ({ message, type, viewButton, onAlertClose }: { me
{
viewButton
&& <p className='md:w-32 lg:w-48 text-base text-primary-700 text-right'>
View more...
<a href={path}>View more... </a>
</p>
}

</span>

</Alert>
: <></>
}
}
1 change: 1 addition & 0 deletions src/components/Issuance/CredDefSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const CredDefSelection = () => {
const getCredDefs = async (schemaId: string) => {
setLoading(true)
const response = await getCredentialDefinitions(schemaId);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
Expand Down
7 changes: 4 additions & 3 deletions src/components/Issuance/IssuedCrdentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const CredentialList = () => {

const getIssuedCredDefs = async () => {
setLoading(true);
const response = await getIssuedCredentials(
IssueCredential.credentialIssued,
);
const response = await getIssuedCredentials();

const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {

const credentialList = data?.data?.map(
(issuedCredential: IssuedCredential) => {
const schemaName = issuedCredential.metadata['_anoncreds/credential']
Expand All @@ -51,6 +51,7 @@ const CredentialList = () => {
.slice(2)
.join(':')
: 'Not available';

return {
data: [
{
Expand Down
2 changes: 0 additions & 2 deletions src/components/Resources/Schema/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import React from 'react';
const [orgId, setOrgId] = useState<number>(0);
const [orgDid, setOrgDid] = useState<string>('');
const [createloader, setCreateLoader] = useState<boolean>(false);

useEffect(() => {
const fetchData = async () => {
const organizationId = await getFromLocalStorage(
Expand Down Expand Up @@ -540,7 +539,6 @@ import React from 'react';
No, cancel
</button>
<Button
data-modal-hide="popup-modal"
type="submit"
isProcessing={createloader}
disabled={createloader}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Resources/Schema/SchemasList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
message={'No Schemas'}
description={'Get started by creating a new Schema'}
buttonContent={'Create'}
svgComponent={<svg className='pr-2' xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
onClick={() => {
Expand All @@ -234,4 +234,4 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
}


export default SchemaList
export default SchemaList
10 changes: 4 additions & 6 deletions src/components/User/UserDashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,20 @@ const UserDashBoard = () => {
getUserRecentActivity()
}, [])

const redirectToInvitations = () => {
window.location.href = pathRoutes.users.invitations
}

const goToOrgDashboard = async (orgId: number, roles: string[]) => {
await setToLocalStorage(storageKeys.ORG_ID, orgId.toString());
window.location.href = pathRoutes.organizations.dashboard;
};

return (
<div className="px-4 pt-6">
<div className="cursor-pointer" onClick={redirectToInvitations}>
<div className="cursor-pointer">

<AlertComponent
message={message ? message : error}
type={message ? 'warning' : 'failure'}
viewButton={viewButton}
path={pathRoutes.users.invitations}
onAlertClose={() => {
setMessage(null)
setError(null)
Expand Down Expand Up @@ -293,4 +291,4 @@ const UserDashBoard = () => {

)
}
export default UserDashBoard;
export default UserDashBoard;
3 changes: 2 additions & 1 deletion src/components/Verification/CredDefSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const CredDefSelection = () => {
//Fetch credential definitions against schemaId
const getCredDefs = async (schemaId: string) => {
setLoading(true)
const response = await getCredentialDefinitionsForVerification(schemaId);
const response = await getCredentialDefinitionsForVerification(schemaId,31);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Verification/Verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const VerificationCred = () => {

const attributes = await selectedUsersData.map(user => ({
attributeName: user.name,
credDefId: credDefId,
...(credDefId ? { credDefId } : {}),
schemaId: schemaId
}));
const verifyCredentialPayload: VerifyCredentialPayload = {
Expand Down
1 change: 1 addition & 0 deletions src/components/Verification/VerificationCredentialList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const VerificationCredentialList = () => {
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {

const credentialList = data?.data?.map((requestProof: RequestProof) => {
return {
data: [
Expand Down
5 changes: 3 additions & 2 deletions src/components/organization/OrganizationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {

setLoading(true)
const response = await createConnection(orgData?.name as string);

const { data } = response as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {

setConnectionData(data?.data)

Expand Down Expand Up @@ -210,4 +211,4 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {

}

export default OrganizationDetails
export default OrganizationDetails
2 changes: 1 addition & 1 deletion src/components/organization/OrganizationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const OrganizationsList = () => {
buttonContent={'Create Organization'}
onClick={createOrganizationModel}
feature={Features.CRETAE_ORG}
svgComponent={<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
svgComponent={<svg className='pr-2 mr-1' xmlns="http://www.w3.org/2000/svg" width="24" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>} />)
}
Expand Down
22 changes: 11 additions & 11 deletions src/config/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export const apiRoutes = {
fidoVerifyAuthentication: 'Fido/verify-authentication/'

},
Issuance:{
getIssuedCredentials:'/issue-credentials',
getAllConnections:'/connections',
issueCredential:'/issue-credentials/create-offer'
},
Verification:{
getAllRequestList: '/proofs',
verifyCredential:'/proofs/request-proof',
presentationVerification:'/proofs/verify-presentation',
proofRequestAttributesVerification:'/proofs/form-data'
},
Issuance: {
getIssuedCredentials: '/credentials',
getAllConnections: '/connections',
issueCredential: '/credentials/offer',
},
Verification: {
getAllRequestList: '/credentials/proofs',
verifyCredential: '/proofs',
presentationVerification: '/proofs',
proofRequestAttributesVerification: '/proofs'
},
Agent:{
checkAgentHealth: '/agents/health',
agentDedicatedSpinup: '/agents/spinup',
Expand Down

0 comments on commit 405a50d

Please sign in to comment.