Skip to content

Commit

Permalink
VCDM v2.0 (#549)
Browse files Browse the repository at this point in the history
* Data Model v2.0 traits.
* VCDM v2.0 (JSON) syntax types.
* Add `DataIntegrityDocument` type.
* Add documentation, defaults & re-exports.
  • Loading branch information
timothee-haudebourg committed Jun 27, 2024
1 parent b9e988d commit 2446a45
Show file tree
Hide file tree
Showing 79 changed files with 1,635 additions and 890 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ any Data-Integrity proof supported by SSI.
```rust
use ssi::prelude::*;

let vc = any_credential_from_json_str(
let vc = ssi::claims::vc::v1::data_integrity::any_credential_from_json_str(
&std::fs::read_to_string("examples/files/vc.jsonld")
.expect("unable to load VC")
).await.expect("invalid VC");
Expand Down Expand Up @@ -165,7 +165,7 @@ pub struct MyCredentialSubject {
email: String
}

let credential = SpecializedJsonCredential::<MyCredentialSubject>::new(
let credential = ssi::claims::vc::v1::JsonCredential::<MyCredentialSubject>::new(
Some(uri!("https://example.org/#CredentialId").to_owned()), // id
uri!("https://example.org/#Issuer").to_owned().into(), // issuer
DateTime::now(), // issuance date
Expand Down
79 changes: 79 additions & 0 deletions crates/claims/crates/data-integrity/core/src/document.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use std::{borrow::Cow, collections::BTreeMap, hash::Hash};

use rdf_types::VocabularyMut;
use serde::{Deserialize, Serialize};
use ssi_claims_core::Validate;
use ssi_core::OneOrMany;
use ssi_json_ld::{JsonLdError, JsonLdNodeObject, JsonLdObject, Loader};
use ssi_rdf::{Interpretation, LdEnvironment, LinkedDataResource, LinkedDataSubject, Vocabulary};

/// Any Data-Integrity-compatible document.
///
/// The only assumption made by this type is that the JSON-LD `@type` attribute
/// is aliased to `type`, which is common practice (for instance with
/// Verifiable Credentials).
///
/// Note that this type represents an *unsecured* document.
/// The type for any Data-Integrity-secured document (with the cryptosuite `S`)
/// is [`DataIntegrity<DataIntegrityDocument, S>`](crate::DataIntegrity).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataIntegrityDocument {
#[serde(rename = "@context", skip_serializing_if = "Option::is_none")]
pub context: Option<ssi_json_ld::syntax::Context>,

#[serde(
rename = "type",
alias = "@type",
default,
skip_serializing_if = "OneOrMany::is_empty"
)]
pub types: OneOrMany<String>,

#[serde(flatten)]
pub properties: BTreeMap<String, ssi_json_ld::syntax::Value>,
}

impl ssi_json_ld::Expandable for DataIntegrityDocument {
type Error = JsonLdError;

type Expanded<I: Interpretation, V: Vocabulary> = ssi_json_ld::ExpandedDocument<V::Iri, V::BlankId>
where
I: Interpretation,
V: VocabularyMut,
V::Iri: LinkedDataResource<I, V> + LinkedDataSubject<I, V>,
V::BlankId: LinkedDataResource<I, V> + LinkedDataSubject<I, V>;

#[allow(async_fn_in_trait)]
async fn expand_with<I, V>(
&self,
ld: &mut LdEnvironment<V, I>,
loader: &impl Loader,
) -> Result<Self::Expanded<I, V>, Self::Error>
where
I: Interpretation,
V: VocabularyMut,
V::Iri: Clone + Eq + Hash + LinkedDataResource<I, V> + LinkedDataSubject<I, V>,
V::BlankId: Clone + Eq + Hash + LinkedDataResource<I, V> + LinkedDataSubject<I, V>,
{
let json = ssi_json_ld::CompactJsonLd(json_syntax::to_value(self).unwrap());
json.expand_with(ld, loader).await
}
}

impl JsonLdObject for DataIntegrityDocument {
fn json_ld_context(&self) -> Option<Cow<ssi_json_ld::syntax::Context>> {
self.context.as_ref().map(Cow::Borrowed)
}
}

impl JsonLdNodeObject for DataIntegrityDocument {
fn json_ld_type(&self) -> ssi_json_ld::JsonLdTypes {
ssi_json_ld::JsonLdTypes::new(&[], Cow::Borrowed(self.types.as_slice()))
}
}

impl<E, P> Validate<E, P> for DataIntegrityDocument {
fn validate(&self, _env: &E, _proof: &P) -> ssi_claims_core::ClaimsValidity {
Ok(())
}
}
2 changes: 2 additions & 0 deletions crates/claims/crates/data-integrity/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ops::{Deref, DerefMut};
pub mod canonicalization;
mod de;
mod decode;
mod document;
pub mod hashing;
mod options;
mod proof;
Expand All @@ -23,6 +24,7 @@ pub use suite::{
DeserializeCryptographicSuite, SerializeCryptographicSuite, StandardCryptographicSuite,
};

pub use document::*;
#[doc(hidden)]
pub use ssi_rdf;

Expand Down
2 changes: 0 additions & 2 deletions crates/claims/crates/data-integrity/core/src/signing/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ where
prepared_claims: S::PreparedClaims,
proof: ProofRef<S>,
) -> Result<ssi_claims_core::ProofValidity, ProofValidationError> {
eprintln!("payload: {:?}", prepared_claims.as_ref());

let JWS {
header, signature, ..
} = proof
Expand Down
2 changes: 1 addition & 1 deletion crates/claims/crates/data-integrity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub type AnyProof = Proof<AnySuite>;
pub type AnyProofs = Proofs<AnySuite>;

/// Data-Integrity-secured claims with any cryptographic suite.
pub type AnyDataIntegrity<T> = DataIntegrity<T, AnySuite>;
pub type AnyDataIntegrity<T = DataIntegrityDocument> = DataIntegrity<T, AnySuite>;
11 changes: 3 additions & 8 deletions crates/claims/crates/jws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,7 @@ pub fn verify_bytes_warnable(
signature: &[u8],
) -> Result<VerificationWarnings, Error> {
let mut warnings = VerificationWarnings::default();
eprintln!("verify with algorithm: {algorithm}");
if let Some(key_algorithm) = key.algorithm {
eprintln!("key algorithm: {key_algorithm}");
if key_algorithm != algorithm
&& !(key_algorithm == Algorithm::EdDSA && algorithm == Algorithm::EdBlake2b)
&& !(key_algorithm == Algorithm::ES256 && algorithm == Algorithm::ESBlake2b)
Expand Down Expand Up @@ -638,12 +636,9 @@ pub fn verify_bytes_warnable(
return Err(ssi_jwk::Error::CurveNotImplemented(okp.curve.to_string()).into());
}
let hash = match algorithm {
Algorithm::EdBlake2b => {
eprintln!("verifying EdBlake2b");
<blake2::Blake2b<U32> as Digest>::new_with_prefix(data)
.finalize()
.to_vec()
}
Algorithm::EdBlake2b => <blake2::Blake2b<U32> as Digest>::new_with_prefix(data)
.finalize()
.to_vec(),
_ => data.to_vec(),
};
#[cfg(feature = "ring")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ssi_data_integrity::{
};
use ssi_json_ld::{CompactJsonLd, Expandable, JsonLdError, JsonLdNodeObject, JsonLdObject, Loader};
use ssi_jws::{CompactJWS, InvalidCompactJWS, JWSVerifier, ValidateJWSHeader};
use ssi_vc::{json::JsonCredentialTypes, Context, V2};
use ssi_vc::v2::{syntax::JsonCredentialTypes, Context};
use ssi_verification_methods::ssi_core::OneOrMany;

use crate::{
Expand All @@ -27,7 +27,7 @@ use super::BitstringStatusListEntry;
pub struct BitstringStatusListEntrySetCredential {
/// JSON-LD context.
#[serde(rename = "@context")]
pub context: Context<V2>,
pub context: Context,

/// Credential identifier.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use ssi_data_integrity::{
use ssi_json_ld::{CompactJsonLd, Expandable, JsonLdError, JsonLdNodeObject, JsonLdObject, Loader};
use ssi_jws::{CompactJWS, InvalidCompactJWS, JWSVerifier, ValidateJWSHeader};
use ssi_vc::{
json::{JsonCredentialTypes, RequiredCredentialType},
Context, V2,
syntax::RequiredType,
v2::syntax::{Context, JsonCredentialTypes},
};

use crate::{EncodedStatusMap, FromBytes, FromBytesOptions};
Expand All @@ -27,16 +27,16 @@ pub const BITSTRING_STATUS_LIST_CREDENTIAL_TYPE: &str = "BitstringStatusListCred
#[derive(Debug, Clone, Copy)]
pub struct BitstringStatusListCredentialType;

impl RequiredCredentialType for BitstringStatusListCredentialType {
const REQUIRED_CREDENTIAL_TYPE: &'static str = BITSTRING_STATUS_LIST_CREDENTIAL_TYPE;
impl RequiredType for BitstringStatusListCredentialType {
const REQUIRED_TYPE: &'static str = BITSTRING_STATUS_LIST_CREDENTIAL_TYPE;
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BitstringStatusListCredential {
/// JSON-LD context.
#[serde(rename = "@context")]
pub context: Context<V2>,
pub context: Context,

/// Credential identifier.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
8 changes: 4 additions & 4 deletions crates/claims/crates/vc/examples/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use xsd_types::DateTime;
pub struct Credential {
#[ld(ignore)]
#[serde(rename = "@context")]
context: ssi_vc::Context,
context: ssi_vc::v1::Context,

#[ld(ignore)]
#[serde(rename = "type")]
type_: ssi_vc::json::JsonCredentialTypes,
type_: ssi_vc::v1::JsonCredentialTypes,

#[ld("cred:credentialSubject")]
credential_subject: CredentialSubject,
Expand Down Expand Up @@ -55,11 +55,11 @@ where
E: ssi_claims_core::DateTimeEnvironment,
{
fn validate(&self, env: &E, _proof: &P) -> ssi_claims_core::ClaimsValidity {
ssi_vc::Credential::validate_credential(self, env)
ssi_vc::v1::Credential::validate_credential(self, env)
}
}

impl ssi_vc::Credential for Credential {
impl ssi_vc::v1::Credential for Credential {
type Subject = CredentialSubject;
type Issuer = Uri;
type Status = std::convert::Infallible;
Expand Down
21 changes: 0 additions & 21 deletions crates/claims/crates/vc/src/data_model/evidence.rs

This file was deleted.

11 changes: 0 additions & 11 deletions crates/claims/crates/vc/src/data_model/issuer.rs

This file was deleted.

15 changes: 0 additions & 15 deletions crates/claims/crates/vc/src/data_model/mod.rs

This file was deleted.

20 changes: 0 additions & 20 deletions crates/claims/crates/vc/src/data_model/refresh_service.rs

This file was deleted.

17 changes: 0 additions & 17 deletions crates/claims/crates/vc/src/data_model/status.rs

This file was deleted.

22 changes: 0 additions & 22 deletions crates/claims/crates/vc/src/data_model/terms_of_use.rs

This file was deleted.

Loading

0 comments on commit 2446a45

Please sign in to comment.