Skip to content

Commit

Permalink
changing console.log to logger, package.json version change
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilkumar1612 committed Nov 21, 2024
1 parent 4f65235 commit 360a27d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
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.7",
"version": "1.6.8",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
const privateKey = wallet.privateKey;
const publicAddress = await wallet.getAddress();

console.log("-----------headers----------", request.headers);
console.log("-----------hmac secret----------", server.config.HMAC_SECRET);
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;
console.log("-----------signature----------", signature);
console.log("-----------timestamp----------", timestamp);
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
9 changes: 5 additions & 4 deletions backend/src/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto, { BinaryToTextEncoding } from 'crypto';
import { KmsKeyringNode, buildClient, CommitmentPolicy } from '@aws-crypto/client-node';
import { server } from 'server';

function createDigest(encodedData: string, format: BinaryToTextEncoding, hmacSecret: string) {
return crypto
Expand Down Expand Up @@ -65,16 +66,16 @@ 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();
console.log("-----------now----------", now);
console.log("-----------hmacSecret----------", hmacSecret);
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);
console.log("-----------computedSignature----------", computedSignature);
console.log("-----------signature----------", signature, computedSignature===signature);
server.log.info(`-----------computedSignature----------${computedSignature}`);
server.log.info(`-----------signature----------${signature} ${computedSignature === signature}`);
return signature === computedSignature;
}

0 comments on commit 360a27d

Please sign in to comment.