From 9ca96d81855104ed17d3b3b9cb90539c52c7be97 Mon Sep 17 00:00:00 2001 From: Philipp Potisk Date: Mon, 15 Jul 2024 11:15:08 +0200 Subject: [PATCH] Added RunAll config for Java --- README.md | 14 +++++--- settings.gradle.kts | 2 +- src/main/java/waltid/CustomKeyExample.java | 37 +++++++++++----------- src/main/java/waltid/DidExamples.java | 11 +++++-- src/main/java/waltid/KeysExamples.java | 11 +++++-- src/main/java/waltid/RunAll.java | 17 ++++++++++ src/main/java/waltid/VcExamples.java | 8 +++-- src/main/kotlin/RunAll.kt | 30 ++++++++++-------- 8 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 src/main/java/waltid/RunAll.java diff --git a/README.md b/README.md index ababe3c..bf69bb3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

walt.id identity examples

-

This repository contains a few examples to quickly get you started with the waltid-identity code API. +

This repository contains a few examples to quickly get you started with the waltid-identity SDK.

@@ -30,22 +30,26 @@ For a selection of examples, please take a look at the following table: Follow the link to view the associated code example. -You can also view samples in the test directories of the [identity repository](https://github.com/walt-id/waltid-identity). +You can also view samples in the test directories of +the [identity repository](https://github.com/walt-id/waltid-identity). ## Running the examples We're writing our projects with Gradle in mind; however, you can absolutely also use Apache Maven. -Use the repository `https://maven.waltid.dev/releases`. For a web interface to list available artifacts and their current versions, +Use the repository `https://maven.waltid.dev/releases`. For a web interface to list available artifacts and their +current versions, visit https://maven.waltid.dev/#/releases/id/walt in your web browser. If you use Gradle with e.g., IntelliJ IDEA, you can simply run the examples by right-clicking them. ## Join the community -* Connect and get the latest updates: Discord | +* Connect and get the latest updates: + Discord | Newsletter | YouTube | Twitter -* Get help, request features and report bugs: GitHub +* Get help, request features and report bugs: + GitHub Discussions ## License diff --git a/settings.gradle.kts b/settings.gradle.kts index 37f15e2..b01c612 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "identity-test" +rootProject.name = "waltid-examples" diff --git a/src/main/java/waltid/CustomKeyExample.java b/src/main/java/waltid/CustomKeyExample.java index 4abcd7d..bd3d827 100644 --- a/src/main/java/waltid/CustomKeyExample.java +++ b/src/main/java/waltid/CustomKeyExample.java @@ -26,6 +26,23 @@ public CustomKeyExample(String xyz) { this._xyz = xyz; } + public static void runCustomKeyExample() { + var key = new CustomKeyExample("abc"); + System.out.println("A type: " + key.getKeyType()); + + var plaintext = "plaintext".getBytes(StandardCharsets.UTF_8); + System.out.println("Plaintext: " + new String(plaintext, StandardCharsets.UTF_8)); + + var signed = (byte[]) key.javaSignRaw(plaintext); + System.out.println("Stub signed: " + new String(signed, StandardCharsets.UTF_8)); + + var verify = key.javaVerifyRaw(signed, plaintext); + System.out.println("Stub verified: " + new String(verify, StandardCharsets.UTF_8)); + } + + public static void main(String[] args) { + runCustomKeyExample(); + } private byte[] reverseArray(byte[] arr) { for (int i = 0; i < arr.length / 2; i++) { @@ -94,7 +111,7 @@ public String javaSignJws(@NotNull byte[] plaintext, @NotNull Map < (_| | | | | | | |_) | | __/\\__ \\\n" + - " \\_/\\_/ \\__,_|_|\\__(_)_|\\__,_| \\___/_/\\_\\__,_|_| |_| |_| .__/|_|\\___||___/\n" + - " | | \n" + - " |_| ") + println( + " _ _ _ _ _ \n" + + " | | | (_) | | | | \n" + + " __ ____ _| | |_ _ __| | _____ ____ _ _ __ ___ _ __ | | ___ ___ \n" + + " \\ \\ /\\ / / _` | | __| | |/ _` | / _ \\ \\/ / _` | '_ ` _ \\| '_ \\| |/ _ \\/ __|\n" + + " \\ V V / (_| | | |_ _| | (_| | | __/> < (_| | | | | | | |_) | | __/\\__ \\\n" + + " \\_/\\_/ \\__,_|_|\\__(_)_|\\__,_| \\___/_/\\_\\__,_|_| |_| |_| .__/|_|\\___||___/\n" + + " | | \n" + + " |_| " + ) // Crypto println("create_ed25519() ----------------------------------------------------------------------------------------") @@ -37,15 +41,15 @@ suspend fun main() { println("create_ed25519() ----------------------------------------------------------------------------------------") create_ed25519() - println("import_ed25519_jwk() ----------------------------------------------------------------------------------------") + println("import_ed25519_jwk() ------------------------------------------------------------------------------------") import_ed25519_jwk() println("import_rsa_jwk() ----------------------------------------------------------------------------------------") import_rsa_jwk() println("import_rsa_raw() ----------------------------------------------------------------------------------------") // FIXME import_rsa_raw() - println("import_secp256k1_jwk() ----------------------------------------------------------------------------------------") + println("import_secp256k1_jwk() ----------------------------------------------------------------------------------") import_secp256k1_jwk() - println("import_secp256r1_jwk() ----------------------------------------------------------------------------------------") + println("import_secp256r1_jwk() ----------------------------------------------------------------------------------") import_secp256r1_jwk() // DIDs