-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8c63bf
commit c33c39f
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::{borrow::Cow, collections::BTreeMap, hash::Hash}; | ||
|
||
use rdf_types::VocabularyMut; | ||
use serde::{Deserialize, Serialize}; | ||
use ssi_claims_core::{Proof, Validate}; | ||
use ssi_core::OneOrMany; | ||
use ssi_json_ld::{AnyJsonLdEnvironment, JsonLdError, JsonLdNodeObject, JsonLdObject}; | ||
|
||
/// 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). | ||
#[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<E, V, L> ssi_rdf::Expandable<E> for DataIntegrityDocument | ||
where | ||
E: AnyJsonLdEnvironment<Vocabulary = V, Loader = L>, | ||
V: VocabularyMut, | ||
V::Iri: Clone + Eq + Hash, | ||
V::BlankId: Clone + Eq + Hash, | ||
L: json_ld::Loader<V::Iri>, | ||
L::Error: std::fmt::Display, | ||
{ | ||
type Error = JsonLdError<L::Error>; | ||
|
||
type Expanded = json_ld::ExpandedDocument<V::Iri, V::BlankId>; | ||
|
||
async fn expand(&self, environment: &mut E) -> Result<Self::Expanded, Self::Error> { | ||
let json = ssi_json_ld::CompactJsonLd(json_syntax::to_value(self).unwrap()); | ||
json.expand(environment).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: Proof> Validate<E, P> for DataIntegrityDocument { | ||
fn validate(&self, _env: &E, _proof: &P::Prepared) -> ssi_claims_core::ClaimsValidity { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters