Skip to content

Commit

Permalink
feat(dataverse): implement vc proof parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 5, 2024
1 parent a972284 commit bd826f9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions contracts/okp4-dataverse/src/did/crypto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::did::consts::RDF_TYPE;
use crate::ContractError;
use itertools::Itertools;
use okp4_rdf::dataset::{Dataset, QuadIterator};
use rio_api::model::Term;

pub struct Proof<'a> {
type_: String,
inner: Dataset<'a>,
}

impl<'a> TryFrom<Dataset<'a>> for Proof<'a> {
type Error = ContractError;

fn try_from(dataset: Dataset<'a>) -> Result<Self, Self::Error> {
Ok(Self {
type_: dataset
.match_pattern(None, Some(RDF_TYPE), None, None)
.objects()
.exactly_one()
.map_err(|_| {
ContractError::InvalidCredential(
"Credential proof can must have only one type".to_string(),
)
})
.and_then(|o| match o {
Term::NamedNode(n) => Ok(n.iri.to_string()),
_ => Err(ContractError::InvalidCredential(
"Credential proof type must be a named node".to_string(),
)),
})?,
inner: dataset,
})
}
}

0 comments on commit bd826f9

Please sign in to comment.