diff --git a/admin_frontend/package.json b/admin_frontend/package.json index a87ffa3..90184df 100644 --- a/admin_frontend/package.json +++ b/admin_frontend/package.json @@ -1,6 +1,6 @@ { "name": "admin_frontend", - "version": "1.2.9", + "version": "1.3.0", "private": true, "dependencies": { "@emotion/react": "11.11.3", diff --git a/backend/package.json b/backend/package.json index b7e6c1d..a56129e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "1.2.9", + "version": "1.3.0", "description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software", "type": "module", "directories": { diff --git a/backend/src/constants/ErrorMessage.ts b/backend/src/constants/ErrorMessage.ts index 92f9c29..3f8226a 100644 --- a/backend/src/constants/ErrorMessage.ts +++ b/backend/src/constants/ErrorMessage.ts @@ -3,6 +3,7 @@ export default { INVALID_SPONSORSHIP_POLICY: 'Invalid sponsorship policy data', INVALID_SPONSORSHIP_POLICY_ID: 'Invalid sponsorship policy id', INVALID_API_KEY: 'Invalid Api Key', + API_KEY_NOT_CONFIGURED_IN_DATABASE: 'Api Key not configured in database', UNSUPPORTED_NETWORK: 'Unsupported network', UNSUPPORTED_NETWORK_TOKEN: 'Unsupported network/token', EMPTY_BODY: 'Empty Body received', diff --git a/backend/src/routes/paymaster-routes.ts b/backend/src/routes/paymaster-routes.ts index 5667ffc..564ea15 100644 --- a/backend/src/routes/paymaster-routes.ts +++ b/backend/src/routes/paymaster-routes.ts @@ -128,8 +128,8 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => { const apiKeyEntity = await server.apiKeyRepository.findOneByApiKey(api_key); if (!apiKeyEntity) { - server.log.error("Invalid Api Key provided") - return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }) + server.log.error("APIKey not configured in database") + return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_NOT_CONFIGURED_IN_DATABASE }) } if (apiKeyEntity.erc20Paymasters) { @@ -197,7 +197,7 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => { // get wallet_address from api_key const apiKeyData = await server.apiKeyRepository.findOneByApiKey(api_key); - if (!apiKeyData) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY }); + if (!apiKeyData) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_NOT_CONFIGURED_IN_DATABASE }); // get sponsorshipPolicy for the user from walletAddress and entrypoint version const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersion(apiKeyData?.walletAddress, getEPVersion(epVersion)); @@ -215,9 +215,6 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => { const supportedNetworks: number[] | undefined | null = sponsorshipPolicy.enabledChains; if (!supportedNetworks || !supportedNetworks.includes(chainId.chainId)) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); - // is chainId exists in supportedNetworks - if (!supportedNetworks.includes(chainId.chainId)) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); - if (txnMode) { const signerAddress = await signer.getAddress(); const IndexerData = await getIndexerData(signerAddress, userOp.sender, date.getMonth(), date.getFullYear(), noOfTxns, indexerEndpoint); diff --git a/backend/src/routes/sponsorship-policy-routes.ts b/backend/src/routes/sponsorship-policy-routes.ts index fff733e..356da4c 100644 --- a/backend/src/routes/sponsorship-policy-routes.ts +++ b/backend/src/routes/sponsorship-policy-routes.ts @@ -4,7 +4,7 @@ import ErrorMessage, { generateErrorMessage } from "../constants/ErrorMessage.js import ReturnCode from "../constants/ReturnCode.js"; import { SponsorshipPolicyDto, getEPVersion } from "../types/sponsorship-policy-dto.js"; import { SponsorshipPolicy } from "../models/sponsorship-policy.js"; -import { getChainIdsFromSupportedNetworks } from "../utils/common.js"; +import { getChainIdsFromDefaultSupportedNetworks, getChainIdsFromSupportedNetworks } from "../utils/common.js"; interface RouteParams { id?: string; @@ -262,21 +262,25 @@ const sponsorshipPolicyRoutes: FastifyPluginAsync = async (server) => { // apiKey has supportedNetworks and validate if the enabledChains array in SponsorshipPolicyDto is a subset of supportedNetworks const supportedNetworks = apiKey.supportedNetworks; - if (!supportedNetworks) { + + // get supportedNetworks from defaultConfig + const supportedChains: number[] = supportedNetworks ? getChainIdsFromSupportedNetworks(supportedNetworks as string) : getChainIdsFromDefaultSupportedNetworks(); + + if (!supportedChains || supportedChains.length === 0) { return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK }); } - const apiKeySupportedChains: number[] = getChainIdsFromSupportedNetworks(supportedNetworks as string); + const sponsorshipPolicySupportedChains = sponsorshipPolicyDto.enabledChains; - if (sponsorshipPolicySupportedChains && sponsorshipPolicySupportedChains.length > 0) { + if (!sponsorshipPolicyDto.isApplicableToAllNetworks && sponsorshipPolicySupportedChains && sponsorshipPolicySupportedChains.length > 0) { - if (!sponsorshipPolicySupportedChains.every((chainId: number) => sponsorshipPolicySupportedChains.includes(chainId))) { + if (!sponsorshipPolicySupportedChains.every((chainId: number) => supportedChains.includes(chainId))) { //generate a comma separate string of sponsorshipPolicySupportedChains const sponsorshipPolicySupportedChainsCSV: string = sponsorshipPolicySupportedChains.join(','); //generate a comma separated string of apiKeySupportedChains - const apiKeySupportedChainsCSV: string = apiKeySupportedChains.join(','); + const apiKeySupportedChainsCSV: string = supportedChains.join(','); const errorMessage: string = generateErrorMessage(ErrorMessage.SPONSORSHIP_POLICY_CHAINS_NOT_IN_SUBSET_OF_APIKEY_SUPPORTED_CHAINS, { sponsorshipPolicyChains: sponsorshipPolicySupportedChainsCSV, apiKeyChains: apiKeySupportedChainsCSV }); return reply.code(ReturnCode.FAILURE).send({ error: errorMessage }); diff --git a/backend/src/utils/common.ts b/backend/src/utils/common.ts index 5a529f9..f1de5eb 100644 --- a/backend/src/utils/common.ts +++ b/backend/src/utils/common.ts @@ -18,6 +18,10 @@ export function getNetworkConfig(key: any, supportedNetworks: any, entryPoint: s return SupportedNetworks.find((chain) => chain.chainId == key && chain.entryPoint == entryPoint); } +export function getChainIdsFromDefaultSupportedNetworks() { + return SupportedNetworks.map((chain) => chain.chainId); +} + export function decodeSupportedNetworks(supportedNetworksForDecode: string) { const buffer = Buffer.from(supportedNetworksForDecode, "base64"); return JSON.parse(buffer.toString()); diff --git a/frontend/package.json b/frontend/package.json index a91bd06..f1eaa32 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "arka_frontend", - "version": "1.2.9", + "version": "1.3.0", "private": true, "dependencies": { "@babel/plugin-proposal-private-property-in-object": "7.21.11",