validateTimestamp
import { validateTimestamp } from '@kairo-js/utils'
Validates a message timestamp against the current tick. Throws the appropriate error if the timestamp has exceeded its timeout window or if the timestamp is set in the future relative to the current tick.
function validateTimestamp(
currentTick: number,
timestamp: number,
timeout: number,
onTimeout: () => Error,
onFuture: () => Error,
): voidParameters
currentTick:
numberThe current tick count, typically obtained from
router.currentTick.timestamp:
numberThe tick value recorded when the message or event was created.
timeout:
numberThe maximum number of ticks allowed between
timestampandcurrentTickbefore the message is considered expired.onTimeout:
() => ErrorA factory function that produces the
Errorto throw when the timestamp has timed out (currentTick - timestamp > timeout).onFuture:
() => ErrorA factory function that produces the
Errorto throw when the timestamp is in the future (timestamp > currentTick).
Returns: void
Examples
import { validateTimestamp } from '@kairo-js/utils'
import { router } from '@kairo-js/router'
validateTimestamp(
router.currentTick,
message.timestamp,
20,
() => new Error('Message timed out'),
() => new Error('Message timestamp is in the future'),
)