Skip to content

Commit

Permalink
feat: reuse connection for issuance (#949)
Browse files Browse the repository at this point in the history
* feat: reuse connection for issuance

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: property name

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: argument name

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: dto name

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* fix: added certificate template

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

---------

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 6, 2024
1 parent 1f1e260 commit 940bfd2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
6 changes: 6 additions & 0 deletions apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ export class OOBCredentialDtoWithEmail {
@IsOptional()
credentialType: IssueCredentialType;

@ApiPropertyOptional({ default: true })
@IsOptional()
@IsNotEmpty({ message: 'please provide valid value for isReuseConnection' })
@IsBoolean({ message: 'isReuseConnection must be a boolean' })
isReuseConnection?: boolean;

imageUrl?: string;

orgId: string;
Expand Down
4 changes: 2 additions & 2 deletions apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,9 @@ async downloadBulkIssuanceCSVTemplate(
async outOfBandCredentialOffer(
@User() user: IUserRequest,
@Body() outOfBandCredentialDto: OOBCredentialDtoWithEmail,
@Query('credentialType') credentialType: IssueCredentialType = IssueCredentialType.INDY,
@Param('orgId') orgId: string,
@Res() res: Response
@Res() res: Response,
@Query('credentialType') credentialType: IssueCredentialType = IssueCredentialType.INDY
): Promise<Response> {
outOfBandCredentialDto.orgId = orgId;
outOfBandCredentialDto.credentialType = credentialType;
Expand Down
3 changes: 3 additions & 0 deletions apps/issuance/interfaces/issuance.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface OutOfBandCredentialOfferPayload {
emailId?: string;
attributes?: IAttributes[];
protocolVersion?: string;
isReuseConnection?: boolean;
goalCode?: string,
parentThreadId?: string,
willConfirm?: boolean,
Expand Down Expand Up @@ -282,6 +283,7 @@ export interface SendEmailCredentialOffer {
index: number;
credentialType: IssueCredentialType;
protocolVersion: string;
isReuseConnection?: boolean;
attributes: IAttributes[];
credentialDefinitionId: string;
outOfBandCredential: OutOfBandCredentialOfferPayload;
Expand Down Expand Up @@ -341,6 +343,7 @@ export interface IQueuePayload{
certificate?: string;
size?: string;
orientation?: string;
isReuseConnection?: boolean;
}

interface FileDetails {
Expand Down
32 changes: 24 additions & 8 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ async outOfBandCredentialOffer(outOfBandCredential: OutOfBandCredentialOfferPayl
protocolVersion,
attributes,
emailId,
credentialType
credentialType,
isReuseConnection
} = outOfBandCredential;

if (IssueCredentialType.JSONLD === credentialType) {
Expand Down Expand Up @@ -637,6 +638,7 @@ async outOfBandCredentialOffer(outOfBandCredential: OutOfBandCredentialOfferPayl
index: number;
credentialType: IssueCredentialType;
protocolVersion: string;
isReuseConnection?: boolean;
attributes: IAttributes[];
credentialDefinitionId: string;
outOfBandCredential: OutOfBandCredentialOfferPayload;
Expand All @@ -652,6 +654,7 @@ async outOfBandCredentialOffer(outOfBandCredential: OutOfBandCredentialOfferPayl
} = {
credentialType,
protocolVersion,
isReuseConnection,
attributes,
credentialDefinitionId,
outOfBandCredential,
Expand Down Expand Up @@ -735,12 +738,22 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
orgId,
organizationDetails,
platformName,
organizationLogoUrl
organizationLogoUrl,
isReuseConnection
} = sendEmailCredentialOffer;
const iterationNo = index + 1;
try {


let invitationDid: string | undefined;
if (true === isReuseConnection) {
const data: agent_invitations[] = await this.issuanceRepository.getInvitationDidByOrgId(orgId);
if (data && 0 < data.length) {
const [firstElement] = data;
invitationDid = firstElement?.invitationDid ?? undefined;
}
}

let outOfBandIssuancePayload;
if (IssueCredentialType.INDY === credentialType) {

Expand All @@ -759,7 +772,8 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
parentThreadId: outOfBandCredential.parentThreadId || undefined,
willConfirm: outOfBandCredential.willConfirm || undefined,
label: organisation?.name,
imageUrl: organisation?.logoUrl || outOfBandCredential?.imageUrl
imageUrl: organisation?.logoUrl || outOfBandCredential?.imageUrl,
invitationDid: invitationDid || undefined
};
}

Expand All @@ -779,7 +793,8 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
parentThreadId: outOfBandCredential.parentThreadId || undefined,
willConfirm: outOfBandCredential.willConfirm || undefined,
label: organisation?.name,
imageUrl: organisation?.logoUrl || outOfBandCredential?.imageUrl
imageUrl: organisation?.logoUrl || outOfBandCredential?.imageUrl,
invitationDid: invitationDid || undefined
};

const payloadAttributes = outOfBandIssuancePayload?.credentialFormats?.jsonld?.credential?.credentialSubject;
Expand Down Expand Up @@ -1516,7 +1531,6 @@ return newCacheKey;
const { orgId } = jobDetails;

const agentDetails = await this.issuanceRepository.getAgentEndPoint(orgId);

const { organisation, orgDid } = agentDetails;
let prettyVc;
let isErrorOccurred = false;
Expand All @@ -1529,7 +1543,8 @@ return newCacheKey;
label: organisation?.name,
attributes: [],
emailId: jobDetails?.credential_data?.email_identifier,
credentialType: IssueCredentialType.INDY
credentialType: IssueCredentialType.INDY,
isReuseConnection: true
};
for (const key in jobDetails?.credential_data) {

Expand All @@ -1546,8 +1561,8 @@ return newCacheKey;
schemaLedgerId,
credentialData: jobDetails.credential_data,
orgDid,
orgId

orgId,
isReuseConnection: true
};

prettyVc = {
Expand All @@ -1558,6 +1573,7 @@ return newCacheKey;

oobIssuancepayload = await createOobJsonldIssuancePayload(JsonldCredentialDetails, prettyVc);
}

const oobCredentials = await this.outOfBandCredentialOffer(
oobIssuancepayload, jobDetails?.platformName, jobDetails?.organizationLogoUrl, prettyVc);
if (oobCredentials) {
Expand Down
7 changes: 7 additions & 0 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,12 @@ export class VerificationService {

const verifiableCredential = verifiableCredentials[index]?.credentialSubject;

if (getProofPresentationById?.response) {
certificate =
getProofPresentationById?.response?.presentation?.presentationExchange?.verifiableCredential[0].prettyVc
?.certificate;
}

if (
requestedAttributesForPresentationExchangeFormat &&
Array.isArray(requestedAttributesForPresentationExchangeFormat)
Expand All @@ -806,6 +812,7 @@ export class VerificationService {
}
});
}

// For Indy format
if (getProofPresentationById?.response?.request?.indy) {
const requestedAttributes = getProofPresentationById?.response?.request?.indy?.requested_attributes;
Expand Down
5 changes: 3 additions & 2 deletions libs/common/src/cast.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const validateEmail = (email: string): boolean => {

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldCredential, prettyVc: IPrettyVc) => {
const {credentialData, orgDid, orgId, schemaLedgerId, schemaName} = JsonldCredentialDetails;
const {credentialData, orgDid, orgId, schemaLedgerId, schemaName, isReuseConnection} = JsonldCredentialDetails;
const credentialSubject = { };

const proofType = (orgDid?.includes(DidMethod.POLYGON)) ? ProofType.POLYGON_PROOFTYPE : ProofType.NO_LEDGER_PROOFTYPE;
Expand Down Expand Up @@ -215,7 +215,8 @@ export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldC
'comment': 'string',
'protocolVersion': 'v2',
'credentialType': 'jsonld',
orgId
orgId,
isReuseConnection
};
};

Expand Down
1 change: 1 addition & 0 deletions libs/common/src/interfaces/issuance.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IIssuedCredential {
credentialData: CredentialData
orgDid: string;
orgId: string;
isReuseConnection?: boolean;
}

export interface ICredentialOfferResponse {
Expand Down

0 comments on commit 940bfd2

Please sign in to comment.