From d25d66129b17ae715df0d248f56b4ef8d86b72d0 Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Wed, 6 Aug 2025 23:38:16 +0530 Subject: [PATCH 1/6] fix: schema by id Signed-off-by: Tipu_Singh --- .../src/agent-service.service.ts | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index d0838048b..7128637a4 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -1251,27 +1251,14 @@ export class AgentServiceService { async getSchemaById(payload: GetSchemaAgentRedirection): Promise { try { - let schemaResponse; - const getApiKey = await this.getOrgAgentApiKey(payload.orgId); - if (OrgAgentType.DEDICATED === payload.agentType) { - const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID.replace( - '#', - `${payload.schemaId}` - )}`; - schemaResponse = await this.commonService - .httpGet(url, { headers: { authorization: getApiKey } }) - .then(async (schema) => schema); - } else if (OrgAgentType.SHARED === payload.agentType) { - const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID}`.replace( - '#', - `${payload.tenantId}` - ); - - schemaResponse = await this.commonService - .httpGet(url, { headers: { authorization: getApiKey } }) - .then(async (schema) => schema); - } + const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID.replace( + '#', + `${payload.schemaId}` + )}`; + const schemaResponse = await this.commonService + .httpGet(url, { headers: { authorization: getApiKey } }) + .then(async (schema) => schema); return schemaResponse; } catch (error) { this.logger.error(`Error in getting schema: ${error}`); From 4bb20ae23a79017a67e0cf24719808253cd8ea9b Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Thu, 7 Aug 2025 00:09:20 +0530 Subject: [PATCH 2/6] fix: schema by id Signed-off-by: Tipu_Singh --- .../src/agent-service.service.ts | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index 7128637a4..b1daa0053 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -1251,14 +1251,27 @@ export class AgentServiceService { async getSchemaById(payload: GetSchemaAgentRedirection): Promise { try { + let schemaResponse; + const getApiKey = await this.getOrgAgentApiKey(payload.orgId); - const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID.replace( - '#', - `${payload.schemaId}` - )}`; - const schemaResponse = await this.commonService - .httpGet(url, { headers: { authorization: getApiKey } }) - .then(async (schema) => schema); + if (OrgAgentType.DEDICATED === payload.agentType) { + const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID.replace( + '#', + `${payload.schemaId}` + )}`; + schemaResponse = await this.commonService + .httpGet(url, { headers: { authorization: getApiKey } }) + .then(async (schema) => schema); + } else if (OrgAgentType.SHARED === payload.agentType) { + const url = `${payload.agentEndPoint}${CommonConstants.URL_SCHM_GET_SCHEMA_BY_ID}`.replace( + '#', + `${payload.payload.schemaId}` + ); + + schemaResponse = await this.commonService + .httpGet(url, { headers: { authorization: getApiKey } }) + .then(async (schema) => schema); + } return schemaResponse; } catch (error) { this.logger.error(`Error in getting schema: ${error}`); From ad6719e98b2c9994512f8fe36f3f6b4be4758d38 Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Thu, 7 Aug 2025 12:35:22 +0530 Subject: [PATCH 3/6] fix: duplicate URL creation Signed-off-by: Tipu_Singh --- .../src/agent-service.service.ts | 16 +++++------ libs/common/src/common.service.ts | 27 ++++++++++++------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index b1daa0053..e0eafeb57 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -1047,17 +1047,15 @@ export class AgentServiceService { */ async createSecp256k1KeyPair(orgId: string): Promise { 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, {}, diff --git a/libs/common/src/common.service.ts b/libs/common/src/common.service.ts index 7650f043d..251e36cdb 100644 --- a/libs/common/src/common.service.ts +++ b/libs/common/src/common.service.ts @@ -311,16 +311,14 @@ export class CommonService { } async getBaseAgentToken(agentEndPoint: string, apiKey: string): Promise { - const agentBaseWalletDetils = await this.httpPost( - `${process.env.API_GATEWAY_PROTOCOL}://${agentEndPoint}${CommonConstants.URL_AGENT_TOKEN}`, - '', - { - headers: { - Accept: 'application/json', - Authorization: apiKey - } + const normalizedBaseUrl = 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); } @@ -328,8 +326,10 @@ export class CommonService { } async getTenantWalletToken(agentEndPoint: string, apiKey: string, tenantId: string): Promise { + const normalizedBaseUrl = 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: { @@ -343,4 +343,11 @@ export class CommonService { } return tenantWalletDetails.token; } + + async normalizeUrlWithProtocol(baseUrl: string): Promise { + if (baseUrl.startsWith('http://') || baseUrl.startsWith('https://')) { + return baseUrl; + } + return `${process.env.API_GATEWAY_PROTOCOL}://${baseUrl}`; + } } From 46f0e51233ffb691ed0fa82b96862f38ad6244b2 Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Thu, 7 Aug 2025 12:59:20 +0530 Subject: [PATCH 4/6] fix: added await in common method Signed-off-by: Tipu_Singh --- libs/common/src/common.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/common/src/common.service.ts b/libs/common/src/common.service.ts index 251e36cdb..7d031b7a5 100644 --- a/libs/common/src/common.service.ts +++ b/libs/common/src/common.service.ts @@ -311,7 +311,7 @@ export class CommonService { } async getBaseAgentToken(agentEndPoint: string, apiKey: string): Promise { - const normalizedBaseUrl = this.normalizeUrlWithProtocol(agentEndPoint); + 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: { @@ -326,7 +326,7 @@ export class CommonService { } async getTenantWalletToken(agentEndPoint: string, apiKey: string, tenantId: string): Promise { - const normalizedBaseUrl = this.normalizeUrlWithProtocol(agentEndPoint); + const normalizedBaseUrl = await this.normalizeUrlWithProtocol(agentEndPoint); this.logger.log(`Fetching tenant wallet token for tenantId: ${tenantId} from ${normalizedBaseUrl}`); const tenantWalletDetails = await this.httpPost( `${normalizedBaseUrl}${CommonConstants.URL_SHARED_WALLET_TOKEN}${tenantId}`, From 0528f7e40e955f6dbe4828edee6fd4f7feb7f9ef Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Thu, 7 Aug 2025 13:19:04 +0530 Subject: [PATCH 5/6] fix: added logic for get token Signed-off-by: Tipu_Singh --- apps/agent-service/src/agent-service.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/agent-service/src/agent-service.service.ts b/apps/agent-service/src/agent-service.service.ts index e0eafeb57..ae092b204 100644 --- a/apps/agent-service/src/agent-service.service.ts +++ b/apps/agent-service/src/agent-service.service.ts @@ -1879,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 }; From 9403864f6d1fdb3b1d51d75a0a3eb998049a1fd6 Mon Sep 17 00:00:00 2001 From: Tipu_Singh Date: Thu, 7 Aug 2025 15:01:08 +0530 Subject: [PATCH 6/6] fix: polygon routes Signed-off-by: Tipu_Singh --- apps/ledger/src/schema/schema.service.ts | 12 +----------- libs/common/src/common.constant.ts | 3 +-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/apps/ledger/src/schema/schema.service.ts b/apps/ledger/src/schema/schema.service.ts index a640cbc23..f3f7bd5a2 100644 --- a/apps/ledger/src/schema/schema.service.ts +++ b/apps/ledger/src/schema/schema.service.ts @@ -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, { diff --git a/libs/common/src/common.constant.ts b/libs/common/src/common.constant.ts index 4925f4b01..dd282e009 100644 --- a/libs/common/src/common.constant.ts +++ b/libs/common/src/common.constant.ts @@ -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',