Skip to content

Commit

Permalink
feat: credential abstraction (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: Ahmed Moussa <[email protected]>
Signed-off-by: Cristian G <[email protected]>
  • Loading branch information
cristianIOHK and hamada147 committed May 13, 2024
1 parent 503ff23 commit 505e022
Show file tree
Hide file tree
Showing 25 changed files with 835 additions and 611 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import io.iohk.atala.prism.walletsdk.domain.models.Message
import io.iohk.atala.prism.walletsdk.domain.models.PeerDID
import io.iohk.atala.prism.walletsdk.domain.models.PrismDIDInfo
import io.iohk.atala.prism.walletsdk.domain.models.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.VerifiableCredential
import io.iohk.atala.prism.walletsdk.domain.models.StorableCredential
import io.iohk.atala.prism.walletsdk.pluto.CredentialRecovery
import ioiohkatalaprismwalletsdkpluto.data.AvailableClaims
import kotlinx.coroutines.flow.Flow

interface Pluto {
Expand All @@ -31,7 +33,7 @@ interface Pluto {

fun storeMediator(mediator: DID, host: DID, routing: DID)

fun storeCredential(credential: VerifiableCredential)
fun storeCredential(credential: StorableCredential)

fun getAllPrismDIDs(): Flow<List<PrismDIDInfo>>

Expand Down Expand Up @@ -78,5 +80,13 @@ interface Pluto {

fun getAllMediators(): Flow<List<Mediator>>

fun getAllCredentials(): Flow<List<VerifiableCredential>>
fun getAllCredentials(): Flow<List<CredentialRecovery>>

fun insertAvailableClaim(credentialId: String, claim: String)

fun insertAvailableClaims(credentialId: String, claims: Array<String>)

fun getAvailableClaimsByCredentialId(credentialId: String): Flow<Array<AvailableClaims>>

fun getAvailableClaimsByClaim(claim: String): Flow<Array<AvailableClaims>>
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.iohk.atala.prism.walletsdk.domain.buildingblocks

import io.iohk.atala.prism.walletsdk.domain.models.Credential
import io.iohk.atala.prism.walletsdk.domain.models.DID
import io.iohk.atala.prism.walletsdk.domain.models.PrivateKey
import io.iohk.atala.prism.walletsdk.domain.models.VerifiableCredential
import io.iohk.atala.prism.walletsdk.domain.models.StorableCredential
import kotlinx.serialization.json.JsonObject

interface Pollux {
fun parseVerifiableCredential(jwtString: String): VerifiableCredential
fun parseVerifiableCredential(data: String): Credential

fun createRequestCredentialJWT(
subjectDID: DID,
Expand All @@ -17,7 +18,11 @@ interface Pollux {
fun createVerifiablePresentationJWT(
subjectDID: DID,
privateKey: PrivateKey,
credential: VerifiableCredential,
credential: Credential,
requestPresentationJson: JsonObject
): String

fun restoreCredential(restorationIdentifier: String, credentialData: ByteArray): Credential

fun credentialToStorableCredential(credential: Credential): StorableCredential
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.iohk.atala.prism.walletsdk.domain.models

import kotlinx.serialization.Serializable

@Serializable
class Claim(
val key: String,
val value: ClaimType
)

@Serializable
sealed class ClaimType : Comparable<ClaimType> {
data class StringValue(val value: String) : ClaimType()
data class BoolValue(val value: Boolean) : ClaimType()
data class DataValue(val value: ByteArray) : ClaimType()
data class NumberValue(val value: Double) : ClaimType()

override fun compareTo(other: ClaimType): Int {
return when (this) {
is StringValue -> {
if (other is StringValue) {
value.compareTo(other.value)
} else {
throw IllegalArgumentException("Cannot compare different types")
}
}
is NumberValue -> {
if (other is NumberValue) {
value.compareTo(other.value)
} else {
throw IllegalArgumentException("Cannot compare different types")
}
}
else -> throw IllegalArgumentException("Cannot compare non-comparable types")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.iohk.atala.prism.walletsdk.domain.models

abstract interface Credential {
val id: String
val issuer: String
val subject: String?
val claims: Array<Claim>
val properties: Map<String, Any?>
}
Loading

0 comments on commit 505e022

Please sign in to comment.