From ec3a862b6fd5b01a31c7ff666632e41164f11ee0 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 5 Jul 2023 16:32:08 +0200 Subject: [PATCH] Fix invocation expiry time (#147) * fix invocation expiry time --- sdk/src/session.rs | 11 ++++++++--- src/kv/store.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sdk/src/session.rs b/sdk/src/session.rs index 4a2f805a..ac6c788b 100644 --- a/sdk/src/session.rs +++ b/sdk/src/session.rs @@ -15,7 +15,7 @@ use kepler_lib::{ use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; use std::collections::HashMap; -use time::OffsetDateTime; +use time::{ext::NumericalDuration, Duration, OffsetDateTime}; #[serde_as] #[derive(Deserialize, Clone)] @@ -138,13 +138,18 @@ impl Session { let target = self .orbit_id .to_resource(Some(service), Some(path), Some(action)); + let now = OffsetDateTime::now_utc(); + let nanos = now.nanosecond(); + let unix = now.unix_timestamp(); + // 60 seconds in the future + let exp = (unix.seconds() + Duration::nanoseconds(nanos.into()) + Duration::MINUTE) + .as_seconds_f64(); make_invocation( target, self.delegation_cid, &self.jwk, self.verification_method, - // 60 seconds in the future - (OffsetDateTime::now_utc().nanosecond() as f64 / 1e+9_f64) + 60.0, + exp, None, None, ) diff --git a/src/kv/store.rs b/src/kv/store.rs index b2ae6920..8f1810e0 100644 --- a/src/kv/store.rs +++ b/src/kv/store.rs @@ -121,7 +121,7 @@ impl Store { } #[instrument(name = "kv::list", skip_all)] - pub async fn list(&self) -> impl Iterator>> + '_ { + pub async fn list(&self) -> impl Iterator>> { let elements = match self.index.elements().await { Ok(e) => e, Err(e) => return vec![Err(e)].into_iter(),