Skip to content

Commit

Permalink
feat: integrate receive invitation JSON and receive invitation URL (#437
Browse files Browse the repository at this point in the history
)

* fix: removed the unnecessary logger from the agent-service module (#419)

Signed-off-by: KulkarniShashank <[email protected]>

* feat: integrate receive invitation url and invitation JSON

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: modify the interface in connection

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: modify the interface in agent-service

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: modify the interface in agent-service

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: modify the interface in connection dto

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: added common interface in conection and agent service

Signed-off-by: KulkarniShashank <[email protected]>

---------

Signed-off-by: KulkarniShashank <[email protected]>
Co-authored-by: Nishad Shirsat <[email protected]>
Co-authored-by: Nishad <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
  • Loading branch information
4 people authored and KulkarniShashank committed Sep 11, 2024
1 parent 5964ac7 commit 5f434a0
Show file tree
Hide file tree
Showing 12 changed files with 668 additions and 112 deletions.
30 changes: 23 additions & 7 deletions apps/agent-service/src/agent-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IProofPresentationDetails } from '@credebl/common/interfaces/verificati

@Controller()
export class AgentServiceController {
constructor(private readonly agentServiceService: AgentServiceService) {}
constructor(private readonly agentServiceService: AgentServiceService) { }


//DONE
Expand Down Expand Up @@ -45,7 +45,7 @@ export class AgentServiceController {
return this.agentServiceService.createCredentialDefinition(payload);
}

// DONE
// DONE
@MessagePattern({ cmd: 'agent-get-credential-definition' })
async getCredentialDefinitionById(payload: IGetCredDefAgentRedirection): Promise<object> {
return this.agentServiceService.getCredentialDefinitionById(payload);
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AgentServiceController {
}): Promise<IAgentProofRequest> {
return this.agentServiceService.sendProofRequest(payload.proofRequestPayload, payload.url, payload.apiKey);
}
//DONE
//DONE
@MessagePattern({ cmd: 'agent-verify-presentation' })
async verifyPresentation(payload: { url: string; apiKey: string }): Promise<IPresentation> {
return this.agentServiceService.verifyPresentation(payload.url, payload.apiKey);
Expand All @@ -119,9 +119,8 @@ export class AgentServiceController {
return this.agentServiceService.getConnections(payload.url, payload.apiKey);
}

//DONE
@MessagePattern({ cmd: 'agent-get-connections-by-connectionId' })
async getConnectionsByconnectionId(payload: { url: string; apiKey: string }): Promise<object> {
@MessagePattern({ cmd: 'agent-get-connection-details-by-connectionId' })
async getConnectionsByconnectionId(payload: { url: string, apiKey: string }): Promise<IConnectionDetailsById> {
return this.agentServiceService.getConnectionsByconnectionId(payload.url, payload.apiKey);
}

Expand Down Expand Up @@ -205,5 +204,22 @@ export class AgentServiceController {
async getOrgAgentApiKey(payload: { orgId: string }): Promise<string> {
return this.agentServiceService.getOrgAgentApiKey(payload.orgId);
}


@MessagePattern({ cmd: 'agent-receive-invitation-url' })
async receiveInvitationUrl(payload: {
url,
apiKey,
receiveInvitationUrl
}): Promise<string> {
return this.agentServiceService.receiveInvitationUrl(payload.receiveInvitationUrl, payload.url, payload.apiKey);
}

@MessagePattern({ cmd: 'agent-receive-invitation' })
async receiveInvitation(payload: {
url,
apiKey,
receiveInvitation
}): Promise<string> {
return this.agentServiceService.receiveInvitation(payload.receiveInvitation, payload.url, payload.apiKey);
}
}
37 changes: 26 additions & 11 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as dotenv from 'dotenv';
import * as fs from 'fs';
import { map } from 'rxjs/operators';
dotenv.config();
import { IGetCredDefAgentRedirection, IConnectionDetails, IUserRequestInterface, IAgentSpinupDto, IStoreOrgAgentDetails, ITenantCredDef, ITenantDto, ITenantSchema, IWalletProvision, ISendProofRequestPayload, IIssuanceCreateOffer, IOutOfBandCredentialOffer, IAgentSpinUpSatus, ICreateTenant, IAgentStatus, ICreateOrgAgent, IOrgAgentsResponse, IProofPresentation, IAgentProofRequest, IPresentation } from './interface/agent-service.interface';
import { IGetCredDefAgentRedirection, IConnectionDetails, IUserRequestInterface, IAgentSpinupDto, IStoreOrgAgentDetails, ITenantCredDef, ITenantDto, ITenantSchema, IWalletProvision, ISendProofRequestPayload, IIssuanceCreateOffer, IOutOfBandCredentialOffer, IAgentSpinUpSatus, ICreateTenant, IAgentStatus, ICreateOrgAgent, IOrgAgentsResponse, IProofPresentation, IAgentProofRequest, IPresentation, IReceiveInvitationUrl, IReceiveInvitation } from './interface/agent-service.interface';
import { AgentSpinUpStatus, AgentType, Ledgers, OrgAgentType } from '@credebl/enum/enum';
import { AgentServiceRepository } from './repositories/agent-service.repository';
import { ledgers, org_agents, organisation, platform_config } from '@prisma/client';
Expand Down Expand Up @@ -851,7 +851,6 @@ export class AgentServiceService {
{ headers: { 'authorization': platformAdminSpinnedUp.org_agents[0].apiKey } }
);

this.logger.debug(`API Response Data: ${JSON.stringify(tenantDetails)}`);
return tenantDetails;
}

Expand Down Expand Up @@ -896,7 +895,6 @@ export class AgentServiceService {
};
schemaResponse = await this.commonService.httpPost(url, schemaPayload, { headers: { 'authorization': payload.apiKey } })
.then(async (schema) => {
this.logger.debug(`API Response Data: ${JSON.stringify(schema)}`);
return schema;
})
.catch(error => {
Expand All @@ -917,7 +915,6 @@ export class AgentServiceService {
};
schemaResponse = await this.commonService.httpPost(url, schemaPayload, { headers: { 'authorization': payload.apiKey } })
.then(async (schema) => {
this.logger.debug(`API Response Data: ${JSON.stringify(schema)}`);
return schema;
})
.catch(error => {
Expand All @@ -942,7 +939,6 @@ export class AgentServiceService {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID.replace('#', `${payload.schemaId}`)}`;
schemaResponse = await this.commonService.httpGet(url, payload.schemaId)
.then(async (schema) => {
this.logger.debug(`API Response Data: ${JSON.stringify(schema)}`);
return schema;
});

Expand All @@ -951,7 +947,6 @@ export class AgentServiceService {

schemaResponse = await this.commonService.httpGet(url, { headers: { 'authorization': payload.apiKey } })
.then(async (schema) => {
this.logger.debug(`API Response Data: ${JSON.stringify(schema)}`);
return schema;
});
}
Expand All @@ -977,7 +972,6 @@ export class AgentServiceService {

credDefResponse = await this.commonService.httpPost(url, credDefPayload, { headers: { 'authorization': payload.apiKey } })
.then(async (credDef) => {
this.logger.debug(`API Response Data: ${JSON.stringify(credDef)}`);
return credDef;
});

Expand All @@ -990,7 +984,6 @@ export class AgentServiceService {
};
credDefResponse = await this.commonService.httpPost(url, credDefPayload, { headers: { 'authorization': payload.apiKey } })
.then(async (credDef) => {
this.logger.debug(`API Response Data: ${JSON.stringify(credDef)}`);
return credDef;
});
}
Expand All @@ -1010,15 +1003,13 @@ export class AgentServiceService {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_CRED_DEF_BY_ID.replace('#', `${payload.credentialDefinitionId}`)}`;
credDefResponse = await this.commonService.httpGet(url, payload.credentialDefinitionId)
.then(async (credDef) => {
this.logger.debug(`API Response Data: ${JSON.stringify(credDef)}`);
return credDef;
});

} else if (OrgAgentType.SHARED === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CRED_DEF}`.replace('@', `${payload.payload.credentialDefinitionId}`).replace('#', `${payload.tenantId}`);
credDefResponse = await this.commonService.httpGet(url, { headers: { 'authorization': payload.apiKey } })
.then(async (credDef) => {
this.logger.debug(`API Response Data: ${JSON.stringify(credDef)}`);
return credDef;
});
}
Expand Down Expand Up @@ -1147,7 +1138,7 @@ export class AgentServiceService {

try {
const data = await this.commonService
.httpGet(url, { headers: { 'x-api-key': apiKey } })
.httpGet(url, { headers: { 'authorization': apiKey } })
.then(async response => response)
.catch(error => this.handleAgentSpinupStatusErrors(error));

Expand Down Expand Up @@ -1309,6 +1300,30 @@ export class AgentServiceService {
}
}

async receiveInvitationUrl(receiveInvitationUrl: IReceiveInvitationUrl, url: string, apiKey: string): Promise<string> {
try {
const receiveInvitationUrlRes = await this.commonService
.httpPost(url, receiveInvitationUrl, { headers: { 'authorization': apiKey } })
.then(async response => response);
return receiveInvitationUrlRes;
} catch (error) {
this.logger.error(`Error in receive invitation in agent service : ${JSON.stringify(error)}`);
throw error;
}
}

async receiveInvitation(receiveInvitation: IReceiveInvitation, url: string, apiKey: string): Promise<string> {
try {
const receiveInvitationRes = await this.commonService
.httpPost(url, receiveInvitation, { headers: { 'authorization': apiKey } })
.then(async response => response);
return receiveInvitationRes;
} catch (error) {
this.logger.error(`Error in receive invitation in agent service : ${JSON.stringify(error)}`);
throw error;
}
}

async getOrgAgentApiKey(orgId: string): Promise<string> {
try {
let agentApiKey;
Expand Down
93 changes: 51 additions & 42 deletions apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IAgentSpinupDto {
tenant?: boolean;
ledgerName?: string[];
platformAdminEmail?: string;
apiKey?:string;
apiKey?: string;
}

export interface IOutOfBandCredentialOffer {
Expand Down Expand Up @@ -83,26 +83,6 @@ export interface ITenantCredDef {
agentEndPoint?: string;
}

export interface ITenantCredDefDto {
tag: string;
schemaId: string;
issuerId: string;
}

export interface IGetCredDefAgentRedirection {
credentialDefinitionId?: string;
tenantId?: string;
payload?: IGetCredDefFromTenantPayload;
apiKey?: string;
agentEndPoint?: string;
agentType?: string;
method?: string;
}

export interface IGetCredDefFromTenantPayload {
credentialDefinitionId: string;
}

export interface IWalletProvision {
orgId: string;
externalIp: string;
Expand All @@ -122,7 +102,7 @@ export interface IWalletProvision {
afjVersion: string;
protocol: string;
tenant: boolean;
apiKey?:string;
apiKey?: string;
}

export interface IPlatformConfigDto {
Expand Down Expand Up @@ -174,19 +154,19 @@ export interface IUserRequestInterface {
tenantOrgId?: string;
userRoleOrgPermissions?: UserRoleOrgPermsDto[];
orgName?: string;
selectedOrg: ISelectedOrgInterface;
selectedOrg: IOrgInterface;
}

export interface ISelectedOrgInterface {
export interface IOrgInterface {
id: string;
userId: string;
orgRoleId: string;
orgId: string;
orgRole: object;
organisation: IOrganizationInterface;
organisation: IOrganizationAgentInterface;
}

export interface IOrganizationInterface {
export interface IOrganizationAgentInterface {
name: string;
description: string;
org_agents: IOrgAgentInterface[]
Expand All @@ -203,18 +183,6 @@ export interface IOrgAgentInterface {
orgId: string;
}

export interface ITenantCredDef {
tenantId?: string;
tag?: string;
schemaId?: string;
issuerId?: string;
payload?: ITenantCredDef;
method?: string;
agentType?: string;
apiKey?: string;
agentEndPoint?: string;
}

export interface ITenantCredDefDto {
tag: string;
schemaId: string;
Expand Down Expand Up @@ -356,6 +324,9 @@ export interface IStoreAgent {
id: string;
}

export interface IAcceptCredentials {
credentialRecordId: string;
}
export interface IAgentProofRequest {
metadata: object;
id: string;
Expand All @@ -366,7 +337,7 @@ export interface IAgentProofRequest {
threadId: string;
autoAcceptProof: string;
updatedAt: string;
}
}

export interface IPresentation {
_tags: ITags;
Expand All @@ -377,6 +348,44 @@ export interface IStoreAgent {
id: string;
}

export interface IReceiveInvite {
alias?: string;
label?: string;
imageUrl?: string;
autoAcceptConnection?: boolean;
autoAcceptInvitation?: boolean;
reuseConnection?: boolean;
acceptInvitationTimeoutMs?: number;
}

export interface IReceiveInvitationUrl extends IReceiveInvite {
invitationUrl: string;
}

interface IService {
id: string;
serviceEndpoint: string;
type: string;
recipientKeys: string[];
routingKeys: string[];
accept: string[];
}

interface IInvitation {
'@id': string;
'@type': string;
label: string;
goalCode: string;
goal: string;
accept: string[];
handshake_protocols: string[];
services: (IService | string)[];
imageUrl?: string;
}

export interface IReceiveInvitation extends IReceiveInvite {
invitation: IInvitation;
}
export interface IProofPresentation {
createdAt: string;
protocolVersion: string;
Expand All @@ -386,11 +395,11 @@ export interface IProofPresentation {
autoAcceptProof: string;
updatedAt: string;
isVerified: boolean;
}
}

interface ITags {
connectionId: string;
state: string;
threadId: string;
}
}

Loading

0 comments on commit 5f434a0

Please sign in to comment.