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:add-invitation-did-for-reuse-connection #694

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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 apps/api-gateway/src/connection/dtos/connection.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export class CreateOutOfBandConnectionInvitation {
@IsOptional()
@IsNotEmpty({ message: 'Please provide recipientKey' })
recipientKey: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'Please provide invitation did' })
invitationDid?: string;

orgId;
}
Expand Down Expand Up @@ -125,6 +131,12 @@ export class CreateConnectionDto {
@IsOptional()
@IsNotEmpty({ message: 'Please provide recipientKey' })
recipientKey: string;

@ApiPropertyOptional()
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'Please provide invitation did' })
invitationDid?: string;
}

export class ConnectionDto {
Expand Down
4 changes: 2 additions & 2 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ConnectionRepository {
connectionInvitation: string,
agentId: string,
orgId: string,
recipientKey: string
invitationDid : string
// eslint-disable-next-line camelcase
): Promise<agent_invitations> {
try {
Expand All @@ -59,7 +59,7 @@ export class ConnectionRepository {
agentId,
connectionInvitation,
multiUse: true,
recipientKey
invitationDid
}
});
return agentDetails;
Expand Down
13 changes: 8 additions & 5 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ export class ConnectionService {
multiUseInvitation,
orgId,
routing,
recipientKey
recipientKey,
invitationDid
} = payload?.createOutOfBandConnectionInvitation;

const agentDetails = await this.connectionRepository.getAgentEndPoint(payload?.createOutOfBandConnectionInvitation?.orgId);
Expand All @@ -645,7 +646,8 @@ export class ConnectionService {
appendedAttachments: appendedAttachments || undefined,
routing: routing || undefined,
messages: messages || undefined,
recipientKey: recipientKey || undefined
recipientKey: recipientKey || undefined,
invitationDid: invitationDid || undefined
};

const createConnectionInvitationFlag = 'connection-invitation';
Expand All @@ -662,12 +664,13 @@ export class ConnectionService {
connectionInvitationUrl,
connectionPayload.multiUseInvitation
);
const recipientsKey = createConnectionInvitation?.response?.recipientKey || recipientKey;

const invitationsDid = createConnectionInvitation?.response?.invitationDid || invitationDid;
const saveConnectionDetails = await this.connectionRepository.saveAgentConnectionInvitations(
shortenedUrl,
agentId,
orgId,
recipientsKey
invitationsDid
);
const connectionDetailRecords: ConnectionResponseDetail = {
id: saveConnectionDetails.id,
Expand All @@ -680,7 +683,7 @@ export class ConnectionService {
lastChangedDateTime: saveConnectionDetails.lastChangedDateTime,
lastChangedBy: saveConnectionDetails.lastChangedBy,
recordId: createConnectionInvitation.response.outOfBandRecord.id,
recipientKey: saveConnectionDetails.recipientKey
invitationDid: saveConnectionDetails.invitationDid
};
return connectionDetailRecords;
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion apps/connection/src/interfaces/connection.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IConnection {
handshakeProtocols: string[];
orgId: string;
recipientKey?: string;
invitationDid?: string
}
export interface IUserRequestInterface {
userId: string;
Expand Down Expand Up @@ -265,7 +266,7 @@ export interface ConnectionResponseDetail {
lastChangedDateTime: Date;
lastChangedBy: number;
recordId: string;
recipientKey:string;
invitationDid?: string
}

export interface ICreateConnectionInvitation {
Expand All @@ -283,6 +284,7 @@ export interface ICreateConnectionInvitation {
appendedAttachments?: object[];
orgId?: string;
recipientKey?: string;
invitationDid?: string;
}

export interface ICreateOutOfbandConnectionInvitation {
Expand Down
4 changes: 2 additions & 2 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class IssuanceRepository {
}


async getRecipientKeyByOrgId(orgId: string): Promise<agent_invitations[]> {
async getInvitationDidByOrgId(orgId: string): Promise<agent_invitations[]> {
try {
return this.prisma.agent_invitations.findMany({
where: {
Expand All @@ -83,7 +83,7 @@ export class IssuanceRepository {
}
});
} catch (error) {
this.logger.error(`Error in getRecipientKey in issuance repository: ${error.message}`);
this.logger.error(`Error in getInvitationDid in issuance repository: ${error.message}`);
throw error;
}
}
Expand Down
10 changes: 5 additions & 5 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ export class IssuanceService {
}

const agentDetails = await this.issuanceRepository.getAgentEndPoint(orgId);
let recipientKey: string | undefined;
let invitationDid: string | undefined;
if (true === reuseConnection) {
const data: agent_invitations[] = await this.issuanceRepository.getRecipientKeyByOrgId(orgId);
const data: agent_invitations[] = await this.issuanceRepository.getInvitationDidByOrgId(orgId);
if (data && 0 < data.length) {
const [firstElement] = data;
recipientKey = firstElement?.recipientKey ?? undefined;
invitationDid = firstElement?.invitationDid ?? undefined;
}
}
const { agentEndPoint, organisation } = agentDetails;
Expand Down Expand Up @@ -233,7 +233,7 @@ export class IssuanceService {
imageUrl: organisation?.logoUrl || payload?.imageUrl || undefined,
label: organisation?.name,
comment: comment || '',
recipientKey:recipientKey || undefined
invitationDid:invitationDid || undefined
};

}
Expand All @@ -254,7 +254,7 @@ export class IssuanceService {
imageUrl: organisation?.logoUrl || payload?.imageUrl || undefined,
label: organisation?.name,
comment: comment || '',
recipientKey:recipientKey || undefined
invitationDid:invitationDid || undefined
};
}
const credentialCreateOfferDetails = await this._outOfBandCredentialOffer(issueData, url, orgId);
Expand Down
1 change: 1 addition & 0 deletions apps/verification/src/interfaces/verification.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export interface ISendProofRequestPayload {
presentationDefinition?:IProofRequestPresentationDefinition;
reuseConnection?: boolean;
recipientKey?:string;
invitationDid?: string
}

export interface IWSendProofRequestPayload {
Expand Down
4 changes: 2 additions & 2 deletions apps/verification/src/repositories/verification.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class VerificationRepository {
}

// eslint-disable-next-line camelcase
async getRecipientKeyByOrgId(orgId: string): Promise<agent_invitations[]> {
async getInvitationDidByOrgId(orgId: string): Promise<agent_invitations[]> {
try {
return this.prisma.agent_invitations.findMany({
where: {
Expand All @@ -198,7 +198,7 @@ export class VerificationRepository {
}
});
} catch (error) {
this.logger.error(`Error in getRecipientKey in verification repository: ${error.message}`);
this.logger.error(`Error in getInvitationDid in verification repository: ${error.message}`);
throw error;
}
}
Expand Down
10 changes: 5 additions & 5 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ export class VerificationService {

// Destructuring 'outOfBandRequestProof' to remove emailId, as it is not used while agent operation
const { isShortenUrl, emailId, type, reuseConnection, ...updateOutOfBandRequestProof } = outOfBandRequestProof;
let recipientKey: string | undefined;
let invitationDid: string | undefined;
if (true === reuseConnection) {
const data: agent_invitations[] = await this.verificationRepository.getRecipientKeyByOrgId(user.orgId);
const data: agent_invitations[] = await this.verificationRepository.getInvitationDidByOrgId(user.orgId);
if (data && 0 < data.length) {
const [firstElement] = data;
recipientKey = firstElement?.recipientKey ?? undefined;
invitationDid = firstElement?.invitationDid ?? undefined;
}
}
outOfBandRequestProof.autoAcceptProof = outOfBandRequestProof.autoAcceptProof || AutoAccept.Always;
Expand All @@ -363,7 +363,7 @@ export class VerificationService {

if (ProofRequestType.INDY === type) {
updateOutOfBandRequestProof.protocolVersion = updateOutOfBandRequestProof.protocolVersion || 'v1';
updateOutOfBandRequestProof.recipientKey = recipientKey || undefined;
updateOutOfBandRequestProof.invitationDid = invitationDid || undefined;
payload = {
orgId: user.orgId,
url,
Expand All @@ -390,7 +390,7 @@ export class VerificationService {
}
},
autoAcceptProof:outOfBandRequestProof.autoAcceptProof,
recipientKey:recipientKey || undefined
invitationDid:invitationDid || undefined
}
};
}
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/interfaces/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface InvitationMessage {
};
outOfBandRecord: OutOfBandRecord;
recipientKey?:string
invitationDid?: string
};
}

Expand Down
1 change: 1 addition & 0 deletions libs/common/src/interfaces/connection.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export interface IConnectionsListCount {
lastChangedDateTime: Date;
lastChangedBy: number;
recipientKey?:string;
invitationDid?: string
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "agent_invitations" ADD COLUMN "invitationDid" TEXT;
21 changes: 11 additions & 10 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ model org_agents {
}

model org_dids {
id String @id @default(uuid()) @db.Uuid
createDateTime DateTime @default(now()) @db.Timestamptz(6)
createdBy String @db.Uuid
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
lastChangedBy String @db.Uuid
orgId String @db.Uuid
isPrimaryDid Boolean
did String @db.VarChar(500)
id String @id @default(uuid()) @db.Uuid
createDateTime DateTime @default(now()) @db.Timestamptz(6)
createdBy String @db.Uuid
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
lastChangedBy String @db.Uuid
orgId String @db.Uuid
isPrimaryDid Boolean
did String @db.VarChar(500)
didDocument Json
orgAgentId String @db.Uuid
org_agents org_agents @relation(fields: [orgAgentId], references: [id])
orgAgentId String @db.Uuid
org_agents org_agents @relation(fields: [orgAgentId], references: [id])
}

model org_agents_type {
Expand Down Expand Up @@ -309,6 +309,7 @@ model agent_invitations {
org_agents org_agents @relation(fields: [agentId], references: [id])
organisation organisation @relation(fields: [orgId], references: [id])
recipientKey String?
invitationDid String?
}

model connections {
Expand Down