@@ -47,37 +47,58 @@ public Object list(CredentialFilter kargs) throws IOException, InterruptedExcept
4747 return Utils .fromJson (response .body (), Object .class );
4848 }
4949
50- public Optional <Object > get (String said ) throws IOException , InterruptedException , LibsodiumException {
51- return this .get (said , false );
50+ /**
51+ * Get a credential as raw CESR string.
52+ */
53+ public Optional <String > get (String said ) throws IOException , InterruptedException , LibsodiumException {
54+ return this .getCESR (said );
5255 }
5356
5457 /**
55- * Get a credential
56- *
57- * @param said - SAID of the credential
58- * @param includeCESR - Optional flag export the credential in CESR format
59- * @return Optional containing the credential if found, or empty if not found.
60- * Returns String (raw CESR text) when includeCESR=true,
61- * or Object (parsed JSON) when includeCESR=false
58+ * Get a credential as parsed JSON (Object) or raw CESR string depending on includeCESR.
6259 */
6360 public Optional <Object > get (String said , boolean includeCESR ) throws IOException , InterruptedException , LibsodiumException {
61+ if (includeCESR ) {
62+ // For backward compatibility, but prefer getCESR for type safety
63+ Optional <String > cesr = getCESR (said );
64+ return cesr .map (s -> (Object ) s );
65+ } else {
66+ return getJson (said );
67+ }
68+ }
69+
70+ /**
71+ * Get a credential as raw CESR string.
72+ */
73+ public Optional <String > getCESR (String said ) throws IOException , InterruptedException , LibsodiumException {
6474 final String path = "/credentials/" + said ;
6575 final String method = "GET" ;
66-
6776 Map <String , String > extraHeaders = new LinkedHashMap <>();
68- if (includeCESR ) {
69- extraHeaders .put ("Accept" , "application/json+cesr" );
70- } else {
71- extraHeaders .put ("Accept" , "application/json" );
77+ extraHeaders .put ("Accept" , "application/json+cesr" );
78+
79+ HttpResponse <String > response = this .client .fetch (path , method , null , extraHeaders );
80+
81+ if (response .statusCode () == java .net .HttpURLConnection .HTTP_NOT_FOUND ) {
82+ return Optional .empty ();
7283 }
84+ return Optional .of (response .body ());
85+ }
86+
87+ /**
88+ * Get a credential as parsed JSON (Object).
89+ */
90+ private Optional <Object > getJson (String said ) throws IOException , InterruptedException , LibsodiumException {
91+ final String path = "/credentials/" + said ;
92+ final String method = "GET" ;
93+ Map <String , String > extraHeaders = new LinkedHashMap <>();
94+ extraHeaders .put ("Accept" , "application/json" );
7395
7496 HttpResponse <String > response = this .client .fetch (path , method , null , extraHeaders );
75-
97+
7698 if (response .statusCode () == java .net .HttpURLConnection .HTTP_NOT_FOUND ) {
7799 return Optional .empty ();
78100 }
79-
80- return Optional .of (includeCESR ? response .body () : Utils .fromJson (response .body (), Object .class ));
101+ return Optional .of (Utils .fromJson (response .body (), Object .class ));
81102 }
82103
83104 /**
@@ -262,26 +283,23 @@ public RevokeCredentialResult revoke(String name, String said, String datetime)
262283 /**
263284 * Verify a credential and issuing event
264285 *
265- * @param acdc ACDC to process and verify
266- * @param iss Issuing event for ACDC in TEL
267- * @param acdcAtc Optional attachment string to be verified against the credential
268- * @param issAtc Optional attachment string to be verified against the issuing event
286+ * @param options CredentialVerifyOptions containing all verification parameters
269287 * @return Operation containing the verification result
270288 */
271- public Operation <?> verify (Serder acdc , Serder iss , String acdcAtc , String issAtc ) throws IOException , InterruptedException , LibsodiumException {
289+ public Operation <?> verify (CredentialVerifyOptions options ) throws IOException , InterruptedException , LibsodiumException {
272290 final String path = "/credentials/verify" ;
273291 final String method = "POST" ;
274292
275293 Map <String , Object > body = new LinkedHashMap <>();
276- body .put ("acdc" , acdc .getKed ());
277- body .put ("iss" , iss .getKed ());
294+ body .put ("acdc" , options . getAcdc () .getKed ());
295+ body .put ("iss" , options . getIss () .getKed ());
278296
279- if (acdcAtc != null && !acdcAtc .isEmpty ()) {
280- body .put ("acdcAtc" , acdcAtc );
297+ if (options . getAcdcAtc () != null && !options . getAcdcAtc () .isEmpty ()) {
298+ body .put ("acdcAtc" , options . getAcdcAtc () );
281299 }
282300
283- if (issAtc != null && !issAtc .isEmpty ()) {
284- body .put ("issAtc" , issAtc );
301+ if (options . getIssAtc () != null && !options . getIssAtc () .isEmpty ()) {
302+ body .put ("issAtc" , options . getIssAtc () );
285303 }
286304
287305 HttpResponse <String > response = this .client .fetch (path , method , body );
0 commit comments