From 6e7b3b14faf5e47fe79e016579059e5f7edff589 Mon Sep 17 00:00:00 2001 From: Ryan Tate Date: Wed, 11 Dec 2024 10:07:08 -0800 Subject: [PATCH] use array as preferred for credential types (#628) * use array as preferred for credential types Signed-off-by: Ryan Tate Co-Authored-By: Joey Silberman Signed-off-by: Ryan Tate * resolve failing cargo test (doctest) Signed-off-by: Ryan Tate * update readme Signed-off-by: Ryan Tate * fix eip resolve_vc_issue_verify unit test Signed-off-by: Ryan Tate * Update crates/claims/crates/vc/Cargo.toml --------- Signed-off-by: Ryan Tate Co-authored-by: Joey Silberman --- README.md | 7 ++++--- crates/claims/crates/vc/Cargo.toml | 5 ++++- crates/claims/crates/vc/src/v1/syntax/presentation.rs | 2 +- crates/dids/methods/pkh/src/lib.rs | 2 +- src/lib.rs | 7 ++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 771fc6768..cecbb4230 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ yourself. ```rust use static_iref::uri; use serde::{Serialize, Deserialize}; +use ssi::claims::vc::syntax::NonEmptyVec; use ssi::prelude::*; // Defines the shape of our custom claims. @@ -183,10 +184,10 @@ let credential = ssi::claims::vc::v1::JsonCredential::::new Some(uri!("https://example.org/#CredentialId").to_owned()), // id uri!("https://example.org/#Issuer").to_owned().into(), // issuer DateTime::now(), // issuance date - vec![MyCredentialSubject { + NonEmptyVec::new(MyCredentialSubject { name: "John Smith".to_owned(), email: "john.smith@example.org".to_owned() - }] + }) ); // Create a random signing key, and turn its public part into a DID URL. @@ -216,7 +217,7 @@ let vc = cryptosuite.sign( ProofOptions::from_method(verification_method) ).await.expect("signature failed"); ``` - + It is critical that custom claims can be interpreted as Linked-Data. In the above example this is done by specifying a serialization URL for each field of `MyCredentialSubject`. This can also be done by creating a custom diff --git a/crates/claims/crates/vc/Cargo.toml b/crates/claims/crates/vc/Cargo.toml index 83cdfd630..a527fe0bc 100644 --- a/crates/claims/crates/vc/Cargo.toml +++ b/crates/claims/crates/vc/Cargo.toml @@ -33,7 +33,10 @@ educe.workspace = true base64.workspace = true bitvec = "0.20" flate2 = "1.0" -reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } +reqwest = { version = "0.11", default-features = false, features = [ + "json", + "rustls-tls", +] } ssi-verification-methods.workspace = true ssi-dids-core.workspace = true ssi-data-integrity.workspace = true diff --git a/crates/claims/crates/vc/src/v1/syntax/presentation.rs b/crates/claims/crates/vc/src/v1/syntax/presentation.rs index 909f89420..8f0842a57 100644 --- a/crates/claims/crates/vc/src/v1/syntax/presentation.rs +++ b/crates/claims/crates/vc/src/v1/syntax/presentation.rs @@ -21,7 +21,7 @@ impl RequiredType for PresentationType { } impl TypeSerializationPolicy for PresentationType { - const PREFER_ARRAY: bool = false; + const PREFER_ARRAY: bool = true; } pub type JsonPresentationTypes = Types; diff --git a/crates/dids/methods/pkh/src/lib.rs b/crates/dids/methods/pkh/src/lib.rs index c98edf75a..22772dbef 100644 --- a/crates/dids/methods/pkh/src/lib.rs +++ b/crates/dids/methods/pkh/src/lib.rs @@ -1313,7 +1313,7 @@ mod tests { ], "VerifiablePresentation": [ { "name": "@context", "type": "string[]" }, - { "name": "type", "type": "string" }, + { "name": "type", "type": "string[]" }, { "name": "holder", "type": "string" }, { "name": "verifiableCredential", "type": "VerifiableCredential" }, { "name": "proof", "type": "Proof" } diff --git a/src/lib.rs b/src/lib.rs index f4c0fc536..8895b5cb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,6 +171,7 @@ //! # async fn main() { //! use static_iref::uri; //! use serde::{Serialize, Deserialize}; +//! use ssi::claims::vc::syntax::NonEmptyVec; //! use ssi::prelude::*; //! //! // Defines the shape of our custom claims. @@ -187,10 +188,10 @@ //! Some(uri!("https://example.org/#CredentialId").to_owned()), // id //! uri!("https://example.org/#Issuer").to_owned().into(), // issuer //! DateTime::now(), // issuance date -//! vec![MyCredentialSubject { +//! NonEmptyVec::new(MyCredentialSubject { //! name: "John Smith".to_owned(), //! email: "john.smith@example.org".to_owned() -//! }] +//! }) //! ); //! //! // Create a random signing key, and turn its public part into a DID URL. @@ -221,7 +222,7 @@ //! ).await.expect("signature failed"); //! # } //! ``` -//! +//! //! It is critical that custom claims can be interpreted as Linked-Data. In //! the above example this is done by specifying a serialization URL for each //! field of `MyCredentialSubject`. This can also be done by creating a custom