Skip to content

Commit

Permalink
TECH-156 - Add some cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
TYRONEMICHAEL committed May 15, 2024
1 parent ab95d0d commit 1eaac11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 60 deletions.
46 changes: 3 additions & 43 deletions src/civic_canister_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use vc_util::issuer_api::{
use vc_util::{ did_for_principal, get_verified_id_alias_from_jws, vc_jwt_to_jws,
vc_signing_input, vc_signing_input_hash, AliasTuple,
};
use ic_cdk::{api, print};
use ic_cdk::api;
use lazy_static::lazy_static;
use ic_cdk_macros::post_upgrade;
use identity_credential::credential::CredentialBuilder;
Expand Down Expand Up @@ -529,7 +529,7 @@ fn exp_timestamp_s() -> u32 {
}


struct CredentialParams {
pub struct CredentialParams {
spec: CredentialSpec,
subject_id: String,
credential_id_url: String,
Expand All @@ -539,17 +539,7 @@ fn exp_timestamp_s() -> u32 {
expiration_timestamp_s: u32,
}


/// Builds a verifiable credential with the given parameters and returns the credential as a JWT-string.
pub fn build_credential_jwt(params: CredentialParams) -> String {
// let mut subject_json = json!({"id": params.subject_id});
// subject_json.as_object_mut().unwrap().insert(
// params.spec.credential_type.clone(),
// credential_spec_args_to_json(&params.spec),
// );
// let subject = Subject::from_json_value(subject_json).unwrap();

// build "credentialSubject" objects
let subjects = build_claims_into_credential_subjects(params.claims, params.subject_id);
let expiration_date = Timestamp::from_unix(params.expiration_timestamp_s as i64)
.expect("internal: failed computing expiration timestamp");
Expand All @@ -562,10 +552,7 @@ pub fn build_credential_jwt(params: CredentialParams) -> String {
.subjects(subjects) // add objects to the credentialSubject
.expiration_date(expiration_date);

// add all the context
credential = add_context(credential, params.context);
// //add all the type data
// credential = add_types(credential, params.types_);

let credential = credential.build().unwrap();
credential.serialize_jwt().unwrap()
Expand All @@ -589,31 +576,4 @@ pub struct HttpResponse {
pub body: ByteBuf,
}

ic_cdk::export_candid!();


// candid::export_service!();

// #[cfg(test)]
// mod test {
// use crate::__export_service;
// use candid_parser::utils::{service_equal, CandidSource};
// use std::path::Path;

// /// Checks candid interface type equality by making sure that the service in the did file is
// /// a subtype of the generated interface and vice versa.
// #[test]
// fn check_candid_interface_compatibility() {
// let canister_interface = __export_service();
// service_equal(
// CandidSource::Text(&canister_interface),
// CandidSource::File(Path::new("civic_canister_backend.did")),
// )
// .unwrap_or_else(|e| {
// panic!(
// "the canister code interface is not equal to the did file: {:?}",
// e
// )
// });
// }
// }
ic_cdk::export_candid!();
19 changes: 2 additions & 17 deletions src/civic_canister_backend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@ pub(crate) enum CredentialError {
NoCredentialsFound(String),
}


// Helper functions for constructing the credential that is returned from the canister

/// Build a credentialSubject {
/// id: SubjectId,
/// otherData
/// }

pub(crate) fn build_claims_into_credentialSubjects(claims: Vec<Claim>, subject: String) -> Vec<Subject> {
pub(crate) fn build_claims_into_credential_subjects(claims: Vec<Claim>, subject: String) -> Vec<Subject> {
claims.into_iter().zip(repeat(subject)).map(|(c, id )|{
let mut sub = c.into();
sub.id = Url::parse(id).ok();
Expand All @@ -79,11 +71,4 @@ pub(crate) fn add_context(mut credential: CredentialBuilder, context: Vec<String
credential = credential.context(Url::parse(c).unwrap());
}
credential
}

// pub fn add_types(mut credential: CredentialBuilder, types: Vec<String>) -> CredentialBuilder {
// for t in types {
// credential = credential.type_(t);
// }
// credential
// }
}

0 comments on commit 1eaac11

Please sign in to comment.