1
1
use crate :: credential:: rdf_marker:: IRI_VC_TYPE ;
2
2
use crate :: credential:: vc:: VerifiableCredential ;
3
+ use crate :: registrar:: rdf:: VC_CLAIM ;
3
4
use crate :: ContractError ;
4
5
use cosmwasm_std:: Addr ;
5
6
use itertools:: Itertools ;
6
- use okp4_rdf :: dataset :: Dataset ;
7
+ use rio_api :: model :: { BlankNode , NamedNode , Subject , Term , Triple } ;
7
8
8
9
#[ derive( Debug , PartialEq ) ]
9
10
pub struct DataverseCredential < ' a > {
@@ -14,7 +15,7 @@ pub struct DataverseCredential<'a> {
14
15
pub valid_from : & ' a str ,
15
16
pub valid_until : Option < & ' a str > ,
16
17
pub subject : & ' a str ,
17
- pub claim : & ' a Dataset < ' a > ,
18
+ pub claim : Vec < Triple < ' a > > ,
18
19
}
19
20
20
21
impl < ' a > DataverseCredential < ' a > {
@@ -33,16 +34,46 @@ impl<'a> DataverseCredential<'a> {
33
34
34
35
fn extract_vc_claim (
35
36
vc : & ' a VerifiableCredential < ' a > ,
36
- ) -> Result < ( & ' a str , & ' a Dataset < ' a > ) , ContractError > {
37
- vc. claims
37
+ ) -> Result < ( & ' a str , Vec < Triple < ' a > > ) , ContractError > {
38
+ //todo: use the canon identifier issuer instead and rename all blank nodes
39
+ let claim_node = BlankNode { id : "c0" } ;
40
+
41
+ let claim = vc. claims . iter ( ) . exactly_one ( ) . map_err ( |_| {
42
+ ContractError :: UnsupportedCredential (
43
+ "credential is expected to contain exactly one claim" . to_string ( ) ,
44
+ )
45
+ } ) ?;
46
+
47
+ let mut triples = claim
48
+ . content
38
49
. iter ( )
39
- . exactly_one ( )
40
- . map ( |claim| ( claim. id , & ( claim. content ) ) )
41
- . map_err ( |_| {
42
- ContractError :: UnsupportedCredential (
43
- "credential is expected to contain exactly one claim" . to_string ( ) ,
44
- )
50
+ . map ( |q| {
51
+ let subject = match q. subject {
52
+ Subject :: NamedNode ( n) => {
53
+ if n. iri != claim. id {
54
+ Err ( ContractError :: UnsupportedCredential (
55
+ "claim hierarchy can be forge only through blank nodes" . to_string ( ) ,
56
+ ) ) ?;
57
+ }
58
+ Subject :: BlankNode ( claim_node)
59
+ }
60
+ _ => q. subject ,
61
+ } ;
62
+ Ok ( Triple {
63
+ subject,
64
+ predicate : q. predicate ,
65
+ object : q. object ,
66
+ } )
45
67
} )
68
+ . collect :: < Result < Vec < Triple < ' a > > , ContractError > > ( ) ?;
69
+
70
+ triples. push ( Triple {
71
+ subject : Subject :: NamedNode ( NamedNode { iri : vc. id } ) ,
72
+ predicate : VC_CLAIM ,
73
+ object : Term :: BlankNode ( BlankNode { id : "c0" } ) ,
74
+ } ) ;
75
+
76
+ Ok ( ( claim. id , triples) )
46
77
}
47
78
}
48
79
0 commit comments