Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exp claim to VCs issued by the issuer #2070

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion demos/vc_issuer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ic_cdk_macros::{init, query, update};
use ic_certification::{Hash, HashTree};
use ic_stable_structures::storable::Bound;
use ic_stable_structures::{DefaultMemoryImpl, RestrictedMemory, StableCell, Storable};
use identity_core::common::Url;
use identity_core::common::{Timestamp, Url};
use identity_core::convert::FromJson;
use identity_credential::credential::{Credential, CredentialBuilder, Subject};
use serde::Serialize;
Expand Down Expand Up @@ -36,6 +36,8 @@ type ConfigCell = StableCell<IssuerConfig, Memory>;
const MINUTE_NS: u64 = 60 * 1_000_000_000;
const CERTIFICATE_VALIDITY_PERIOD_NS: u64 = 5 * MINUTE_NS;
const PROD_II_CANISTER_ID: &str = "rdmx6-jaaaa-aaaaa-aaadq-cai";
// The expiration of issued verifiable credentials.
const VC_EXPIRATION_PERIOD_NS: u64 = 15 * MINUTE_NS;

thread_local! {
/// Static configuration of the canister set by init() or post_upgrade().
Expand Down Expand Up @@ -418,6 +420,7 @@ fn bachelor_degree_credential(subject_principal: Principal) -> Credential {
.issuer(Url::parse("https://example.edu").unwrap())
.type_("UniversityDegreeCredential")
.subject(subject)
.expiration_date(exp_timestamp())
.build()
.unwrap()
}
Expand All @@ -438,10 +441,16 @@ fn dfinity_employment_credential(subject_principal: Principal) -> Credential {
.issuer(Url::parse("https://employment.info").unwrap())
.type_("VerifiedEmployee")
.subject(subject)
.expiration_date(exp_timestamp())
.build()
.unwrap()
}

fn exp_timestamp() -> Timestamp {
Timestamp::from_unix(((time() + VC_EXPIRATION_PERIOD_NS) / 1_000_000_000) as i64)
.expect("internal: failed computing expiration timestamp")
}

fn prepare_credential_payload(
req: &PrepareCredentialRequest,
alias_tuple: &AliasTuple,
Expand Down