summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-04-07 14:12:29 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-04-07 14:12:29 +0530
commit34eca9c51215485c70492d6edea3513ada1c8895 (patch)
tree51982ac8c0204d13df7e5834111d975ca0ec309d /src/util
parentfaba5e9db8e0d1fdc4845de6b504b4e2ea3ca72b (diff)
downloadwallet-core-34eca9c51215485c70492d6edea3513ada1c8895.tar.gz
wallet-core-34eca9c51215485c70492d6edea3513ada1c8895.tar.bz2
wallet-core-34eca9c51215485c70492d6edea3513ada1c8895.zip
always round timestamps before signature creation/verification
Diffstat (limited to 'src/util')
-rw-r--r--src/util/time.ts14
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 };