Skip to content

Commit

Permalink
refactor: set id (optional), set exp to one year
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-mader committed Nov 6, 2024
1 parent adcac7e commit 087a811
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions agent_issuance/src/credential/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,32 +232,47 @@ impl Aggregate for Credential {

info!("Credential: {:?}", credential);

#[cfg(feature = "test_utils")]
let iat = 0;
#[cfg(not(feature = "test_utils"))]
let iat = credential.raw["issuanceDate"]
let issuance_date = credential.raw["issuanceDate"]
.as_str()
.unwrap()
.parse::<chrono::DateTime<chrono::Utc>>()
.unwrap()
.timestamp();
.unwrap();

#[cfg(feature = "test_utils")]
let iat = 0;
#[cfg(not(feature = "test_utils"))]
let iat = issuance_date.timestamp();
// let iat = std::time::SystemTime::now()
// .duration_since(std::time::UNIX_EPOCH)
// .unwrap()
// .as_secs() as i64;

#[cfg(feature = "test_utils")]
let exp = 0;
#[cfg(not(feature = "test_utils"))]
let exp = iat + 60 * 60 * 24 * 365; // TODO: currently hard-coded to one year from issuance date

// let exp = issuance_date + chrono::Duration::days(365);
// let exp: i32 = exp.timestamp();

// Add standard claims
let vc_jwt_builder = VerifiableCredentialJwt::builder()
.sub(subject_id)
.iss(issuer_did)
.iat(iat)
.nbf(iat) // TODO: currently iat == nbf
.exp(exp);

let vc_jwt_builder = if let Some(id) = id {
vc_jwt_builder.jti(id.to_string())
} else {
vc_jwt_builder
};

json!(jwt::encode(
services.issuer.clone(),
Header::new(get_preferred_signing_algorithm()),
VerifiableCredentialJwt::builder()
.sub(subject_id)
.iss(issuer_did)
.iat(iat)
// TODO: find out whether this is a required field.
.exp(9999999999i64)
.verifiable_credential(credential.raw)
.build()
.ok(),
vc_jwt_builder.verifiable_credential(credential.raw).build().ok(),
&default_did_method.to_string()
)
.await
Expand Down

0 comments on commit 087a811

Please sign in to comment.