Skip to content

Commit

Permalink
Merge pull request #243 from credebl/develop-main-multi-ecosystem
Browse files Browse the repository at this point in the history
feat: multi ecosystem feature to main branch
  • Loading branch information
KulkarniShashank authored Nov 9, 2023
2 parents b4a3ba3 + 6a41e66 commit c569293
Show file tree
Hide file tree
Showing 94 changed files with 3,199 additions and 1,006 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PLATFORM_ID=

AFJ_AGENT_ENDPOINT_PATH=/apps/agent-provisioning/AFJ/endpoints/
DATABASE_URL="postgresql://postgres:xxxxxx@localhost:5432/postgres?schema=public" #Provide supabase postgres url and Use the correct user/pwd, IP Address
POOL_DATABASE_URL="" #Provide pooler supabase postgres url
CLUSTER_NAME="" # ecs cluster
TESKDEFINITION_FAMILY="" # ecs task-definition
AGENT_PROTOCOL=http
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
dist
uploadedFiles
.env
sonar-project.properties
.scannerwork/*
Expand Down
1 change: 1 addition & 0 deletions Dockerfiles/Dockerfile.api-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ COPY --from=build /app/dist/apps/api-gateway/ ./dist/apps/api-gateway/
# Copy the libs folder from the build stage
COPY --from=build /app/libs/ ./libs/
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/uploadedFiles ./uploadedFiles

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate && cd ../.. && node dist/apps/api-gateway/main.js"]
1 change: 1 addition & 0 deletions Dockerfiles/Dockerfile.issuance
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COPY --from=build /app/dist/apps/issuance/ ./dist/apps/issuance/
COPY --from=build /app/libs/ ./libs/
#COPY --from=build /app/package.json ./
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/uploadedFiles ./uploadedFiles


# Set the command to run the microservice
Expand Down
7 changes: 6 additions & 1 deletion apps/agent-service/src/agent-service.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { AgentServiceService } from './agent-service.service';
import { GetCredDefAgentRedirection, GetSchemaAgentRedirection, IAgentSpinupDto, IIssuanceCreateOffer, ITenantCredDef, ITenantDto, ITenantSchema } from './interface/agent-service.interface';
import { GetCredDefAgentRedirection, GetSchemaAgentRedirection, IAgentSpinupDto, IIssuanceCreateOffer, ITenantCredDef, ITenantDto, ITenantSchema, OutOfBandCredentialOffer } from './interface/agent-service.interface';
import { IConnectionDetails, IUserRequestInterface } from './interface/agent-service.interface';
import { ISendProofRequestPayload } from './interface/agent-service.interface';
import { user } from '@prisma/client';
Expand Down Expand Up @@ -124,4 +124,9 @@ export class AgentServiceController {
async submitTransaction(payload: { url: string, apiKey: string, submitEndorsementPayload:object }): Promise<object> {
return this.agentServiceService.sumbitTransaction(payload.url, payload.apiKey, payload.submitEndorsementPayload);
}

@MessagePattern({ cmd: 'agent-out-of-band-credential-offer' })
async outOfBandCredentialOffer(payload: { outOfBandIssuancePayload: OutOfBandCredentialOffer, url: string, apiKey: string }): Promise<object> {
return this.agentServiceService.outOfBandCredentialOffer(payload.outOfBandIssuancePayload, payload.url, payload.apiKey);
}
}
38 changes: 25 additions & 13 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as dotenv from 'dotenv';
import * as fs from 'fs';
import { catchError, map } from 'rxjs/operators';
dotenv.config();
import { GetCredDefAgentRedirection, IAgentSpinupDto, IStoreOrgAgentDetails, ITenantCredDef, ITenantDto, ITenantSchema, IWalletProvision, ISendProofRequestPayload, IIssuanceCreateOffer } from './interface/agent-service.interface';
import { GetCredDefAgentRedirection, IAgentSpinupDto, IStoreOrgAgentDetails, ITenantCredDef, ITenantDto, ITenantSchema, IWalletProvision, ISendProofRequestPayload, IIssuanceCreateOffer, OutOfBandCredentialOffer } from './interface/agent-service.interface';
import { AgentType, OrgAgentType } from '@credebl/enum/enum';
import { IConnectionDetails, IUserRequestInterface } from './interface/agent-service.interface';
import { AgentServiceRepository } from './repositories/agent-service.repository';
Expand Down Expand Up @@ -133,7 +133,7 @@ export class AgentServiceService {

agentSpinupDto.agentType = agentSpinupDto.agentType ? agentSpinupDto.agentType : 1;
agentSpinupDto.tenant = agentSpinupDto.tenant ? agentSpinupDto.tenant : false;
agentSpinupDto.ledgerId = !agentSpinupDto.ledgerId || 0 === agentSpinupDto.ledgerId.length ? [3] : agentSpinupDto.ledgerId;
agentSpinupDto.ledgerId = !agentSpinupDto.ledgerId || 0 === agentSpinupDto.ledgerId?.length ? [3] : agentSpinupDto.ledgerId;


const platformConfig: platform_config = await this.agentServiceRepository.getPlatformConfigDetails();
Expand Down Expand Up @@ -289,7 +289,8 @@ export class AgentServiceService {
orgId: orgData.id,
walletName: agentSpinupDto.walletName,
clientSocketId: agentSpinupDto.clientSocketId,
ledgerId
ledgerId,
did: agentSpinupDto.did
};

if (agentEndPoint && agentSpinupDto.clientSocketId) {
Expand Down Expand Up @@ -338,21 +339,20 @@ export class AgentServiceService {


const agentDidWriteUrl = `${payload.agentEndPoint}${CommonConstants.URL_AGENT_WRITE_DID}`;
const { seed, ledgerId } = payload;
const { apiKey } = payload;
const { seed, ledgerId, did, apiKey } = payload;
const writeDid = 'write-did';
const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(ledgerId);
const agentDid = await this._retryAgentSpinup(agentDidWriteUrl, apiKey, writeDid, seed, ledgerDetails[0].indyNamespace);
const agentDid = await this._retryAgentSpinup(agentDidWriteUrl, apiKey, writeDid, seed, ledgerDetails[0].indyNamespace, did);
if (agentDid) {

const getDidMethodUrl = `${payload.agentEndPoint}${CommonConstants.URL_AGENT_GET_DIDS}`;
const getDidMethodUrl = `${payload.agentEndPoint}${CommonConstants.URL_AGENT_GET_DID}`.replace('#', agentDid['did']);
const getDidDic = 'get-did-doc';
const getDidMethod = await this._retryAgentSpinup(getDidMethodUrl, apiKey, getDidDic);


const storeOrgAgentData: IStoreOrgAgentDetails = {
did: getDidMethod[0]?.did,
verkey: getDidMethod[0]?.didDocument?.verificationMethod[0]?.publicKeyBase58,
did: getDidMethod['didDocument']?.id,
verkey: getDidMethod['didDocument']?.verificationMethod[0]?.publicKeyBase58,
isDidPublic: true,
agentSpinUpStatus: 2,
walletName: payload.walletName,
Expand Down Expand Up @@ -389,14 +389,14 @@ export class AgentServiceService {
}
}

async _retryAgentSpinup(agentUrl: string, apiKey: string, agentApiState: string, seed?: string, indyNamespace?: string): Promise<object> {
async _retryAgentSpinup(agentUrl: string, apiKey: string, agentApiState: string, seed?: string, indyNamespace?: string, did?: string): Promise<object> {
return retry(
async () => {

if ('write-did' === agentApiState) {

const agentDid = await this.commonService
.httpPost(agentUrl, { seed, method: indyNamespace }, { headers: { 'x-api-key': apiKey } })
.httpPost(agentUrl, { seed, method: indyNamespace, did: did ? did : undefined }, { headers: { 'x-api-key': apiKey } })
.then(async response => response);
return agentDid;
} else if ('get-did-doc' === agentApiState) {
Expand Down Expand Up @@ -487,7 +487,7 @@ export class AgentServiceService {
async _createTenant(payload: ITenantDto, user: IUserRequestInterface): Promise<void> {
try {

payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId.length ? [3] : payload.ledgerId;
payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId?.length ? [3] : payload.ledgerId;

const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(payload.ledgerId);
const sharedAgentSpinUpResponse = new Promise(async (resolve, _reject) => {
Expand Down Expand Up @@ -520,12 +520,13 @@ export class AgentServiceService {
let tenantDetails;
const url = `${platformAdminSpinnedUp.org_agents[0].agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_TENANT}`;
for (const iterator of ledgerDetails) {
const { label, seed } = payload;
const { label, seed, did } = payload;
const createTenantOptions = {
config: {
label
},
seed,
did: did ? did : undefined,
method: iterator.indyNamespace
};
const apiKey = '';
Expand Down Expand Up @@ -944,5 +945,16 @@ export class AgentServiceService {
}
}

async outOfBandCredentialOffer(outOfBandIssuancePayload: OutOfBandCredentialOffer, url: string, apiKey: string): Promise<object> {
try {
const sendOutOfbandCredentialOffer = await this.commonService
.httpPost(url, outOfBandIssuancePayload, { headers: { 'x-api-key': apiKey } })
.then(async response => response);
return sendOutOfbandCredentialOffer;
} catch (error) {
this.logger.error(`Error in out-of-band credential in agent service : ${JSON.stringify(error)}`);
throw new RpcException(error);
}
}
}

17 changes: 14 additions & 3 deletions apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@ export interface IAgentSpinupDto {
walletPassword: string;
seed: string;
orgId: number;
did?: string;
ledgerId?: number[];
agentType?: AgentType;
transactionApproval?: boolean;
clientSocketId?: string
tenant?: boolean;
}

export interface OutOfBandCredentialOffer {
emailId: string;
attributes: Attributes[];
credentialDefinitionId: string;
comment: string;
protocolVersion?: string;
orgId: number;
}

export interface ITenantDto {
label: string;
seed: string;
ledgerId?: number[];
method: string;
orgId: number;
did?: string;
ledgerId?: number[];
tenantId?: string;
clientSocketId?: string;
}
Expand Down Expand Up @@ -231,10 +242,10 @@ export interface ICredentialFormats {
}

export interface IIndy {
attributes: IAttributes[];
attributes: Attributes[];
}

export interface IAttributes {
export interface Attributes {
name: string;
value: string;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/api-gateway/src/agent-service/dto/agent-service.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class AgentSpinupDto {
@IsNotEmpty({ message: 'Password is required.' })
walletPassword: string;


@ApiProperty()
@Transform(({ value }) => trim(value))
@IsNotEmpty({ message: 'seed is required' })
Expand All @@ -35,6 +34,11 @@ export class AgentSpinupDto {
})
seed: string;

@ApiProperty()
@IsOptional()
@IsString({ message: 'did must be in string format.' })
did?: string;

@ApiProperty({ example: [1] })
@IsOptional()
@IsArray({ message: 'ledgerId must be an array' })
Expand Down
5 changes: 5 additions & 0 deletions apps/api-gateway/src/agent-service/dto/create-tenant.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export class CreateTenantDto {

orgId: number;

@ApiProperty()
@IsOptional()
@IsString({ message: 'did must be in string format.' })
did?: string;

@ApiProperty()
@IsOptional()
@ApiPropertyOptional()
Expand Down
33 changes: 4 additions & 29 deletions apps/api-gateway/src/authz/authz.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BadRequestException,
Body,
Controller,
Get,
Expand Down Expand Up @@ -83,37 +82,17 @@ export class AuthzController {
@Post('/signup')
@ApiOperation({ summary: 'Register new user to platform', description: 'Register new user to platform' })
async addUserDetails(@Body() userInfo: AddUserDetails, @Res() res: Response): Promise<Response> {
let finalResponse;
let userDetails;

if (false === userInfo.isPasskey) {

const decryptedPassword = this.commonService.decryptPassword(userInfo.password);
if (8 <= decryptedPassword.length && 50 >= decryptedPassword.length) {
this.commonService.passwordValidation(decryptedPassword);
userInfo.password = decryptedPassword;
userDetails = await this.authzService.addUserDetails(userInfo);
finalResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.user.success.create,
data: userDetails.response
};
} else {
throw new BadRequestException('Password name must be between 8 to 50 Characters');
}
} else {

userDetails = await this.authzService.addUserDetails(userInfo);
finalResponse = {
const userDetails = await this.authzService.addUserDetails(userInfo);
const finalResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.user.success.create,
data: userDetails.response
};
}
return res.status(HttpStatus.CREATED).json(finalResponse);

}


/**
*
* @param loginUserDto
Expand All @@ -130,11 +109,7 @@ export class AuthzController {
async login(@Body() loginUserDto: LoginUserDto, @Res() res: Response): Promise<Response> {

if (loginUserDto.email) {
let decryptedPassword;
if (loginUserDto.password) {
decryptedPassword = this.commonService.decryptPassword(loginUserDto.password);
}
const userData = await this.authzService.login(loginUserDto.email, decryptedPassword, loginUserDto.isPasskey);
const userData = await this.authzService.login(loginUserDto.email, loginUserDto.password, loginUserDto.isPasskey);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.login,
Expand Down
15 changes: 15 additions & 0 deletions apps/api-gateway/src/authz/guards/org-roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ export class OrgRolesGuard implements CanActivate {
}
});

} else if (requiredRolesNames.includes(OrgRoles.PLATFORM_ADMIN)) {

// eslint-disable-next-line array-callback-return
const isPlatformAdmin = user.userOrgRoles.find((orgDetails) => {
if (orgDetails.orgRole.name === OrgRoles.PLATFORM_ADMIN) {
return true;
}
});

if (isPlatformAdmin) {
return true;
}

return false;

} else {
throw new HttpException('organization is required', HttpStatus.BAD_REQUEST);
}
Expand Down
25 changes: 0 additions & 25 deletions apps/api-gateway/src/config/multer.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/api-gateway/src/connection/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class ConnectionController {
@Post('/orgs/:orgId/connections')
@ApiOperation({ summary: 'Create outbound out-of-band connection (Legacy Invitation)', description: 'Create outbound out-of-band connection (Legacy Invitation)' })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER)
@ApiResponse({ status: 201, description: 'Success', type: AuthTokenResponse })
async createLegacyConnectionInvitation(
@Param('orgId') orgId: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,25 @@ export class CredentialDefinitionController {
};
return res.status(HttpStatus.CREATED).json(credDefResponse);
}

@Get('/orgs/:orgId/bulk/cred-defs')
@ApiOperation({
summary: 'Fetch all credential definition for bulk opeartion',
description: 'Fetch all credential definition from metadata saved in database for bulk opeartion.'
})
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
async getAllCredDefAndSchemaForBulkOperation(
@Param('orgId') orgId: number,
@Res() res: Response
): Promise<object> {
const credentialsDefinitionDetails = await this.credentialDefinitionService.getAllCredDefAndSchemaForBulkOperation(orgId);
const credDefResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.credentialDefinition.success.fetch,
data: credentialsDefinitionDetails.response
};
return res.status(HttpStatus.CREATED).json(credDefResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export class CredentialDefinitionService extends BaseService {
const payload = { schemaId };
return this.sendNats(this.credDefServiceProxy, 'get-all-credential-definitions-by-schema-id', payload);
}

getAllCredDefAndSchemaForBulkOperation(orgId:number): Promise<{ response: object }> {
const payload = { orgId };
return this.sendNats(this.credDefServiceProxy, 'get-all-schema-cred-defs-for-bulk-operation', payload);
}
}
Loading

0 comments on commit c569293

Please sign in to comment.