diff --git a/backend/migrations/20241126170930-change-chain-id-to-bigint.cjs b/backend/migrations/20241126170930-change-chain-id-to-bigint.cjs new file mode 100644 index 0000000..0192843 --- /dev/null +++ b/backend/migrations/20241126170930-change-chain-id-to-bigint.cjs @@ -0,0 +1,45 @@ +require('dotenv').config(); +const { DataTypes } = require('sequelize'); + +async function up({ context: queryInterface }) { + await queryInterface.changeColumn( + {schema: process.env.DATABASE_SCHEMA_NAME, tableName: 'sponsorship_policies'}, + 'ENABLED_CHAINS', + { + type: DataTypes.ARRAY(DataTypes.BIGINT), + allowNull: true + } + ); + + await queryInterface.changeColumn( + {schema: process.env.DATABASE_SCHEMA_NAME, tableName: 'contract_whitelist'}, + 'CHAIN_ID', + { + type: DataTypes.BIGINT, + allowNull: false + } + ); +} + +async function down({ context: queryInterface }) { + await queryInterface.changeColumn( + {schema: process.env.DATABASE_SCHEMA_NAME, tableName: 'sponsorship_policies'}, + 'ENABLED_CHAINS', + { + type: DataTypes.ARRAY(DataTypes.INTEGER), + allowNull: true + } + ); + + await queryInterface.changeColumn( + {schema: process.env.DATABASE_SCHEMA_NAME, tableName: 'contract_whitelist'}, + 'CHAIN_ID', + { + type: DataTypes.INTEGER, + allowNull: false + } + ); +} + +/** @type {import('sequelize-cli').Migration} */ +module.exports = {up, down}; diff --git a/backend/package.json b/backend/package.json index a5d2855..df7a224 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "1.6.8", + "version": "1.6.9", "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/models/contract-whitelist.ts b/backend/src/models/contract-whitelist.ts index 89d3e74..f3b5ce4 100644 --- a/backend/src/models/contract-whitelist.ts +++ b/backend/src/models/contract-whitelist.ts @@ -40,9 +40,13 @@ export function initializeContractWhitelistModel(sequelize: Sequelize, schema: s field: 'ABI' }, chainId: { - type: DataTypes.INTEGER, + type: DataTypes.BIGINT, allowNull: false, - field: 'CHAIN_ID' + field: 'CHAIN_ID', + get() { + const value = this.getDataValue('chainId'); + return +value; + } }, createdAt: { type: DataTypes.DATE, diff --git a/backend/src/models/sponsorship-policy.ts b/backend/src/models/sponsorship-policy.ts index a58ae9c..79c3f91 100644 --- a/backend/src/models/sponsorship-policy.ts +++ b/backend/src/models/sponsorship-policy.ts @@ -112,9 +112,13 @@ export function initializeSponsorshipPolicyModel(sequelize: Sequelize, schema: s field: 'IS_APPLICABLE_TO_ALL_NETWORKS' }, enabledChains: { - type: DataTypes.ARRAY(DataTypes.INTEGER), + type: DataTypes.ARRAY(DataTypes.BIGINT), allowNull: true, - field: 'ENABLED_CHAINS' + field: 'ENABLED_CHAINS', + get() { + const value = this.getDataValue('enabledChains'); + return value?.map((item: any) => +item); + } }, supportedEPVersions: { type: DataTypes.ARRAY(DataTypes.STRING), diff --git a/backend/src/repository/sponsorship-policy-repository.ts b/backend/src/repository/sponsorship-policy-repository.ts index 10159b0..f2f4ac7 100644 --- a/backend/src/repository/sponsorship-policy-repository.ts +++ b/backend/src/repository/sponsorship-policy-repository.ts @@ -39,7 +39,7 @@ export class SponsorshipPolicyRepository { ] } }); - return result.map(apiKey => apiKey as SponsorshipPolicy); + return result.map(apiKey => apiKey.get() as SponsorshipPolicy); } // findAllEnabled diff --git a/backend/src/routes/admin-routes.ts b/backend/src/routes/admin-routes.ts index 6b6ded3..11ef7e9 100644 --- a/backend/src/routes/admin-routes.ts +++ b/backend/src/routes/admin-routes.ts @@ -107,14 +107,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => { const privateKey = wallet.privateKey; const publicAddress = await wallet.getAddress(); - request.log.info(`-----------headers---------- ${JSON.stringify(request.headers)}`); - request.log.info(`-----------hmac secret---------- ${server.config.HMAC_SECRET}`); - - if(!unsafeMode) { const { 'x-signature': signature, 'x-timestamp': timestamp } = request.headers as IncomingHttpHeaders & AuthDto; - request.log.info(`-----------signature---------- ${signature}`); - request.log.info(`-----------timestamp---------- ${timestamp}`); if(!signature || !timestamp) return reply.code(ReturnCode.NOT_AUTHORIZED).send({ error: ErrorMessage.INVALID_SIGNATURE_OR_TIMESTAMP }); diff --git a/backend/src/utils/crypto.ts b/backend/src/utils/crypto.ts index 4a26e21..a52ef3e 100644 --- a/backend/src/utils/crypto.ts +++ b/backend/src/utils/crypto.ts @@ -66,8 +66,6 @@ export async function decodeSafe(value: string, hmacSecret: string) { export function verifySignature(signature: string, data: string, timestamp: string, hmacSecret: string) { // unauthorize signature if signed before 10s or signed in future. const now = Date.now(); - server.log.info(`-----------now---------- ${now}`); - server.log.info(`-----------hmacSecret---------- ${hmacSecret}`); if( now < parseInt(timestamp) || now - parseInt(timestamp) > 10000 @@ -75,7 +73,5 @@ export function verifySignature(signature: string, data: string, timestamp: stri return false; } const computedSignature = createDigest(data + timestamp, 'hex', hmacSecret); - server.log.info(`-----------computedSignature----------${computedSignature}`); - server.log.info(`-----------signature----------${signature} ${computedSignature === signature}`); return signature === computedSignature; }