Skip to content

Commit

Permalink
Bump rdf-types to version 0.22.
Browse files Browse the repository at this point in the history
Bump `nquads-syntax` to 0.19.
Bump `linked-data` to 0.1.2.
Bump `json-ld` to commit `d437133`.
Remove `grdf` dependency.
  • Loading branch information
timothee-haudebourg committed Mar 26, 2024
1 parent 7040d7d commit fab3d9b
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 196 deletions.
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ thiserror = "1.0.40"
chrono = "0.4.24"
iref = "3.1.2"
static-iref = "3.0"
rdf-types = "0.18.3"
rdf-types = "0.22.3"
xsd-types = "0.9.2"
grdf = "0.22"
locspan = "0.8"
json-syntax = "0.12.2"
nquads-syntax = "0.17"
nquads-syntax = "0.19"
multibase = "0.9.1"
# json-ld = "0.15"
json-ld = { git = "https://github.com/timothee-haudebourg/json-ld.git" }
json-ld = { git = "https://github.com/timothee-haudebourg/json-ld.git", rev = "d437133" }
serde = "1.0"
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
serde_jcs = "0.1.0"
Expand All @@ -98,7 +97,7 @@ derivative = "2.2.0"
educe = "0.4.22"
pin-project = "1.1.3"
futures = "0.3.28"
linked-data = { git = "https://github.com/spruceid/linked-data-rs.git" }
linked-data = "0.1.2"
rand_chacha = "0.3.1"
contextual = "0.1.6"
lazy_static = "1.4.0"
Expand Down
1 change: 0 additions & 1 deletion crates/claims/crates/data-integrity/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ thiserror.workspace = true
static-iref.workspace = true
json-ld = { workspace = true, features = ["serde"] }
locspan.workspace = true
grdf.workspace = true
hex.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
64 changes: 34 additions & 30 deletions crates/claims/crates/data-integrity/core/src/proof/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use educe::Educe;
use grdf::{HashDataset, HashGraph};
use iref::{Iri, IriBuf};
use linked_data::{LinkedDataResource, LinkedDataSubject};
use rdf_types::{
ExportedFromVocabulary, Id, InterpretationMut, IriVocabulary, Literal, Quad,
ReverseBlankIdInterpretation, ReverseIriInterpretation, ReverseLiteralInterpretation, Term,
Triple, VocabularyMut,
dataset::{BTreeGraph, IndexedBTreeDataset, PatternMatchingDataset},
interpretation::ReverseTermInterpretation,
vocabulary::IriVocabulary,
Id, InterpretationMut, LexicalQuad, Quad, Term, Triple, VocabularyMut,
};
use serde::{Deserialize, Serialize};
use ssi_core::Referencable;
Expand Down Expand Up @@ -405,11 +405,8 @@ where
V: VocabularyMut,
V::Iri: Clone + Eq + Hash + LinkedDataResource<I, V> + LinkedDataSubject<I, V>,
V::BlankId: Clone + Eq + Hash + LinkedDataResource<I, V> + LinkedDataSubject<I, V>,
V::Literal: ExportedFromVocabulary<V, Output = Literal>,
I: InterpretationMut<V>
+ ReverseIriInterpretation<Iri = V::Iri>
+ ReverseBlankIdInterpretation<BlankId = V::BlankId>
+ ReverseLiteralInterpretation<Literal = V::Literal>,
+ ReverseTermInterpretation<Iri = V::Iri, BlankId = V::BlankId, Literal = V::Literal>,
I::Resource: Clone,
L: json_ld::Loader<V::Iri>,
//
Expand Down Expand Up @@ -486,17 +483,18 @@ where
&node,
)?;

let mut dataset: HashDataset<Id, IriBuf, Term, Id> = quads.into_iter().collect();
let subject = Term::Id(subject);

