@@ -200,6 +200,39 @@ public CompletionStage<AccessGrant> issue(final URI type, final URI agent, final
200200 });
201201 }
202202
203+ /**
204+ * Verify an access grant or request.
205+ *
206+ * @param accessGrant the access grant to verify
207+ * @return the next stage of completion containing the resulting credential
208+ */
209+ public CompletionStage <VerificationResponse > verify (final AccessGrant accessGrant ) {
210+ return v1Metadata ().thenCompose (metadata -> {
211+
212+ final Map <String , Object > presentation = new HashMap <>();
213+ presentation .put (VERIFIABLE_CREDENTIAL , accessGrant );
214+
215+ final Request req = Request .newBuilder (metadata .verifyEndpoint )
216+ .header (CONTENT_TYPE , APPLICATION_JSON )
217+ .POST (Request .BodyPublishers .ofByteArray (serialize (presentation ))).build ();
218+
219+ return client .send (req , Response .BodyHandlers .ofInputStream ())
220+ .thenApply (res -> {
221+ try (final InputStream input = res .body ()) {
222+ final int status = res .statusCode ();
223+ if (isSuccess (status )) {
224+ return processVerificationResult (input );
225+ }
226+ throw new AccessGrantException ("Unable to perform Access Grant verify: HTTP error " + status ,
227+ status );
228+ } catch (final IOException ex ) {
229+ throw new AccessGrantException (
230+ "Unexpected I/O exception while verifying Access Grant" , ex );
231+ }
232+ });
233+ });
234+ }
235+
203236 /**
204237 * Perform an Access Grant query.
205238 *
@@ -339,6 +372,10 @@ AccessGrant processVerifiableCredential(final InputStream input, final Set<Strin
339372 }
340373 }
341374
375+ VerificationResponse processVerificationResult (final InputStream input ) throws IOException {
376+ return jsonService .fromJson (input , VerificationResponse .class );
377+ }
378+
342379 List <AccessGrant > processQueryResponse (final InputStream input , final Set <String > validTypes ) throws IOException {
343380 final Map <String , Object > data = jsonService .fromJson (input ,
344381 new HashMap <String , Object >(){}.getClass ().getGenericSuperclass ());
@@ -546,4 +583,24 @@ static boolean isAccessRequest(final URI type) {
546583 return "SolidAccessRequest" .equals (type .toString ()) || ACCESS_REQUEST .equals (type );
547584
548585 }
586+
587+ /**
588+ * A data objects for verification responses.
589+ */
590+ public static class VerificationResponse {
591+ /**
592+ * The verification checks that were performed.
593+ */
594+ public List <String > checks ;
595+
596+ /**
597+ * The verification warnings that were discovered.
598+ */
599+ public List <String > warnings ;
600+
601+ /**
602+ * The verification errors that were discovered.
603+ */
604+ public List <String > errors ;
605+ }
549606}
0 commit comments