Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const createServer = (): express.Application => {
})
app.use('/health', healthRoutes)
app.use('/api', validateRoutes)
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
return app
}

Expand Down
64 changes: 32 additions & 32 deletions controller/validate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const controller = {
domain,
payload,
version,
flow.toString(),
flow,
bap_id,
bpp_id,
)
Expand Down Expand Up @@ -95,22 +95,22 @@ const controller = {

validateToken: async (req: Request, res: Response): Promise<Response | void> => {
try {
const { success, response, signature, signTimestamp } = req.body;
const { success, response, signature, signTimestamp } = req.body

// Validate required fields exist
if (
signature === undefined ||
signTimestamp === undefined ||
response === undefined ||
signature === undefined ||
signTimestamp === undefined ||
response === undefined ||
success === undefined ||
response.payload === undefined // Check payload inside response
response.payload === undefined // Check payload inside response
) {
throw new Error('Payload must contain: signature, signTimestamp, success, response (with payload)');
throw new Error('Payload must contain: signature, signTimestamp, success, response (with payload)')
}

const publicKey = process.env.SIGN_PUBLIC_KEY as string;
const publicKey = process.env.SIGN_PUBLIC_KEY as string
if (!publicKey) {
throw new Error('Server configuration error: SIGN_PUBLIC_KEY not set');
throw new Error('Server configuration error: SIGN_PUBLIC_KEY not set')
}

// Create httpResponse from the response object
Expand All @@ -120,34 +120,34 @@ const controller = {
bpp_id: response.bpp_id,
bap_id: response.bap_id,
domain: response.domain,
payload: response.payload, // Get payload from response
payload: response.payload, // Get payload from response
reportTimestamp: response.reportTimestamp,
};
}

const hashString = await hash({ message: JSON.stringify(httpResponse) });
const signingString = `${hashString}|${signTimestamp}`;
const hashString = await hash({ message: JSON.stringify(httpResponse) })
const signingString = `${hashString}|${signTimestamp}`

const isVerified = await verify({
signedMessage: signature,
message: signingString,
publicKey
});
const isVerified = await verify({
signedMessage: signature,
message: signingString,
publicKey,
})

return res.status(200).send({
success: true,
response: {
return res.status(200).send({
success: true,
response: {
message: isVerified ? 'Signature verification successful' : 'Invalid signature',
verified: isVerified
}
});
verified: isVerified,
},
})
} catch (error: any) {
logger.error('Signature verification failed:', error);
return res.status(400).send({
success: false,
response: {
message: error?.message || 'Signature verification failed'
}
});
logger.error('Signature verification failed:', error)
return res.status(400).send({
success: false,
response: {
message: error?.message || 'Signature verification failed',
},
})
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"libsodium-wrappers": "^0.7.13",
"lmdb": "^2.9.2",
"lodash": "^4.17.21",
"ngrok": "^5.0.0-beta.2",
"pino": "^7.6.4",
"swagger-autogen": "^2.23.7",
"swagger-jsdoc": "^6.2.8",
Expand All @@ -71,6 +70,7 @@
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-security": "^1.4.0",
"jest": "^27.5.1",
"ngrok": "^5.0.0-beta.2",
"nodemon": "^2.0.15",
"pino-pretty": "^7.5.0",
"supertest": "^6.2.2",
Expand Down
Loading