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

feat: reuse connection for issuance #949

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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
5 changes: 3 additions & 2 deletions libs/common/src/cast.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,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 @@ -339,7 +339,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