diff --git a/build.gradle.kts b/build.gradle.kts index 89b7e0d..ec0c9fe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ val kotlin_version: String by project -val waltid_version: String = "0.5.0" +val waltid_version: String = "1.0.2407162254-SNAPSHOT" plugins { - kotlin("jvm") version "2.0.0" + kotlin("jvm") version "2.0.20-Beta1" } group = "identity" @@ -16,7 +16,7 @@ tasks.withType().configureEach { repositories { mavenLocal() mavenCentral() - maven { url = uri("https://maven.waltid.dev/releases") } + maven { url = uri("https://maven.waltid.dev/snapshots") } } diff --git a/src/main/java/waltid/KeysExamples.java b/src/main/java/waltid/KeysExamples.java index 677ccd7..56d4e85 100644 --- a/src/main/java/waltid/KeysExamples.java +++ b/src/main/java/waltid/KeysExamples.java @@ -3,12 +3,12 @@ import id.walt.crypto.keys.Key; import id.walt.crypto.keys.KeyType; import id.walt.crypto.keys.jwk.JWKKey; -import kotlin.Result; - import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.concurrent.ExecutionException; +import kotlin.Result; +@SuppressWarnings({"RedundantThrows", "DuplicateThrows"}) public class KeysExamples { private static final byte[] plaintext = "< this is my plaintext>".getBytes(StandardCharsets.UTF_8); @@ -18,12 +18,13 @@ 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); System.out.println("Signing with key synchronous..."); - var signed = (byte[]) k.signRawBlocking(plaintext); + byte[] signed; + signed = (byte[]) k.signRawBlocking(plaintext); System.out.println("Signed synchronous: " + Arrays.toString(signed)); @@ -45,23 +46,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 -> { + 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 +89,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 ExecutionException, InterruptedException, Exception { KeysExamples.signAsync(); KeysExamples.signBlocking(); @@ -85,7 +98,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..6615c3e 100644 --- a/src/main/java/waltid/RunAll.java +++ b/src/main/java/waltid/RunAll.java @@ -8,7 +8,7 @@ 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();