diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-04-07 14:12:29 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-04-07 14:12:29 +0530 |
commit | 34eca9c51215485c70492d6edea3513ada1c8895 (patch) | |
tree | 51982ac8c0204d13df7e5834111d975ca0ec309d /src/util | |
parent | faba5e9db8e0d1fdc4845de6b504b4e2ea3ca72b (diff) | |
download | wallet-core-34eca9c51215485c70492d6edea3513ada1c8895.tar.xz |
always round timestamps before signature creation/verification
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/time.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/time.ts b/src/util/time.ts index ea4f8ca8d..f296aba12 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -49,6 +49,7 @@ export function getTimestampNow(): Timestamp { export function getDurationRemaining( deadline: Timestamp, now = getTimestampNow(), + ): Duration { if (deadline.t_ms === "never") { return { d_ms: "forever" }; @@ -72,6 +73,19 @@ export function timestampMin(t1: Timestamp, t2: Timestamp): Timestamp { return { t_ms: Math.min(t1.t_ms, t2.t_ms) }; } +/** + * Truncate a timestamp so that that it represents a multiple + * of seconds. The timestamp is always rounded down. + */ +export function timestampTruncateToSecond(t1: Timestamp): Timestamp { + if (t1.t_ms === "never") { + return { t_ms: "never" }; + } + return { + t_ms: Math.floor(t1.t_ms / 1000) * 1000, + }; +} + export function durationMin(d1: Duration, d2: Duration): Duration { if (d1.d_ms === "forever") { return { d_ms: d2.d_ms }; |