Skip to content
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
20 changes: 9 additions & 11 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,17 +1047,15 @@ export class AgentServiceService {
*/
async createSecp256k1KeyPair(orgId: string): Promise<object> {
try {
const orgAgentDetails = await this.agentServiceRepository.getAgentApiKey(orgId);
if (!orgAgentDetails) {
throw new NotFoundException(ResponseMessages.agent.error.orgAgentNotFound, {
cause: new Error(),
description: ResponseMessages.errorMessages.notFound
});
}
const getDcryptedToken = await this.commonService.decryptPassword(orgAgentDetails.apiKey);
const platformAdminSpinnedUp = await this.agentServiceRepository.platformAdminAgent(
CommonConstants.PLATFORM_ADMIN_ORG
);

const url = `${orgAgentDetails.agentEndPoint}${CommonConstants.CREATE_POLYGON_SECP256k1_KEY}`;
const getPlatformAgentEndPoint = platformAdminSpinnedUp.org_agents[0].agentEndPoint;
const getDcryptedToken = await this.commonService.decryptPassword(platformAdminSpinnedUp?.org_agents[0].apiKey);

const url = `${getPlatformAgentEndPoint}${CommonConstants.CREATE_POLYGON_SECP256k1_KEY}`;
this.logger.log(`Creating Secp256k1 key pair at URL: ${url}`);
const createKeyPairResponse = await this.commonService.httpPost(
url,
{},
Expand Down Expand Up @@ -1265,7 +1263,7 @@ export class AgentServiceService {
} else if (OrgAgentType.SHARED === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID}`.replace(
'#',
`${payload.tenantId}`
`${payload.payload.schemaId}`
);

schemaResponse = await this.commonService
Expand Down Expand Up @@ -1881,7 +1879,7 @@ export class AgentServiceService {
}
const walletDetails: WalletDetails = {
agentEndPoint: platformAdminSpinnedUp.org_agents[0]?.agentEndPoint,
apiKey: platformAdminSpinnedUp.org_agents[0]?.apiKey,
apiKey: await this.commonService.decryptPassword(platformAdminSpinnedUp.org_agents[0]?.apiKey),
tenantId: orgAgentDetails.tenantId,
orgId: orgAgentDetails.orgId
};
Expand Down
12 changes: 1 addition & 11 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,7 @@ export class SchemaService extends BaseService {
description: ResponseMessages.errorMessages.badRequest
});
}

const getAgentDetails = await this.schemaRepository.getAgentType(orgId);
const orgAgentType = await this.schemaRepository.getOrgAgentType(getAgentDetails.org_agents[0].orgAgentTypeId);
let url;
if (OrgAgentType.DEDICATED === orgAgentType) {
url = `${agentEndPoint}${CommonConstants.DEDICATED_CREATE_POLYGON_W3C_SCHEMA}`;
} else if (OrgAgentType.SHARED === orgAgentType) {
const { tenantId } = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
url = `${agentEndPoint}${CommonConstants.SHARED_CREATE_POLYGON_W3C_SCHEMA}${tenantId}`;
}

const url = `${agentEndPoint}${CommonConstants.CREATE_POLYGON_W3C_SCHEMA}`;
const schemaObject = await w3cSchemaBuilder(attributes, schemaName, description);
if (!schemaObject) {
throw new BadRequestException(ResponseMessages.schema.error.schemaBuilder, {
Expand Down
3 changes: 1 addition & 2 deletions libs/common/src/common.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ export enum CommonConstants {
URL_SCHM_GET_CRED_DEF_BY_ID = '/anoncreds/credential-definitions/#',

// POLYGON BASED W3C SCHEMAS
DEDICATED_CREATE_POLYGON_W3C_SCHEMA = '/polygon/create-schema',
SHARED_CREATE_POLYGON_W3C_SCHEMA = '/multi-tenancy/polygon-w3c/schema/',
CREATE_POLYGON_W3C_SCHEMA = '/polygon/create-schema',

// SHARED AGENT
URL_SHAGENT_CREATE_TENANT = '/multi-tenancy/create-tenant',
Expand Down
27 changes: 17 additions & 10 deletions libs/common/src/common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,25 @@ export class CommonService {
}

async getBaseAgentToken(agentEndPoint: string, apiKey: string): Promise<string> {
const agentBaseWalletDetils = await this.httpPost(
`${process.env.API_GATEWAY_PROTOCOL}://${agentEndPoint}${CommonConstants.URL_AGENT_TOKEN}`,
'',
{
headers: {
Accept: 'application/json',
Authorization: apiKey
}
const normalizedBaseUrl = await this.normalizeUrlWithProtocol(agentEndPoint);
this.logger.log(`Fetching base agent token from ${normalizedBaseUrl}`);
const agentBaseWalletDetils = await this.httpPost(`${normalizedBaseUrl}${CommonConstants.URL_AGENT_TOKEN}`, '', {
headers: {
Accept: 'application/json',
Authorization: apiKey
}
);
});
if (!agentBaseWalletDetils) {
throw new NotFoundException(ResponseMessages.common.error.fetchBaseWalletToken);
}
return agentBaseWalletDetils.token;
}

async getTenantWalletToken(agentEndPoint: string, apiKey: string, tenantId: string): Promise<string> {
const normalizedBaseUrl = await this.normalizeUrlWithProtocol(agentEndPoint);
this.logger.log(`Fetching tenant wallet token for tenantId: ${tenantId} from ${normalizedBaseUrl}`);
const tenantWalletDetails = await this.httpPost(
`${process.env.API_GATEWAY_PROTOCOL}://${agentEndPoint}${CommonConstants.URL_SHARED_WALLET_TOKEN}${tenantId}`,
`${normalizedBaseUrl}${CommonConstants.URL_SHARED_WALLET_TOKEN}${tenantId}`,
{},
{
headers: {
Expand All @@ -343,4 +343,11 @@ export class CommonService {
}
return tenantWalletDetails.token;
}

async normalizeUrlWithProtocol(baseUrl: string): Promise<string> {
if (baseUrl.startsWith('http://') || baseUrl.startsWith('https://')) {
return baseUrl;
}
return `${process.env.API_GATEWAY_PROTOCOL}://${baseUrl}`;
}
}