Skip to content

Commit

Permalink
fix rust warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
happyhackerbird committed May 14, 2024
1 parent aed38d5 commit 6a24e2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
24 changes: 11 additions & 13 deletions src/civic_canister_backend/src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,34 @@ use std::fmt;
use candid::{CandidType, Deserialize, Principal};
use candid::candid_method;

use serde::{Serialize};
use serde::Serialize;
use serde_json::Value;
use std::collections::{HashMap, BTreeMap};
use identity_credential::credential::{CredentialBuilder, Subject};
use identity_core::common::Url;
use std::iter::repeat;
use canister_sig_util::signature_map::{SignatureMap, LABEL_SIG};
use canister_sig_util::signature_map::LABEL_SIG;
use sha2::{Digest, Sha256};

use ic_cdk::api::{caller, set_certified_data, time};
use ic_cdk_macros::{update, query};
use vc_util::issuer_api::{
CredentialSpec, GetCredentialRequest, IssueCredentialError, IssuedCredentialData,
PrepareCredentialRequest, PreparedCredentialData, SignedIdAlias, DerivationOriginData, DerivationOriginError,
DerivationOriginRequest, Icrc21ConsentInfo, Icrc21Error,
Icrc21VcConsentMessageRequest
PrepareCredentialRequest, PreparedCredentialData, SignedIdAlias
};

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 canister_sig_util::{CanisterSigPublicKey, IC_ROOT_PK_DER, extract_raw_root_pk_from_der};
use ic_certification::{Hash, fork_hash, labeled_hash, pruned};
use canister_sig_util::CanisterSigPublicKey;
use ic_certification::{Hash, fork_hash, labeled_hash};
use serde_bytes::ByteBuf;
use std::cell::RefCell;

use lazy_static::lazy_static;

// Assuming these are defined in the same or another module that needs to be imported
extern crate asset_util;
use asset_util::{collect_assets, CertifiedAssets};

use crate::utils::{CONFIG, CREDENTIALS, SIGNATURES, ASSETS};
use identity_core::common::{Timestamp};
use identity_core::common::Timestamp;

// The expiration of issued verifiable credentials.
const MINUTE_NS: u64 = 60 * 1_000_000_000;
Expand Down Expand Up @@ -118,7 +116,7 @@ pub(crate) enum CredentialError {
/// 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 Down Expand Up @@ -376,7 +374,7 @@ pub (crate) fn verify_credential_spec(spec: &CredentialSpec) -> Result<Supported


/// Builds a verifiable credential with the given parameters and returns the credential as a JWT-string.
pub fn build_credential_jwt(params: CredentialParams) -> String {
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(),
Expand All @@ -385,7 +383,7 @@ pub fn build_credential_jwt(params: CredentialParams) -> String {
// let subject = Subject::from_json_value(subject_json).unwrap();

// build "credentialSubject" objects
let subjects = build_claims_into_credentialSubjects(params.claims, params.subject_id);
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 Down
28 changes: 12 additions & 16 deletions src/civic_canister_backend/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
use canister_sig_util::CanisterSigPublicKey;

use std::cell::RefCell;
use std::collections::{HashSet,HashMap};
use std::collections::HashMap;
use canister_sig_util::signature_map::{SignatureMap, LABEL_SIG};
use crate::credential::{Claim, StoredCredential, CredentialError, add_context, build_claims_into_credentialSubjects, update_root_hash};
use crate::credential::{StoredCredential, update_root_hash};

use crate::consent_message::{get_vc_consent_message, SupportedLanguage};
use std::fmt;

use candid::{candid_method, CandidType, Deserialize, Principal};
// use ic_cdk::candid::candid_method;
use canister_sig_util::{extract_raw_root_pk_from_der, IC_ROOT_PK_DER};

use ic_cdk::api::{caller, set_certified_data, time};

use ic_cdk_macros::{init, query, update};
use ic_certification::{fork_hash, labeled_hash, Hash, pruned};
use ic_certification::{labeled_hash, pruned};

use ic_stable_structures::storable::Bound;
use ic_stable_structures::{DefaultMemoryImpl, RestrictedMemory, StableCell, Storable};
use include_dir::{include_dir, Dir};
use sha2::{Digest, Sha256};

use serde_bytes::ByteBuf;


use std::borrow::Cow;
use asset_util::{collect_assets, CertifiedAssets};
use vc_util::issuer_api::{
CredentialSpec, GetCredentialRequest, IssueCredentialError, IssuedCredentialData,
PrepareCredentialRequest, PreparedCredentialData, SignedIdAlias, DerivationOriginData, DerivationOriginError,
DerivationOriginData, DerivationOriginError,
DerivationOriginRequest, Icrc21ConsentInfo, Icrc21Error,
Icrc21VcConsentMessageRequest
};
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 lazy_static::lazy_static;

use ic_cdk::api;

use ic_cdk_macros::post_upgrade;
use identity_credential::credential::{CredentialBuilder};
use identity_core::common::{Timestamp, Url};




const PROD_II_CANISTER_ID: &str = "rdmx6-jaaaa-aaaaa-aaadq-cai";
Expand Down
2 changes: 1 addition & 1 deletion src/civic_canister_backend/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn issuer_canister_serves_http_assets() -> Result<(), CallError> {
println!("{:?}", http_response);
// assert_eq!(http_response.status_code, 200);

let result = verify_response_certification(
let _result = verify_response_certification(
&env,
canister_id,
request,
Expand Down

0 comments on commit 6a24e2b

Please sign in to comment.