Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Pluto): Add back flows to add reactiveness to the DB #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.{kt,kts}]
ktlint_standard_no_semi = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
5 changes: 5 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ APPLY_FIXES: none
FILTER_REGEX_EXCLUDE: (karma.config.js|polyfill.js|timeout.js)
VALIDATE_ALL_CODEBASE: true
REPOSITORY_DEVSKIM_DISABLE_ERRORS: true
REPOSITORY_CHECKOV_DISABLE_ERRORS: true

DISABLE_LINTERS:
- MARKDOWN_MARKDOWN_LINK_CHECK
- C_CPPLINT
- CPP_CPPLINT
- BASH_SHELLCHECK
- BASH_EXEC
- REPOSITORY_CHECKOV

DISABLE_ERRORS_LINTERS:
- REPOSITORY_CHECKOV
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,78 @@ 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 kotlinx.coroutines.flow.Flow
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
import kotlin.js.JsName

@OptIn(ExperimentalJsExport::class)
@JsExport
interface Pluto {

fun storePrismDID(
fun storePrismDIDAndPrivateKeys(
did: DID,
keyPathIndex: Int,
alias: String?,
privateKeys: List<PrivateKey>,
)

fun storePeerDID(did: DID, privateKeys: Array<PrivateKey>)
fun storePeerDIDAndPrivateKeys(did: DID, privateKeys: List<PrivateKey>)

fun storeDIDPair(host: DID, receiver: DID, name: String)

fun storeMessage(message: Message)

fun storeMessages(messages: Array<Message>)
fun storeMessages(messages: List<Message>)

fun storePrivateKeys(privateKey: PrivateKey, did: DID, keyPathIndex: Int, metaId: String? = null)

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

fun storeCredential(credential: VerifiableCredential)

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

fun getDIDInfoByDID(did: DID): PrismDIDInfo?
fun getDIDInfoByDID(did: DID): Flow<PrismDIDInfo?>

fun getDIDInfoByAlias(alias: String): Array<PrismDIDInfo>
fun getDIDInfoByAlias(alias: String): Flow<List<PrismDIDInfo>>

fun getPrismDIDKeyPathIndex(did: DID): Int?
fun getPrismDIDKeyPathIndex(did: DID): Flow<Int?>

fun getPrismLastKeyPathIndex(): Int
fun getPrismLastKeyPathIndex(): Flow<Int>

fun getAllPeerDIDs(): Array<PeerDID>
fun getAllPeerDIDs(): Flow<List<PeerDID>>

fun getDIDPrivateKeysByDID(did: DID): Array<PrivateKey>?
fun getDIDPrivateKeysByDID(did: DID): Flow<List<PrivateKey?>>

fun getDIDPrivateKeyByID(id: String): PrivateKey?
fun getDIDPrivateKeyByID(id: String): Flow<PrivateKey?>

fun getAllDidPairs(): Array<DIDPair>
fun getAllDidPairs(): Flow<List<DIDPair>>

fun getPairByDID(did: DID): DIDPair?
fun getPairByDID(did: DID): Flow<DIDPair?>

fun getPairByName(name: String): DIDPair?
fun getPairByName(name: String): Flow<DIDPair?>

@JsName("getAllMessages")
fun getAllMessages(): Array<Message>
fun getAllMessages(): Flow<List<Message>>

@JsName("getAllMessagesByDID")
fun getAllMessages(did: DID): Array<Message>
fun getAllMessages(did: DID): Flow<List<Message>>

fun getAllMessagesSent(): Array<Message>
fun getAllMessagesSent(): Flow<List<Message>>

fun getAllMessagesReceived(): Array<Message>
fun getAllMessagesReceived(): Flow<List<Message>>

fun getAllMessagesSentTo(did: DID): Array<Message>
fun getAllMessagesSentTo(did: DID): Flow<List<Message>>

fun getAllMessagesReceivedFrom(did: DID): Array<Message>
fun getAllMessagesReceivedFrom(did: DID): Flow<List<Message>>

fun getAllMessagesOfType(type: String, relatedWithDID: DID?): Array<Message>
fun getAllMessagesOfType(type: String, relatedWithDID: DID?): Flow<List<Message>>

@JsName("getAllMessagesByFromToDID")
fun getAllMessages(from: DID, to: DID): Array<Message>
fun getAllMessages(from: DID, to: DID): Flow<List<Message>>

fun getMessage(id: String): Message?
fun getMessage(id: String): Flow<Message?>

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

fun getAllCredentials(): Array<VerifiableCredential>
fun getAllCredentials(): Flow<List<VerifiableCredential>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import io.iohk.atala.prism.walletsdk.domain.buildingBlocks.Pluto
import io.iohk.atala.prism.walletsdk.domain.models.Secret
import io.iohk.atala.prism.walletsdk.domain.models.SecretMaterialJWK
import io.iohk.atala.prism.walletsdk.domain.models.SecretType
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
class DefaultSecretsResolverImpl(val pluto: Pluto) : SecretsResolver {

@Serializable
Expand All @@ -21,25 +20,28 @@ class DefaultSecretsResolverImpl(val pluto: Pluto) : SecretsResolver {
val d: String? = null,
)

override fun findSecrets(secretIds: Array<String>): Array<String> {
override suspend fun findSecrets(secretIds: Array<String>): Array<String> {
return secretIds.filter {
pluto.getDIDPrivateKeyByID(it) != null
pluto.getDIDPrivateKeyByID(it)
.firstOrNull() != null
}.toTypedArray()
}

override fun getSecret(secretid: String): Secret? {
return pluto.getDIDPrivateKeyByID(secretid)?.let {
Secret(
secretid,
SecretType.JsonWebKey2020,
SecretMaterialJWK(
PrivateJWK(
secretid,
it.keyCurve.curve.toString(),
it.value.base64UrlEncoded,
).toString(),
),
)
}
override suspend fun getSecret(secretid: String): Secret? {
return pluto.getDIDPrivateKeyByID(secretid)
.firstOrNull()
?.let { privateKey ->
return Secret(
secretid,
SecretType.JsonWebKey2020,
SecretMaterialJWK(
PrivateJWK(
secretid,
privateKey.keyCurve.curve.toString(),
privateKey.value.base64UrlEncoded,
).toString(),
),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package io.iohk.atala.prism.walletsdk.mercury.resolvers

import io.iohk.atala.prism.walletsdk.domain.models.Secret
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
interface SecretsResolver {
fun findSecrets(secretIds: Array<String>): Array<String>
fun getSecret(secretId: String): Secret?
suspend fun findSecrets(secretIds: Array<String>): Array<String>
suspend fun getSecret(secretId: String): Secret?
}
Loading