Skip to content

Commit

Permalink
chore: fix timestamp validation logging (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
aditiharini authored Oct 28, 2024
1 parent 472b8e0 commit e4416c2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ export async function validateTransfer(req: TransferRequest, db: Kysely<Database
throw new ValidationError('TOO_MANY_NAMES');
}

if (req.timestamp > currentTimestamp() + TIMESTAMP_TOLERANCE) {
log.error(`Timestamp ${req.timestamp} was > ${TIMESTAMP_TOLERANCE}`);
const maxAcceptableTimestamp = currentTimestamp() + TIMESTAMP_TOLERANCE;
if (req.timestamp > maxAcceptableTimestamp) {
log.error(`Timestamp ${req.timestamp} was > ${maxAcceptableTimestamp}`);
throw new ValidationError('INVALID_TIMESTAMP');
}

if (req.timestamp < currentTimestamp() - TIMESTAMP_TOLERANCE) {
log.error(`Timestamp ${req.timestamp} was < ${TIMESTAMP_TOLERANCE}`);
const minAcceptableTimestamp = currentTimestamp() - TIMESTAMP_TOLERANCE;
if (req.timestamp < minAcceptableTimestamp) {
log.error(`Timestamp ${req.timestamp} was < ${minAcceptableTimestamp}`);
throw new ValidationError('INVALID_TIMESTAMP');
}

Expand Down

0 comments on commit e4416c2

Please sign in to comment.