Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpagac authored Jul 12, 2024
2 parents 423388e + e0eb64b commit 4a47243
Show file tree
Hide file tree
Showing 72 changed files with 2,010 additions and 1,050 deletions.
2 changes: 1 addition & 1 deletion docker-compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ MSSQL_DB_PORT=1433

#sqlite | postgres | mssql
DATABASE_ENGINE=postgres
VERSION_TAG=0.4.0
VERSION_TAG=0.5.0
COMPOSE_PROFILES=$DATABASE_ENGINE
9 changes: 5 additions & 4 deletions waltid-applications/waltid-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Manage keys, DIDs, issue W3C Verifiable Credentials, and verify them using the W
## In development

* `git clone https://github.com/walt-id/waltid-identity.git`
* `cd waltid-identity/waltid-cli`
* `../gradlew clean build`
* `cd waltid-identity`
* `./gradlew clean build`
* `cd waltid-applications/waltid-cli`
* `alias waltid="./waltid-cli.sh"` (for running the project)
* `alias waltid="./waltid-cli-development.sh"` (for building and running the project)

Expand Down Expand Up @@ -56,14 +57,14 @@ We are still preparing a nice distribution strategy. It will be available soon.

In the meantime, you can use Gradle to generate the distribution package:

* `cd waltid-identity/waltid-cli`
* `cd waltid-identity/waltid-applications/waltid-cli`
* `../gradlew distZip` or `../gradlew distTar`

A `waltid-cli-1.0.0-SNAPSHOT` file will be created in the `build/distributions` directory.

```bash
$ pwd
.../waltid-identity/waltid-cli
.../waltid-identity/waltid-applications/waltid-cli

$ ls -la build/distributions/
total 67024
Expand Down
4 changes: 2 additions & 2 deletions waltid-applications/waltid-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ kotlin {
api(project(":waltid-libraries:waltid-sdjwt"))
api(project(":waltid-libraries:waltid-openid4vc"))

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0")
implementation("com.google.code.gson:gson:2.11.0")

Expand Down Expand Up @@ -94,7 +94,7 @@ kotlin {
}
val jvmTest by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("com.wolpl.clikt-testkit:clikt-testkit:2.0.0")

implementation("org.junit.jupiter:junit-jupiter-params:5.11.0-M2")
Expand Down
1 change: 1 addition & 0 deletions waltid-applications/waltid-web-wallet/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PORT=7101
NUXT_PUBLIC_ISSUER_CALLBACK_URL=http://localhost:7100
NUXT_PUBLIC_DEMO_WALLET_URL=https://wallet.walt.id
1 change: 1 addition & 0 deletions waltid-applications/waltid-web-wallet/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default defineNuxtConfig({
public: {
projectId: process.env.ProjectId,
issuerCallbackUrl: process.env.IssuerCallbackUrl ?? "http://localhost:7100",
demoWalletUrl: "https://wallet.walt.id",
}
},

Expand Down

Large diffs are not rendered by default.

162 changes: 77 additions & 85 deletions waltid-applications/waltid-web-wallet/src/layouts/default.vue

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions waltid-libraries/waltid-crypto-oci/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ kotlin {
val commonMain by getting {
dependencies {
// JSON
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")

// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
Expand Down Expand Up @@ -103,7 +103,7 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.8.1")

// OCI
implementation("com.oracle.oci.sdk:oci-java-sdk-shaded-full:3.43.2")
implementation("com.oracle.oci.sdk:oci-java-sdk-shaded-full:3.44.1")

// JOSE
implementation("com.nimbusds:nimbus-jose-jwt:9.40")
Expand All @@ -121,7 +121,7 @@ kotlin {
implementation(kotlin("test"))

implementation("org.junit.jupiter:junit-jupiter-api:5.11.0-M2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("org.junit.jupiter:junit-jupiter-params:5.11.0-M2")
}
}
Expand Down
15 changes: 5 additions & 10 deletions waltid-libraries/waltid-crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,17 @@ walt.id identity.

The library provides the following key entities to work with:

- [JWKKey](https://github.com/walt-id/waltid-identity/blob/main/waltid-libraries/waltid-crypto/src/commonMain/kotlin/id/walt/crypto/keys/JWKKey.kt) -
- [JWKKey](https://github.com/walt-id/waltid-identity/blob/main/waltid-libraries/waltid-crypto/src/commonMain/kotlin/id/walt/crypto/keys/jwk/JWKKey.kt) -
an implementation of a local (in-memory) key (private / public)
- [TSEKey](https://github.com/walt-id/waltid-identity/blob/main/waltid-libraries/waltid-crypto/src/commonMain/kotlin/id/walt/crypto/keys/TSEKey.kt) -
- [TSEKey](https://github.com/walt-id/waltid-identity/blob/main/waltid-libraries/waltid-crypto/src/commonMain/kotlin/id/walt/crypto/keys/tse/TSEKey.kt) -
an implementation of a Hashicorp Vault Transit Secrets Engine key (private / public)

- [OCIKey](https://github.com/walt-id/waltid-identity/blob/main/waltid-libraries/waltid-crypto/src/commonMain/kotlin/id/walt/crypto/keys/oci/OCIKeyRestApi.kt) - an implementation of an OCI key (private / public)
### Working with JWKKey

**Create key**

```kotlin
val key = JWKKey.generate(KeyType.Ed25519, JWKKeyMetadata())
val key = JWKKey.generate(KeyType.Ed25519)
```

**Sign**
Expand Down Expand Up @@ -398,7 +398,7 @@ val verificationResult = key.getPublicKey().verifyJws(signature)
- raw

```kotlin
val verificationResult = key.getPublicKey().verifyRaw(signature as ByteArray)
val verificationResult = key.getPublicKey().verifyRaw(signature , payloadString.encodeToByteArray())
```

**Import key**
Expand Down Expand Up @@ -429,11 +429,6 @@ val key = JWKKey.importRawPublicKey(KeyType.Ed25519, bytes, JWKKeyMetadata())
val jwkString = key.exportJWK()
```

