Skip to content

Commit

Permalink
fix: agent start and mediation achieved (#60)
Browse files Browse the repository at this point in the history
fix: agent start
  • Loading branch information
cristianIOHK authored May 3, 2023
1 parent b0086a1 commit e24f67a
Show file tree
Hide file tree
Showing 40 changed files with 1,237 additions and 244 deletions.
185 changes: 185 additions & 0 deletions apollo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target

val currentModuleName: String = "WalletApollo"
val os: OperatingSystem = OperatingSystem.current()
val apolloVersion = project.property("apollo_version")
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization") version "1.7.20"
id("com.android.library")
id("org.jetbrains.dokka")
}

kotlin {
android {
publishAllLibraryVariants()
}

jvm {
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}

js(IR) {
this.moduleName = currentModuleName
this.binaries.library()
this.useCommonJs()
this.compilations["main"].packageJson {
this.version = rootProject.version.toString()
}
this.compilations["test"].packageJson {
this.version = rootProject.version.toString()
}
browser {
this.webpackTask {
this.output.library = currentModuleName
this.output.libraryTarget = Target.VAR
}
this.testTask {
this.useKarma {
this.useChromeHeadless()
}
}
}
nodejs {
this.testTask {
this.useKarma {
this.useChromeHeadless()
}
}
}
}

sourceSets {

val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("io.iohk.atala.prism:base-asymmetric-encryption:$apolloVersion")
implementation("io.iohk.atala.prism:ecdsa:$apolloVersion")
implementation("com.nimbusds:nimbus-jose-jwt:9.31")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation(project(":domain"))
}
}
val commonTest by getting {
dependencies {
implementation("org.slf4j:slf4j-simple:1.7.30")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
implementation("io.iohk.atala.prism:ecdsa:$apolloVersion")
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
api(kotlin("stdlib-jdk8"))
api(kotlin("reflect"))
}
}
val jvmTest by getting {
dependencies {
implementation("junit:junit:4.13.2")
}
}
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
}
}
val androidTest by getting {
dependencies {
implementation("junit:junit:4.13.2")
}
}
val jsMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-nodejs:0.0.7")
implementation("org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20")
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:1.7.20")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
implementation(npm("stream-browserify", "3.0.0"))
implementation(npm("buffer", "6.0.3"))
}
}
val jsTest by getting

all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
}
}

android {
compileSdk = 32
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 21
targetSdk = 32
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
/**
* Because Software Components will not be created automatically for Maven publishing from
* Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.
* disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new
* publishing DSL.
*/
publishing {
multipleVariants {
withSourcesJar()
withJavadocJar()
allVariants()
}
}
}

ktlint {
filter {
exclude("build/generated-src/**")
exclude("**/generated/**")
exclude("**/generated-src/**")
exclude {
it.file.path.contains("generated-src")
}
exclude {
it.file.path.contains("generated")
}
}
}

// Dokka implementation
tasks.withType<DokkaTask> {
moduleName.set(project.name)
moduleVersion.set(rootProject.version.toString())
description = """
This is a Kotlin Multiplatform Wallet-Core-SDK Library
""".trimIndent()
dokkaSourceSets {
// TODO: Figure out how to include files to the documentations
named("commonMain") {
includes.from("Module.md", "docs/Module.md")
}
}
}

