Skip to content

Commit

Permalink
ft: change data type change for chainid (#150)
Browse files Browse the repository at this point in the history
* ft: change data type change for chainid

* ft: adding get functionalities models

* update: package.json version update
  • Loading branch information
nikhilkumar1612 authored Dec 3, 2024
1 parent 1b02c76 commit 2b7bbc4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
45 changes: 45 additions & 0 deletions backend/migrations/20241126170930-change-chain-id-to-bigint.cjs
Original file line number Diff line number Diff line change
@@ -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};
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions backend/src/models/contract-whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions backend/src/models/sponsorship-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/repository/sponsorship-policy-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SponsorshipPolicyRepository {
]
}
});
return result.map(apiKey => apiKey as SponsorshipPolicy);
return result.map(apiKey => apiKey.get() as SponsorshipPolicy);
}

// findAllEnabled
Expand Down
6 changes: 0 additions & 6 deletions backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
4 changes: 0 additions & 4 deletions backend/src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ 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
) {
return false;
}
const computedSignature = createDigest(data + timestamp, 'hex', hmacSecret);
server.log.info(`-----------computedSignature----------${computedSignature}`);
server.log.info(`-----------signature----------${signature} ${computedSignature === signature}`);
return signature === computedSignature;
}

0 comments on commit 2b7bbc4

Please sign in to comment.