@@ -61,6 +61,24 @@ def _issue_credential(self, issuer_keypath, issuer_did, holder_did, outfile):
6161 return res , code
6262
6363
64+ def _verify_credential (self , vcfile , schema = None , allowed_issuer = None ):
65+ command = ["waltid-cli" , "vc" , "verify" ]
66+ args = ["-p" , "signature" , vcfile ]
67+
68+ if schema :
69+ args = ["-p" , "schema" , f"--arg=schema={ schema } " ] + args
70+
71+ if allowed_issuer :
72+ args = ["-p" , "allowed-issuer" , f"--arg=issuer={ allowed_issuer } " ] + args
73+
74+ # TODO: removed_status_list goes here!
75+
76+ command = command + args
77+ res , code = self ._run_cmd (command )
78+
79+ return res , code
80+
81+
6482 def _create_presentation (
6583 self ,
6684 holder_keypath ,
@@ -114,9 +132,45 @@ def issue_credential(self, issuer_keypath, issuer_did, holder_did, content, clea
114132 token = self ._read_token ("credential.signed.json" , clean = clean )
115133 credential = self ._decode_token (token )
116134
135+ if clean :
136+ os .remove (outfile )
137+
117138 return credential , token
118139
119140
141+ def verify_credential (
142+ self ,
143+ token ,
144+ schema = None ,
145+ allowed_issuer = None ,
146+ clean = True
147+ ):
148+ vcfile = self ._dump_token (token , "credential.signed.jwt" )
149+
150+ res , code = self ._verify_credential (
151+ vcfile , schema = schema , allowed_issuer = allowed_issuer
152+ )
153+
154+ if not code == 0 :
155+ raise SSIVerificationError (res )
156+
157+ if "ERROR" in res .upper ():
158+ raise SSIVerificationError (res )
159+
160+ if "FAIL" in res .upper ():
161+ raise SSIVerificationError (res )
162+
163+ if not "SUCCESS" in res .upper ():
164+ raise SSIVerificationError ("Invalid credential" )
165+
166+ credential = self ._decode_token (token )
167+
168+ if clean :
169+ os .remove (vcfile )
170+
171+ return credential
172+
173+
120174 def create_presentation (
121175 self ,
122176 holder_keypath ,
@@ -175,9 +229,16 @@ def verify_presentation(self, holder_did, token, clean=True):
175229 presentation_submission_output ,
176230 vpfile ,
177231 )
232+
178233 if not code == 0 :
179234 raise SSIVerificationError (res )
180235
236+ if "ERROR" in res .upper ():
237+ raise SSIVerificationError (res )
238+
239+ if "FAIL" in res .upper ():
240+ raise SSIVerificationError (res )
241+
181242 result = res .split ("Overall: " )[1 ].split ("\n " )[0 ].upper ()
182243 if not "SUCCESS" in result :
183244 raise SSIVerificationError ("Invalid presentation" )
@@ -236,6 +297,12 @@ def verify_presentation(self, holder_did, token, clean=True):
236297assert pre_credential ["vc" ] == credential_content
237298assert pre_credential == ssi ._decode_token (pre_token )
238299
300+ verified = ssi .verify_credential (
301+ pre_token ,
302+ allowed_issuer = issuer_did_id ,
303+ )
304+ assert verified == pre_credential
305+
239306pre_presentation , presentation_token = ssi .create_presentation (
240307 holder_keypath ,
241308 holder_did_id ,
0 commit comments