Skip to content

Commit

Permalink
ft: adding get functionalities models
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilkumar1612 committed Nov 29, 2024
1 parent dc96ec9 commit 57975e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
6 changes: 5 additions & 1 deletion backend/src/models/contract-whitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export function initializeContractWhitelistModel(sequelize: Sequelize, schema: s
chainId: {
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
6 changes: 5 additions & 1 deletion backend/src/models/sponsorship-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export function initializeSponsorshipPolicyModel(sequelize: Sequelize, schema: s
enabledChains: {
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 57975e2

Please sign in to comment.