let proof_prop = ssi_security::PROOF.to_owned();
match dataset
.default_graph()
.objects(&subject, &proof_prop)
.next()
{
let mut dataset: IndexedBTreeDataset = quads
.into_iter()
.map(|q| Quad(Term::Id(q.0), Term::iri(q.1), q.2, q.3.map(Term::Id)))
.collect();

let proof_prop = Term::iri(ssi_security::PROOF.to_owned());
match dataset.quad_objects(None, &subject, &proof_prop).next() {
Some(Term::Id(proof_id)) => {
let proof_id = proof_id.clone();
match dataset.remove_graph(&proof_id) {
let proof_id = Term::Id(proof_id.clone());
match dataset.remove_graph(Some(&proof_id)) {
Some(graph) => Ok(LinkedDataConfiguration {
type_iri: proof_type,
graph,
Expand Down Expand Up @@ -548,7 +546,7 @@ pub enum ConfigurationExpansionError<E> {
/// Linked-Data proof configuration.
pub struct LinkedDataConfiguration {
pub type_iri: IriBuf,
pub graph: HashGraph<Id, IriBuf, Term>,
pub graph: BTreeGraph,
}

impl LinkedDataConfiguration {
Expand Down Expand Up @@ -576,12 +574,15 @@ pub struct ExpandedConfiguration<'a, M: Referencable, O: Referencable = ()> {

impl<'a, M: Referencable, O: Referencable> ExpandedConfiguration<'a, M, O> {
/// Returns the quads of the proof configuration, in canonical form.
pub fn quads(&self) -> impl '_ + Iterator<Item = Quad> {
let quads = self
.ld
.graph
.triples()
.map(|Triple(s, p, o)| Quad(s.as_id_ref(), p.as_iri(), o.as_term_ref(), None));
pub fn quads(&self) -> impl '_ + Iterator<Item = LexicalQuad> {
let quads = self.ld.graph.iter().map(|Triple(s, p, o)| {
Quad(
s.as_lexical_term_ref().into_id().unwrap(),
p.as_lexical_term_ref().into_iri().unwrap(),
o.as_lexical_term_ref(),
None,
)
});

urdna2015::normalize(quads)
}
Expand Down Expand Up @@ -697,12 +698,15 @@ impl<'a, M: Referencable, O: Referencable> ExpandedConfigurationRef<'a, M, O> {

impl<'a, M: Referencable, O: Referencable> ExpandedConfigurationRef<'a, M, O> {
/// Returns the quads of the proof configuration, in canonical form.
pub fn quads(&self) -> impl '_ + Iterator<Item = Quad> {
let quads = self
.ld
.graph
.triples()
.map(|Triple(s, p, o)| Quad(s.as_id_ref(), p.as_iri(), o.as_term_ref(), None));
pub fn quads(&self) -> impl '_ + Iterator<Item = LexicalQuad> {
let quads = self.ld.graph.iter().map(|Triple(s, p, o)| {
Quad(
s.as_lexical_term_ref().into_id().unwrap(),
p.as_lexical_term_ref().into_iri().unwrap(),
o.as_lexical_term_ref(),
None,
)
});

urdna2015::normalize(quads)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/claims/crates/data-integrity/src/any/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::AnySuiteOptions;
use rdf_types::{
generator,
interpretation::{self, WithGenerator},
IriVocabulary,
vocabulary::IriVocabulary,
};
use ssi_data_integrity_core::{
suite::{HashError, TransformError},
Expand Down Expand Up @@ -124,8 +124,7 @@ where
I: rdf_types::interpretation::InterpretationMut<V>
+ rdf_types::interpretation::ReverseIriInterpretation<Iri = V::Iri>
+ rdf_types::interpretation::ReverseBlankIdInterpretation<BlankId = V::BlankId>
+ rdf_types::ReverseLiteralInterpretation<Literal = V::Literal>,
V::Literal: rdf_types::ExportedFromVocabulary<V, Output = rdf_types::Literal>,
+ rdf_types::interpretation::ReverseLiteralInterpretation<Literal = V::Literal>,
T: serde::Serialize + Expandable<E>,
T::Expanded: linked_data::LinkedData<I, V>,
{
Expand Down
23 changes: 8 additions & 15 deletions crates/claims/crates/data-integrity/src/any/suite.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use iref::Iri;
use linked_data::{LinkedDataDeserializePredicateObjects, LinkedDataDeserializeSubject};
use rdf_types::{interpretation::ReverseIriInterpretation, Interpretation, Vocabulary};
use rdf_types::{
dataset::PatternMatchingDataset, interpretation::ReverseIriInterpretation, Interpretation,
Vocabulary,
};
use ssi_claims_core::ProofValidity;
use ssi_core::Referencable;
use ssi_crypto::MessageSigner;
Expand All @@ -25,18 +28,13 @@ where
vocabulary: &V,
interpretation: &I,
dataset: &D,
graph: &D::Graph,
graph: Option<&I::Resource>,
objects: impl IntoIterator<Item = &'a I::Resource>,
context: linked_data::Context<I>,
) -> Result<Self, linked_data::FromLinkedDataError>
where
I::Resource: 'a,
D: linked_data::grdf::Dataset<
Subject = I::Resource,
Predicate = I::Resource,
Object = I::Resource,
GraphLabel = I::Resource,
>,
D: PatternMatchingDataset<Resource = I::Resource>,
{
let mut objects = objects.into_iter();
match objects.next() {
Expand Down Expand Up @@ -121,17 +119,12 @@ macro_rules! crypto_suites {
vocabulary: &V,
interpretation: &I,
_dataset: &D,
_graph: &D::Graph,
_graph: Option<&I::Resource>,
resource: &I::Resource,
context: linked_data::Context<I>
) -> Result<Self, linked_data::FromLinkedDataError>
where
D: linked_data::grdf::Dataset<
Subject = I::Resource,
Predicate = I::Resource,
Object = I::Resource,
GraphLabel = I::Resource,
>
D: PatternMatchingDataset<Resource = I::Resource>
{
let mut known_iri = None;

Expand Down
1 change: 0 additions & 1 deletion crates/claims/crates/data-integrity/suites/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ thiserror.workspace = true
static-iref.workspace = true
json-ld = { workspace = true, features = ["serde"] }
locspan.workspace = true
grdf.workspace = true
hex.workspace = true
serde = { workspace = true, features = ["derive"] }
pin-project.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/claims/crates/data-integrity/suites/src/suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ macro_rules! impl_rdf_input_urdna2015 {
I: rdf_types::interpretation::InterpretationMut<V>
+ rdf_types::interpretation::ReverseIriInterpretation<Iri = V::Iri>
+ rdf_types::interpretation::ReverseBlankIdInterpretation<BlankId = V::BlankId>
+ rdf_types::ReverseLiteralInterpretation<Literal = V::Literal>,
V::Literal: rdf_types::ExportedFromVocabulary<V, Output = rdf_types::Literal>,
+ rdf_types::interpretation::ReverseLiteralInterpretation<Literal = V::Literal>,
T: $crate::ssi_rdf::Expandable<E>,
T::Expanded: linked_data::LinkedData<I, V>,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! EIP-712 Signature 2021 implementation.
use rdf_types::Quad;
use rdf_types::{LexicalQuad, Quad};
use ssi_crypto::MessageSigner;
use ssi_data_integrity_core::{
suite::{HashError, TransformError},
Expand Down Expand Up @@ -201,6 +201,10 @@ impl CryptographicSuite for Eip712Signature2021 {
data: ssi_eip712::TypedData,
_proof_configuration: ExpandedConfiguration<Self::VerificationMethod, Self::Options>,
) -> Result<Self::Hashed, HashError> {
eprintln!(
"typed data: {}",
serde_json::to_string_pretty(&data).unwrap()
);
data.encode()
.map_err(|e| HashError::InvalidMessage(Box::new(e)))
}
Expand Down Expand Up @@ -238,8 +242,7 @@ where
I: rdf_types::interpretation::InterpretationMut<V>
+ rdf_types::interpretation::ReverseIriInterpretation<Iri = V::Iri>
+ rdf_types::interpretation::ReverseBlankIdInterpretation<BlankId = V::BlankId>
+ rdf_types::ReverseLiteralInterpretation<Literal = V::Literal>,
V::Literal: rdf_types::ExportedFromVocabulary<V, Output = rdf_types::Literal>,
+ rdf_types::interpretation::ReverseLiteralInterpretation<Literal = V::Literal>,
T: Expandable<E>,
T::Expanded: linked_data::LinkedData<I, V>,
{
Expand Down Expand Up @@ -271,13 +274,12 @@ where
I: rdf_types::interpretation::InterpretationMut<V>
+ rdf_types::interpretation::ReverseIriInterpretation<Iri = V::Iri>
+ rdf_types::interpretation::ReverseBlankIdInterpretation<BlankId = V::BlankId>
+ rdf_types::ReverseLiteralInterpretation<Literal = V::Literal>,
V::Literal: rdf_types::ExportedFromVocabulary<V, Output = rdf_types::Literal>,
+ rdf_types::interpretation::ReverseLiteralInterpretation<Literal = V::Literal>,
T: linked_data::LinkedData<I, V>,
{
let document_quads = context.quads_of(data)?;
let document_quads: Vec<_> =
ssi_rdf::urdna2015::normalize(document_quads.iter().map(|quad| quad.as_quad_ref()))
ssi_rdf::urdna2015::normalize(document_quads.iter().map(|quad| quad.as_lexical_quad_ref()))
.collect();
let proof_quads = options.quads().collect();
Ok(new_ldp_siging_request(document_quads, proof_quads))
Expand All @@ -303,8 +305,8 @@ where
/// }
/// ```
pub fn new_ldp_siging_request(
mut document: Vec<Quad>,
mut proof_configuration: Vec<Quad>,
mut document: Vec<LexicalQuad>,
mut proof_configuration: Vec<LexicalQuad>,
) -> ssi_eip712::TypedData {
use ssi_eip712::{TypeRef, Value};

Expand Down Expand Up @@ -333,7 +335,7 @@ pub fn new_ldp_siging_request(
.collect(),
};

fn encode_statement(Quad(s, p, o, g): Quad) -> Value {
fn encode_statement(Quad(s, p, o, g): LexicalQuad) -> Value {
use rdf_types::RdfDisplay;

let mut terms = vec![
Expand Down
Loading

0 comments on commit fab3d9b

Please sign in to comment.