Skip to content

Commit

Permalink
feat: receive and process presentation request (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Moussa <[email protected]>
  • Loading branch information
cristianIOHK authored Jan 10, 2024
1 parent 55dafc2 commit 1194d11
Show file tree
Hide file tree
Showing 58 changed files with 735 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: true

env:
JAVA_VERSION: 11
JAVA_VERSION: 17
NODEJS_VERSION: 16.17.0
ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defaults:
shell: bash

env:
JAVA_VERSION: 11
JAVA_VERSION: 17
NODEJS_VERSION: 16.17.0
ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 11
java-version: 17

- uses: crazy-max/ghaction-import-gpg@v5
id: import_gpg
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Atala Prism Wallet SDK - Kotlin Multiplatform (Android/JVM)

[![Kotlin](https://img.shields.io/badge/kotlin-1.9.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.22-blue.svg?logo=kotlin)](http://kotlinlang.org)
![android](https://camo.githubusercontent.com/b1d9ad56ab51c4ad1417e9a5ad2a8fe63bcc4755e584ec7defef83755c23f923/687474703a2f2f696d672e736869656c64732e696f2f62616467652f706c6174666f726d2d616e64726f69642d3645444238442e7376673f7374796c653d666c6174)
![jvm](https://camo.githubusercontent.com/700f5dcd442fd835875568c038ae5cd53518c80ae5a0cf12c7c5cf4743b5225b/687474703a2f2f696d672e736869656c64732e696f2f62616467652f706c6174666f726d2d6a766d2d4442343133442e7376673f7374796c653d666c6174)

Expand Down Expand Up @@ -43,7 +43,7 @@ To get started with the Atala PRISM kotlin multiplatform SDK, you can set up the

- Android: API level 21 and above.
- Kotlin 1.9.10 or later.
- JVM: 11 or later.
- JVM: 17 or later.

### Integrating the SDK in an existing project

Expand Down
24 changes: 13 additions & 11 deletions atala-prism-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val apolloVersion = project.property("apollo_version")
val didpeerVersion = project.property("didpeer_version")

plugins {
id("com.squareup.sqldelight")
id("app.cash.sqldelight") version "2.0.1"
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
Expand Down Expand Up @@ -39,7 +39,7 @@ koverReport {
}

kotlin {
android {
androidTarget {
publishAllLibraryVariants()
}

Expand Down Expand Up @@ -84,11 +84,11 @@ kotlin {
exclude("com.google.protobuf")
}

implementation("com.squareup.sqldelight:coroutines-extensions:1.5.5")
implementation("app.cash.sqldelight:coroutines-extensions:2.0.1")

api("org.lighthousegames:logging:1.1.2")

implementation("io.iohk.atala.prism.anoncredskmp:anoncreds-kmp:0.3.4")
implementation("io.iohk.atala.prism.anoncredskmp:anoncreds-kmp:0.4.2")
implementation("com.ionspin.kotlin:bignum:0.3.8")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
}
Expand All @@ -104,15 +104,15 @@ kotlin {
val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:2.3.4")
implementation("com.squareup.sqldelight:sqlite-driver:1.5.5")
implementation("app.cash.sqldelight:sqlite-driver:2.0.1")
}
}
val jvmTest by getting
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("io.ktor:ktor-client-okhttp:2.3.4")
implementation("com.squareup.sqldelight:android-driver:1.5.5")
implementation("app.cash.sqldelight:android-driver:2.0.1")
}
}
val androidInstrumentedTest by getting {
Expand All @@ -139,11 +139,11 @@ kotlin {
}

android {
compileSdk = 32
compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 21
targetSdk = 32
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -173,9 +173,11 @@ android {
}

sqldelight {
database("PrismPlutoDb") {
packageName = "io.iohk.atala.prism.walletsdk"
sourceFolders = listOf("sqldelight")
databases {
create("PrismPlutoDb") {
packageName.set("io.iohk.atala.prism.walletsdk")
srcDirs.setFrom("src/commonMain/sqldelight")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ actual object Platform {
*
* @see PlatformType
*/
actual val type: PlatformType
get() = PlatformType.ANDROID
actual val type: PlatformType = PlatformType.ANDROID
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.iohk.atala.prism.walletsdk.pluto.data

import android.content.Context
import com.squareup.sqldelight.android.AndroidSqliteDriver
import com.squareup.sqldelight.db.SqlDriver
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import io.iohk.atala.prism.walletsdk.PrismPlutoDb
import io.iohk.atala.prism.walletsdk.domain.models.PlutoError

Expand All @@ -11,11 +11,11 @@ import io.iohk.atala.prism.walletsdk.domain.models.PlutoError
*/
actual class DbConnection actual constructor() {
actual var driver: SqlDriver? = null
actual suspend fun connectDb(context: Any?): PrismPlutoDb {
actual suspend fun connectDb(context: Any?): SqlDriver {
val androidContext: Context = (context as? Context) ?: throw PlutoError.DatabaseContextError()
val driver = AndroidSqliteDriver(PrismPlutoDb.Schema, androidContext, "prism.db")
this.driver = driver
return PrismPlutoDb(driver)
return driver
}
}

Expand All @@ -25,7 +25,8 @@ actual class DbConnection actual constructor() {
actual val SqlDriver.isConnected: Boolean
get() {
try {
return this.executeQuery(null, "SELECT 1", 0).next()
return this.execute(null, "SELECT 1", 0).value == 1L
// return this.executeQuery(null, "SELECT 1", 0).next()
} catch (ex: Exception) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import io.iohk.atala.prism.walletsdk.domain.models.StorableCredential
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.StorableKey
import io.iohk.atala.prism.walletsdk.pluto.CredentialRecovery
import io.iohk.atala.prism.walletsdk.pluto.data.AvailableClaims
import io.iohk.atala.prism.walletsdk.pollux.models.CredentialRequestMeta
import ioiohkatalaprismwalletsdkpluto.data.AvailableClaims
import kotlinx.coroutines.flow.Flow

/**
Expand Down Expand Up @@ -67,12 +67,12 @@ interface Pluto {
/**
* Stores the private key along with additional information.
*
* @param privateKey The private key to store. Must implement the [StorableKey] interface.
* @param storableKey The private key to store. Must implement the [StorableKey] interface.
* @param did The DID associated with the private key.
* @param keyPathIndex The key path index.
* @param metaId The optional metadata ID.
*/
fun storePrivateKeys(privateKey: StorableKey, did: DID, keyPathIndex: Int, metaId: String? = null)
fun storePrivateKeys(storableKey: StorableKey, did: DID, keyPathIndex: Int, metaId: String? = null)

/**
* Stores a mediator in the system.
Expand All @@ -86,9 +86,9 @@ interface Pluto {
/**
* Stores a credential in the system.
*
* @param credential The credential to store. It must implement the [StorableCredential] interface.
* @param storableCredential The credential to store. It must implement the [StorableCredential] interface.
*/
fun storeCredential(credential: StorableCredential)
fun storeCredential(storableCredential: StorableCredential)

/**
* Stores a link secret in the system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import anoncreds_wrapper.CredentialOffer
import anoncreds_wrapper.CredentialRequest
import anoncreds_wrapper.CredentialRequestMetadata
import anoncreds_wrapper.LinkSecret
import anoncreds_wrapper.Presentation
import anoncreds_wrapper.Schema
import io.iohk.atala.prism.walletsdk.domain.models.AttachmentDescriptor
import io.iohk.atala.prism.walletsdk.domain.models.Credential
import io.iohk.atala.prism.walletsdk.domain.models.CredentialType
import io.iohk.atala.prism.walletsdk.domain.models.DID
import io.iohk.atala.prism.walletsdk.domain.models.StorableCredential
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.PrivateKey
import io.iohk.atala.prism.walletsdk.pollux.models.AnonCredential
import io.iohk.atala.prism.walletsdk.prismagent.protocols.proofOfPresentation.RequestPresentation
import kotlinx.serialization.json.JsonObject

/**
Expand Down Expand Up @@ -80,6 +84,12 @@ interface Pollux {
requestPresentationJson: JsonObject
): String

suspend fun createVerifiablePresentationAnoncred(
request: RequestPresentation,
credential: AnonCredential,
linkSecret: LinkSecret
): Presentation

/**
* Restores a credential using the provided restoration identifier and credential data.
*
Expand Down Expand Up @@ -113,4 +123,6 @@ interface Pollux {
* @return The credential definition.
*/
suspend fun getCredentialDefinition(id: String): CredentialDefinition

suspend fun getSchema(schemaId: String): Schema
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ constructor(
class InvalidKeyCurve(
invalidCurve: String
) : ApolloError(
"Invalid key curve $invalidCurve. Valid options are: ${
Curve.values().map { it.value }.toTypedArray().joinToString(", ")
}"
message = "Invalid key curve $invalidCurve. Valid options are: ${Curve.entries.map { it.value }.toTypedArray().joinToString(", ")}"
) {
override val code: Int
get() = 14
Expand Down Expand Up @@ -240,9 +238,7 @@ constructor(
class InvalidKeyType(
invalidType: String
) : ApolloError(
"Invalid key type $invalidType. Valid options are: ${
KeyTypes.values().map { it.type }.toTypedArray().joinToString(", ")
}"
message = "Invalid key type $invalidType. Valid options are: ${KeyTypes.values().map { it.type }.toTypedArray().joinToString(", ")}"
) {
override val code: Int
get() = 15
Expand Down Expand Up @@ -560,7 +556,7 @@ constructor(
customMessage: String? = null,
customUnderlyingErrors: Array<Error>
) : MercuryError(
"DIDComm error has occurred with message: $customMessage\nErrors: ${
message = "DIDComm error has occurred with message: $customMessage\nErrors: ${
customUnderlyingErrors.joinToString(
separator = "\n"
) { it.errorDescription ?: "" }
Expand Down Expand Up @@ -649,7 +645,7 @@ constructor(
*
* @see PlutoError
*/
class DatabaseConnectionError : PlutoError("Database connection error") {
class DatabaseConnectionError(message: String? = "Database connection error") : PlutoError(message) {
override val code: Int
get() = 46
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class CredentialType(val type: String) {
ANONCREDS_OFFER("anoncreds/[email protected]"),
ANONCREDS_REQUEST("anoncreds/[email protected]"),
ANONCREDS_ISSUE("anoncreds/[email protected]"),
ANONCREDS_PROOF_REQUEST("anoncreds/[email protected]"),
Unknown("Unknown")
}

Expand Down
Loading

0 comments on commit 1194d11

Please sign in to comment.