From d760bd67e87eea5e6f61cbc56a1b03ae409b1fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Thu, 27 Jun 2024 16:38:07 +0200 Subject: [PATCH] Fix tests. --- .../suites/src/suites/w3c/bbs_2023/derive.rs | 5 +- .../src/suites/w3c/bbs_2023/tests/mod.rs | 51 +++++++++++-------- .../w3c/bbs_2023/transformation/base.rs | 2 +- .../src/suites/w3c/bbs_2023/verification.rs | 3 +- crates/jwk/src/lib.rs | 1 + 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/derive.rs b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/derive.rs index 9233ac59d..bd7c5e1c5 100644 --- a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/derive.rs +++ b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/derive.rs @@ -293,7 +293,6 @@ mod tests { use json_syntax::UnorderedPartialEq; use ssi_data_integrity_core::DataIntegrity; use ssi_di_sd_primitives::select::select_json_ld; - use ssi_json_ld::JsonLdEnvironment; use ssi_verification_methods::Multikey; use static_iref::{iri, uri}; @@ -328,10 +327,10 @@ mod tests { &*PUBLIC_KEY, ); - let mut context = JsonLdEnvironment::default(); + let loader = ssi_json_ld::ContextLoader::default(); let data = create_disclosure_data( - &mut context, + &loader, &signed_base.claims, &verification_method, &signed_base.proofs.first().unwrap().signature, diff --git a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/tests/mod.rs b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/tests/mod.rs index 0e8bd332e..cf621a69b 100644 --- a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/tests/mod.rs +++ b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/tests/mod.rs @@ -10,9 +10,10 @@ use lazy_static::lazy_static; use rdf_types::{BlankIdBuf, VocabularyMut}; use serde::{Deserialize, Serialize}; use ssi_bbs::{BBSplusPublicKey, BBSplusSecretKey}; -use ssi_claims_core::{ClaimsValidity, Proof, Validate}; +use ssi_claims_core::{ClaimsValidity, Validate}; use ssi_di_sd_primitives::JsonPointerBuf; -use ssi_json_ld::{AnyJsonLdEnvironment, JsonLdError, JsonLdNodeObject, JsonLdObject, JsonLdTypes}; +use ssi_json_ld::{JsonLdError, JsonLdNodeObject, JsonLdObject, JsonLdTypes}; +use ssi_rdf::{Interpretation, LdEnvironment, LinkedDataResource, LinkedDataSubject}; use static_iref::iri; /// JSON Credential. @@ -20,7 +21,7 @@ use static_iref::iri; pub struct JsonCredential { /// JSON-LD context. #[serde(rename = "@context")] - pub context: json_ld::syntax::Context, + pub context: ssi_json_ld::syntax::Context, /// Credential type. #[serde(rename = "type")] @@ -31,7 +32,7 @@ pub struct JsonCredential { } impl JsonLdObject for JsonCredential { - fn json_ld_context(&self) -> Option> { + fn json_ld_context(&self) -> Option> { Some(Cow::Borrowed(&self.context)) } } @@ -42,28 +43,36 @@ impl JsonLdNodeObject for JsonCredential { } } -impl Validate for JsonCredential { - fn validate(&self, _env: &E, _proof: &P::Prepared) -> ClaimsValidity { +impl Validate for JsonCredential { + fn validate(&self, _env: &E, _proof: &P) -> ClaimsValidity { Ok(()) } } -impl ssi_rdf::Expandable for JsonCredential -where - E: AnyJsonLdEnvironment, - V: VocabularyMut, - V::Iri: Clone + Eq + Hash, - V::BlankId: Clone + Eq + Hash, - L: json_ld::Loader, - L::Error: std::fmt::Display, -{ - type Error = JsonLdError; - - type Expanded = json_ld::ExpandedDocument; - - async fn expand(&self, environment: &mut E) -> Result { +impl ssi_json_ld::Expandable for JsonCredential { + type Error = JsonLdError; + + type Expanded = ssi_json_ld::ExpandedDocument + where + I: Interpretation, + V: VocabularyMut, + V::Iri: LinkedDataResource + LinkedDataSubject, + V::BlankId: LinkedDataResource + LinkedDataSubject; + + #[allow(async_fn_in_trait)] + async fn expand_with( + &self, + ld: &mut LdEnvironment, + loader: &impl ssi_json_ld::Loader, + ) -> Result, Self::Error> + where + I: Interpretation, + V: VocabularyMut, + V::Iri: Clone + Eq + Hash + LinkedDataResource + LinkedDataSubject, + V::BlankId: Clone + Eq + Hash + LinkedDataResource + LinkedDataSubject, + { let json = ssi_json_ld::CompactJsonLd(json_syntax::to_value(self).unwrap()); - json.expand(environment).await + json.expand_with(ld, loader).await } } diff --git a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/transformation/base.rs b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/transformation/base.rs index 99d6cf2e9..f2e5d9b9c 100644 --- a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/transformation/base.rs +++ b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/transformation/base.rs @@ -79,7 +79,7 @@ mod tests { use ssi_data_integrity_core::{ suite::standard::TypedTransformationAlgorithm, ProofConfiguration, }; - use ssi_di_sd_primitives::{group::canonicalize_and_group, JsonPointerBuf}; + use ssi_di_sd_primitives::group::canonicalize_and_group; use ssi_rdf::IntoNQuads; use ssi_verification_methods::{ProofPurpose, ReferenceOrOwned}; diff --git a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/verification.rs b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/verification.rs index a1a8525e8..7acd43d33 100644 --- a/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/verification.rs +++ b/crates/claims/crates/data-integrity/suites/src/suites/w3c/bbs_2023/verification.rs @@ -144,7 +144,6 @@ mod tests { let mut methods = HashMap::new(); methods.insert(VERIFICATION_METHOD_IRI.to_owned(), verification_method); - let vc = document.into_verifiable().await.unwrap(); - assert!(vc.verify(&methods).await.unwrap().is_ok()) + assert!(document.verify(&methods).await.unwrap().is_ok()) } } diff --git a/crates/jwk/src/lib.rs b/crates/jwk/src/lib.rs index 88fec1d78..d8cb620da 100644 --- a/crates/jwk/src/lib.rs +++ b/crates/jwk/src/lib.rs @@ -949,6 +949,7 @@ pub fn secp256k1_parse(data: &[u8]) -> Result { Ok(pk.into()) } +#[cfg(feature = "secp256k1")] impl From for JWK { fn from(value: k256::PublicKey) -> Self { JWK {