generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dataverse): implement vc proof parsing
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
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,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, | ||
}) | ||
} | ||
} |