From 89a57aae8b4b4d5720c292e79a8b3538c9df27d4 Mon Sep 17 00:00:00 2001
From: mikeplotean <mike@walt.id>
Date: Mon, 12 Aug 2024 19:29:04 +0300
Subject: [PATCH] chore: bump waltid dependencies, fix java interface
 implementations

---
 build.gradle.kts                           |  2 +-
 src/main/java/waltid/CustomKeyExample.java |  9 ++---
 src/main/java/waltid/KeysExamples.java     | 38 ++++++++++++++--------
 src/main/java/waltid/RunAll.java           |  4 +--
 4 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/build.gradle.kts b/build.gradle.kts
index 89b7e0d..754153b 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,5 +1,5 @@
 val kotlin_version: String by project
-val waltid_version: String = "0.5.0"
+val waltid_version: String = "0.6.0"
 
 
 plugins {
diff --git a/src/main/java/waltid/CustomKeyExample.java b/src/main/java/waltid/CustomKeyExample.java
index bd3d827..92967ba 100644
--- a/src/main/java/waltid/CustomKeyExample.java
+++ b/src/main/java/waltid/CustomKeyExample.java
@@ -84,13 +84,11 @@ public byte[] javaVerifyRaw(@NotNull byte[] signed, @Nullable byte[] detachedPla
     }
 
     @NotNull
-    @Override
     public JsonElement javaVerifyJws() {
         return null;
     }
 
     @NotNull
-    @Override
     public byte[] javaVerifyRaw() {
         return new byte[0];
     }
@@ -104,14 +102,13 @@ public JsonElement javaVerifyJws(@Language(value = "json") @NotNull String signe
         }
     }
 
-    @NotNull
     @Override
-    public String javaSignJws(@NotNull byte[] plaintext, @NotNull Map<String, String> headers) {
+    public @NotNull String javaSignJws(@NotNull byte[] bytes, @NotNull Map<String, ? extends JsonElement> map) {
         var base64 = Base64.getUrlEncoder();
 
         String myHeaders = base64.encodeToString("{\"my-headers\": \"xyz\"}".getBytes(StandardCharsets.UTF_8));
         String myPayload = base64.encodeToString("{\"my-payload\": \"xyz\"}".getBytes(StandardCharsets.UTF_8));
-        String mySignature = base64.encodeToString(javaSignRaw(plaintext));
+        String mySignature = base64.encodeToString(javaSignRaw(bytes));
 
         return myHeaders + "." + myPayload + "." + mySignature;
     }
@@ -171,6 +168,4 @@ public KeyType javaGetKeyType() {
             default -> throw new IllegalArgumentException("Unknown key type!");
         };
     }
-
-
 }
diff --git a/src/main/java/waltid/KeysExamples.java b/src/main/java/waltid/KeysExamples.java
index 677ccd7..a84d0c8 100644
--- a/src/main/java/waltid/KeysExamples.java
+++ b/src/main/java/waltid/KeysExamples.java
@@ -18,7 +18,7 @@ public class KeysExamples {
     // demonstrating the Java (async) CompletableFuture API.
     // Replace KeyType.Ed25519 with a different KeyType if desired.
 
-    public static void signBlocking() {
+    public static void signBlocking() throws Exception {
         System.out.println("Generating key synchronous...");
         JWKKey k = (JWKKey) JWKKey.Companion.generateBlocking(KeyType.Ed25519, null);
         System.out.println("Sync generated key: " + k);
@@ -45,23 +45,35 @@ public static void signAsync() {
             System.out.println("Async generated key: " + key);
             System.out.println("Signing with key asynchronous...");
 
-            key.signRawAsync(plaintext).thenAccept(signed -> {
-                System.out.println("Signed asynchronous: " + Arrays.toString((byte[]) signed));
-
-                verifyAsync(key, (byte[]) signed, plaintext, "Test async verification");
-            });
+            try {
+                key.signRawAsync(plaintext).thenAccept(signed -> {
+                    System.out.println("Signed asynchronous: " + Arrays.toString((byte[]) signed));
+
+                    try {
+                        verifyAsync(key, (byte[]) signed, plaintext, "Test async verification");
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         });
     }
 
-    public static void verifyAsync(Key key, byte[] signed, byte[] plaintext, String message) {
+    public static void verifyAsync(Key key, byte[] signed, byte[] plaintext, String message) throws Exception {
         key.getPublicKeyAsync().thenAccept(publicKey -> {
-            publicKey.verifyRawAsync(signed, plaintext).thenAccept(result -> {
-                System.out.println("Verification result (" + message + "): " + result);
-            }).join();
+            try {
+                publicKey.verifyRawAsync(signed, plaintext).thenAccept(result -> {
+                    System.out.println("Verification result (" + message + "): " + result);
+                }).join();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }).join();
     }
 
-    public static String exportKey() {
+    public static String exportKey() throws Exception {
         // Other KeyTypes:
         var key2 = JWKKey.Companion.generateBlocking(KeyType.secp256r1, null);
         System.out.println("Export key...");
@@ -76,7 +88,7 @@ public static void importKey(String jwk) throws ExecutionException, InterruptedE
         System.out.println("Import result: " + keyImport);
     }
 
-    public static void runKeyExample() throws ExecutionException, InterruptedException {
+    public static void runKeyExample() throws Exception {
         KeysExamples.signAsync();
         KeysExamples.signBlocking();
 
@@ -85,7 +97,7 @@ public static void runKeyExample() throws ExecutionException, InterruptedExcepti
     }
 
 
-    public static void main(String[] args) throws ExecutionException, InterruptedException {
+    public static void main(String[] args) throws Exception {
         runKeyExample();
     }
 }
diff --git a/src/main/java/waltid/RunAll.java b/src/main/java/waltid/RunAll.java
index 2329e66..3c721e3 100644
--- a/src/main/java/waltid/RunAll.java
+++ b/src/main/java/waltid/RunAll.java
@@ -1,14 +1,12 @@
 package waltid;
 
-import java.util.concurrent.ExecutionException;
-
 import static waltid.CustomKeyExample.runCustomKeyExample;
 import static waltid.DidExamples.runDidExample;
 import static waltid.KeysExamples.runKeyExample;
 import static waltid.VcExamples.runVcExample;
 
 public class RunAll {
-    public static void main(String[] args) throws ExecutionException, InterruptedException {
+    public static void main(String[] args) throws Exception {
         runKeyExample();
         runDidExample();
         runVcExample();