@aws-amplify/core
Version:
Core category of aws-amplify
24 lines (22 loc) • 1.1 kB
JavaScript
;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.isClockSkewed = void 0;
const getSkewCorrectedDate_1 = require("./getSkewCorrectedDate");
// 5 mins in milliseconds. Ref: https://github.com/aws/aws-sdk-js-v3/blob/6c0f44fab30a1bb2134af47362a31332abc3666b/packages/middleware-signing/src/utils/isClockSkewed.ts#L10
const SKEW_WINDOW = 5 * 60 * 1000;
/**
* Checks if the provided date is within the skew window of 5 minutes.
*
* @param clockTimeInMilliseconds Time to check for skew in milliseconds.
* @param clockOffsetInMilliseconds Offset to check clock against in milliseconds.
*
* @returns True if skewed. False otherwise.
*
* @internal
*/
const isClockSkewed = (clockTimeInMilliseconds, clockOffsetInMilliseconds) => Math.abs((0, getSkewCorrectedDate_1.getSkewCorrectedDate)(clockOffsetInMilliseconds).getTime() -
clockTimeInMilliseconds) >= SKEW_WINDOW;
exports.isClockSkewed = isClockSkewed;
//# sourceMappingURL=isClockSkewed.js.map