// afterEvaluate {
// tasks.withType<AbstractTestTask> {
// testLogging {
// events("passed", "skipped", "failed", "standard_out", "standard_error")
// showExceptions = true
// showStackTraces = true
// }
// }
// }
1 change: 1 addition & 0 deletions atala-prism-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ kotlin {
implementation("io.iohk.atala.prism.apollo:ecdsa:$apolloVersion")
implementation("io.iohk.atala.prism.apollo:hashing:$apolloVersion")
implementation("io.iohk.atala.prism.apollo:uuid:$apolloVersion")
implementation("io.iohk.atala.prism.apollo:multibase:$apolloVersion")

implementation("pro.streem.pbandk:pbandk-runtime:0.14.2")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.iohk.atala.prism.walletsdk.domain.models

import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp

actual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = io.ktor.client.HttpClient(OkHttp) {
config(this)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import io.iohk.atala.prism.walletsdk.domain.models.DIDResolver
import io.iohk.atala.prism.walletsdk.domain.models.DIDUrl
import io.iohk.atala.prism.walletsdk.domain.models.KeyCurve
import io.iohk.atala.prism.walletsdk.domain.models.KeyPair
import io.iohk.atala.prism.walletsdk.domain.models.OctetPublicKey
import io.iohk.atala.prism.walletsdk.domain.models.PublicKey
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
Expand Down Expand Up @@ -66,17 +67,17 @@ internal class CastorShared {

coreProperties.add(
DIDDocument.Authentication(
urls = arrayOf(didString),
urls = arrayOf(),
verificationMethods = peerDIDDocument.authentication.map {
fromVerificationMethodPeerDID(didString, it)
fromVerificationMethodPeerDID(it.id, it)
}.toTypedArray(),
),
)
coreProperties.add(
DIDDocument.KeyAgreement(
urls = arrayOf(didString),
urls = arrayOf(),
verificationMethods = peerDIDDocument.keyAgreement.map {
fromVerificationMethodPeerDID(didString, it)
fromVerificationMethodPeerDID(it.id, it)
}.toTypedArray(),
),
)
Expand Down Expand Up @@ -296,6 +297,10 @@ internal class CastorShared {
}
}

private fun octetPublicKey(keyPair: KeyPair): OctetPublicKey {
return OctetPublicKey(crv = keyPair.keyCurve.curve.value, x = keyPair.publicKey.value.base64UrlEncoded)
}

@JvmStatic
@Throws(CastorError.InvalidKeyError::class)
fun createPeerDID(
Expand All @@ -306,33 +311,29 @@ internal class CastorShared {
val signingKeys: MutableList<VerificationMaterialAuthentication> = mutableListOf()

keyPairs.forEach {
if (it.keyCurve == null) {
throw CastorError.InvalidKeyError()
} else {
when (it.keyCurve.curve) {
Curve.X25519 -> {
encryptionKeys.add(
VerificationMaterialAgreement(
format = VerificationMaterialFormatPeerDID.MULTIBASE,
value = it.publicKey.value.decodeToString(),
type = VerificationMethodTypeAgreement.X25519_KEY_AGREEMENT_KEY_2020,
),
)
}

Curve.ED25519 -> {
signingKeys.add(
VerificationMaterialAuthentication(
format = VerificationMaterialFormatPeerDID.MULTIBASE,
value = it.publicKey.value.decodeToString(),
type = VerificationMethodTypeAuthentication.ED25519_VERIFICATION_KEY_2020,
),
)
}

else -> {
throw CastorError.InvalidKeyError()
}
when (it.keyCurve.curve) {
Curve.X25519 -> {
val octetString = Json.encodeToString(octetPublicKey(it))
encryptionKeys.add(
VerificationMaterialAgreement(
format = VerificationMaterialFormatPeerDID.JWK,
value = octetString,
type = VerificationMethodTypeAgreement.JSON_WEB_KEY_2020,
),
)
}
Curve.ED25519 -> {
val octetString = Json.encodeToString(octetPublicKey(it))
signingKeys.add(
VerificationMaterialAuthentication(
format = VerificationMaterialFormatPeerDID.JWK,
value = octetString,
type = VerificationMethodTypeAuthentication.JSON_WEB_KEY_2020,
),
)
}
else -> {
throw CastorError.InvalidKeyError()
}
}
}
Expand All @@ -354,7 +355,7 @@ internal class CastorShared {
accept = it.serviceEndpoint.accept?.asList() ?: listOf(),
).toDict().toJsonElement(),
)
}.first(),
}.firstOrNull(),
)

return DIDParser.parse(peerDID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface Mercury {

suspend fun sendMessage(message: Message): ByteArray?

suspend fun sendMessageParseMessage(message: Message): Message?
suspend fun sendMessageParseResponse(message: Message): Message?
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.iohk.atala.prism.walletsdk.prismagent.helpers
package io.iohk.atala.prism.walletsdk.domain.models

import io.iohk.atala.prism.walletsdk.domain.models.HttpResponse
import io.iohk.atala.prism.walletsdk.prismagent.shared.KeyValue
import io.ktor.client.HttpClient as KtorClient

Expand All @@ -9,8 +8,8 @@ interface Api {
suspend fun request(
httpMethod: String,
url: String,
urlParameters: Array<KeyValue>,
httpHeaders: Array<KeyValue>,
urlParameters: Array<KeyValue> = emptyArray(),
httpHeaders: Array<KeyValue> = emptyArray(),
body: Any?
): HttpResponse
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.iohk.atala.prism.walletsdk.prismagent.helpers
package io.iohk.atala.prism.walletsdk.domain.models

import io.iohk.atala.prism.walletsdk.domain.models.HttpResponse
import io.iohk.atala.prism.walletsdk.prismagent.shared.KeyValue
import io.iohk.atala.prism.walletsdk.prismagent.shared.PrismShared
import io.ktor.client.HttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ data class DIDUrl @JvmOverloads constructor(
result = 31 * result + (fragment?.hashCode() ?: 0)
return result
}

override fun toString(): String {
return string()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.iohk.atala.prism.walletsdk.domain.models

import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig

expect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.iohk.atala.prism.walletsdk.domain.models

import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.Serializable

@Serializable
data class OctetPublicKey
@JvmOverloads
constructor(@EncodeDefault val kty: String = "OKP", val crv: String, val x: String)

@Serializable
data class OctetPrivateKey(val kty: String, val crv: String, val x: String, val d: String)
Loading

0 comments on commit e24f67a

Please sign in to comment.