- pem

```kotlin
val pemString = key.exportPEM()
```

- JsonObject

Expand Down
6 changes: 3 additions & 3 deletions waltid-libraries/waltid-crypto/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ kotlin {
val commonMain by getting {
dependencies {
// JSON
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")

// Ktor client
implementation("io.ktor:ktor-client-core:$ktor_version")
Expand Down Expand Up @@ -142,7 +142,7 @@ kotlin {
val jvmMain by getting {
dependencies {
//implementation("dev.whyoleg.cryptography:cryptography-jdk:0.1.0")
implementation("com.google.crypto.tink:tink:1.13.0") // for JOSE using Ed25519
implementation("com.google.crypto.tink:tink:1.14.0") // for JOSE using Ed25519

implementation("org.bouncycastle:bcprov-lts8on:2.73.6") // for secp256k1 (which was removed with Java 17)
implementation("org.bouncycastle:bcpkix-lts8on:2.73.6") // PEM import
Expand All @@ -169,7 +169,7 @@ kotlin {
implementation(kotlin("test"))

implementation("org.junit.jupiter:junit-jupiter-api:5.11.0-M2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("org.junit.jupiter:junit-jupiter-params:5.11.0-M2")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class Key {
@JsPromise
@JsExport.Ignore

override fun toString() = "[walt.id CoreCrypto ${if (hasPrivateKey) "private" else "public"} $keyType key]"
override fun toString() = "[walt.id crypto ${if (hasPrivateKey) "private" else "public"} $keyType key]"

@JvmBlocking
@JvmAsync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package id.walt.crypto.keys
import id.walt.crypto.keys.jwk.JWKKey
import id.walt.crypto.keys.oci.OCIKeyRestApi
import id.walt.crypto.keys.tse.TSEKey
import id.walt.crypto.utils.JsonUtils.toJsonElement
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.serialization.json.*
import kotlinx.serialization.serializer
Expand Down Expand Up @@ -50,17 +49,13 @@ object KeyManager {
return function.invoke(generationRequest)
}

fun resolveSerializedKey(jsonString: String): Key = resolveSerializedKey(json = Json.parseToJsonElement(jsonString).jsonObject)
// TODO: return Result<..>
fun resolveSerializedKey(json: JsonObject): Key {
val type = getRegisteredKeyType(json["type"]?.jsonPrimitive?.content ?: error("No type in serialized key"))

val fields = json.filterKeys { it != "type" }
//jwkKey is a stringified json
.mapValues { if (it.value is JsonObject) it.value.toString().toJsonElement() else it.value }

return Json.decodeFromJsonElement(serializer(type), JsonObject(fields)) as Key
}

suspend fun resolveSerializedKey(jsonString: String): Key =
resolveSerializedKey(json = Json.parseToJsonElement(jsonString).jsonObject)

// TODO: return Result<..>
suspend fun resolveSerializedKey(json: JsonObject): Key = json["type"]?.jsonPrimitive?.content?.let {
val type = getRegisteredKeyType(it)
val fields = json.filterKeys { it != "type" }.mapValues { it.value }
Json.decodeFromJsonElement(serializer(type), JsonObject(fields)) as Key
}?.apply { init() } ?: error("No type in serialized key")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package id.walt.crypto.keys.jwk
import id.walt.crypto.keys.JwkKeyMeta
import id.walt.crypto.keys.Key
import id.walt.crypto.keys.KeyType
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.KSerializer
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encodeToString
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.*

expect class JWKKey(jwk: String?) : Key {
override val keyType: KeyType
Expand Down Expand Up @@ -71,3 +76,12 @@ expect class JWKKey(jwk: String?) : Key {
}

}

object JWKKeyJsonFieldSerializer : KSerializer<String?> {
override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
override fun deserialize(decoder: Decoder): String =
Json.encodeToString(decoder.decodeSerializableValue(JsonElement.serializer()))

override fun serialize(encoder: Encoder, value: String?) = encoder.encodeSerializableValue(JsonElement.serializer(),
value?.let { Json.decodeFromString<JsonElement>(it) } ?: JsonNull)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import kotlin.js.json
@Serializable
@SerialName("jwk")
actual class JWKKey actual constructor(
@Serializable(with = JWKKeyJsonFieldSerializer::class)
var jwk: String?,
) : Key() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import id.walt.crypto.keys.KeyManager
import id.walt.crypto.keys.KeySerialization
import id.walt.crypto.keys.KeyType
import id.walt.crypto.keys.jwk.JWKKey
Expand Down Expand Up @@ -41,19 +42,15 @@ class JWKKeyAndDidManagementTest {
assertEquals("jwk", decoded["type"]!!.jsonPrimitive.content)

println("Parsing JWK...")
val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwk = decoded["jwk"]!!.jsonObject
println("JWK is: $jwk")

println("Parsing JWK...")
val jwkObj = Json.parseToJsonElement(jwk).jsonObject
println("Parsed as: $jwkObj")

println("Getting kty, d, crv, kid, x...")
val kty = jwkObj["kty"].toString().removeSurrounding("\"")
val d = jwkObj["d"].toString().removeSurrounding("\"")
val crv = jwkObj["crv"].toString().removeSurrounding("\"")
val kid = jwkObj["kid"].toString().removeSurrounding("\"")
val x = jwkObj["x"].toString().removeSurrounding("\"")
val kty = jwk["kty"].toString().removeSurrounding("\"")
val d = jwk["d"].toString().removeSurrounding("\"")
val crv = jwk["crv"].toString().removeSurrounding("\"")
val kid = jwk["kid"].toString().removeSurrounding("\"")
val x = jwk["x"].toString().removeSurrounding("\"")

println("Checking kty, d, crv, kid, x...")
assertEquals(kty, getKeyTypeMap(it))
Expand Down Expand Up @@ -85,7 +82,7 @@ class JWKKeyAndDidManagementTest {
val testObjJson = Json.encodeToString(testObj)

// sign using newly generated key
val key = KeySerialization.deserializeKey(serializedKey).getOrThrow()
val key = KeyManager.resolveSerializedKey(serializedKey)
val signature = key.signJws(testObjJson.encodeToByteArray())

// verify the signature using public key
Expand All @@ -100,28 +97,28 @@ class JWKKeyAndDidManagementTest {
val testObjJson = Json.encodeToString(testObj)

// sign using newly generated key
val key = KeySerialization.deserializeKey(serializedKey).getOrThrow()
val key = KeyManager.resolveSerializedKey(serializedKey)
val signature = key.signRaw(testObjJson.encodeToByteArray())

assertNotNull(signature)
}

private suspend fun exportJwk(serializedKey: String) {
val decoded = Json.decodeFromString<JsonObject>(serializedKey)
val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwk = decoded["jwk"]!!.jsonObject

val key = KeySerialization.deserializeKey(serializedKey).getOrThrow()
val key = KeyManager.resolveSerializedKey(serializedKey)
val export = key.exportJWK()

assertEquals(jwk, export)
assertEquals(Json.encodeToString(jwk), export)
}

private suspend fun exportJson(serializedKey: String) {
val decoded = Json.decodeFromString<JsonObject>(serializedKey)
val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwk = decoded["jwk"]!!.jsonObject

val key = KeySerialization.deserializeKey(serializedKey).getOrThrow()
val key = KeyManager.resolveSerializedKey(serializedKey)
val export = key.exportJWKObject()
assertEquals(jwk, export.toString())
assertEquals(jwk, export)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private val log = KotlinLogging.logger { }
@SerialName("jwk")
actual class JWKKey actual constructor(
@Suppress("CanBeParameter", "RedundantSuppression")
@Serializable(with = JWKKeyJsonFieldSerializer::class)
var jwk: String?
) : Key() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ class JWKKeyAndDidManagementTest {

assertEquals("jwk", decoded["type"]!!.jsonPrimitive.content)

val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwkObj = Json.parseToJsonElement(jwk).jsonObject
val jwk = decoded["jwk"]!!.jsonObject

val kty = jwkObj["kty"].toString().removeSurrounding("\"")
val d = jwkObj["d"].toString().removeSurrounding("\"")
val crv = jwkObj["crv"].toString().removeSurrounding("\"")
val kid = jwkObj["kid"].toString().removeSurrounding("\"")
val x = jwkObj["x"].toString().removeSurrounding("\"")
val kty = jwk["kty"].toString().removeSurrounding("\"")
val d = jwk["d"].toString().removeSurrounding("\"")
val crv = jwk["crv"].toString().removeSurrounding("\"")
val kid = jwk["kid"].toString().removeSurrounding("\"")
val x = jwk["x"].toString().removeSurrounding("\"")

assertEquals(kty, getKeyTypeMap(it))
assertNotNull(d)
Expand Down Expand Up @@ -91,20 +90,20 @@ class JWKKeyAndDidManagementTest {

private suspend fun exportJwk(serializedKey: String) {
val decoded = Json.decodeFromString<JsonObject>(serializedKey)
val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwk = decoded["jwk"]!!.jsonObject

val key = KeyManager.resolveSerializedKey(serializedKey)
val export = key.exportJWK()

assertEquals(jwk, export)
assertEquals(Json.encodeToString(jwk), export)
}

private suspend fun exportJson(serializedKey: String) {
val decoded = Json.decodeFromString<JsonObject>(serializedKey)
val jwk = decoded["jwk"]!!.jsonPrimitive.content
val jwk = decoded["jwk"]!!.jsonObject

val key = KeyManager.resolveSerializedKey(serializedKey)
val export = key.exportJWKObject()
assertEquals(jwk, export.toString())
assertEquals(jwk, export)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import id.walt.crypto.keys.tse.TSEKey
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
Expand All @@ -32,7 +33,7 @@ class KeySerializationTests {
val decoded = Json.decodeFromString<JsonObject>(serialized)
// then
assertEquals(type, decoded["type"]!!.jsonPrimitive.content)
assertEquals(keyFile.replace("\\s".toRegex(), ""), decoded["jwk"]!!.jsonPrimitive.content)
assertEquals(Json.decodeFromString(keyFile), decoded["jwk"]!!.jsonObject)
}

@ParameterizedTest
Expand Down
Loading

0 comments on commit 4a47243

Please sign in to comment.