Skip to content

Commit

Permalink
feat(agent): add mediation and ability to send messages
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-frade-iohk committed Feb 16, 2023
1 parent f8b69c1 commit f7b5d7f
Show file tree
Hide file tree
Showing 92 changed files with 1,277 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ actual class LongFormPrismDIDResolver(
override suspend fun resolve(didString: String): DIDDocument {
return CastorShared.resolveLongFormPrismDID(
apollo = apollo,
didString = didString
didString = didString,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object DIDUrlParser {
did,
listener.path ?: emptyArray(),
listener.query,
listener.fragment
listener.fragment,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.iohk.atala.prism.walletsdk.castor.io.iohk.atala.prism.walletsdk.castor.did.prismdid
package io.iohk.atala.prism.walletsdk.castor.did.prismdid

import io.iohk.atala.prism.walletsdk.castor.did.prismdid.PrismDIDMethodId
import io.iohk.atala.prism.walletsdk.domain.models.CastorError
import io.iohk.atala.prism.walletsdk.domain.models.DID

Expand All @@ -12,7 +11,7 @@ LongFormPrismDID(val did: DID) {

init {
val methodId = PrismDIDMethodId(
did.methodId
did.methodId,
)

if (methodId.sections.size !== 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PrismDIDPublicKey {
CAPABILITY_DELEGATION_KEY("capabilityDelegationKey"),
CAPABILITY_INVOCATION_KEY("capabilityInvocationKey"),
KEY_AGREEMENT_KEY("keyAgreementKey"),
UNKNOWN_KEY("unknownKey")
UNKNOWN_KEY("unknownKey"),
}

private val apollo: Apollo
Expand Down Expand Up @@ -53,8 +53,8 @@ class PrismDIDPublicKey {
id = id,
usage = usage.toProto(),
keyData = io.iohk.atala.prism.protos.PublicKey.KeyData.CompressedEcKeyData(
compressed.toProto()
)
compressed.toProto(),
),
)
}
}
Expand All @@ -76,7 +76,7 @@ fun KeyUsage.fromProto(): PrismDIDPublicKey.Usage {
fun CompressedPublicKey.toProto(): CompressedECKeyData {
return CompressedECKeyData(
curve = uncompressed.curve.curve.value,
data = ByteArr(value)
data = ByteArr(value),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import io.iohk.atala.prism.protos.CreateDIDOperation
import io.iohk.atala.prism.protos.Service
import io.iohk.atala.prism.walletsdk.castor.did.DIDParser
import io.iohk.atala.prism.walletsdk.castor.did.DIDUrlParser
import io.iohk.atala.prism.walletsdk.castor.did.prismdid.LongFormPrismDID
import io.iohk.atala.prism.walletsdk.castor.did.prismdid.PrismDIDMethodId
import io.iohk.atala.prism.walletsdk.castor.did.prismdid.PrismDIDPublicKey
import io.iohk.atala.prism.walletsdk.castor.did.prismdid.defaultId
import io.iohk.atala.prism.walletsdk.castor.io.iohk.atala.prism.walletsdk.castor.did.prismdid.LongFormPrismDID
import io.iohk.atala.prism.walletsdk.domain.buildingBlocks.Apollo
import io.iohk.atala.prism.walletsdk.domain.models.CastorError
import io.iohk.atala.prism.walletsdk.domain.models.Curve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ actual class LongFormPrismDIDResolver(
return GlobalScope.promise {
CastorShared.resolveLongFormPrismDID(
apollo = apollo,
didString = didString
didString = didString,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ actual interface Castor {
actual fun parseDID(did: String): DID
actual fun createPrismDID(
masterPublicKey: PublicKey,
services: Array<DIDDocument.Service>?
services: Array<DIDDocument.Service>?,
): DID

actual fun createPeerDID(
keyPairs: Array<KeyPair>,
services: Array<DIDDocument.Service>
services: Array<DIDDocument.Service>,
): DID

@Throws() // TODO: Add throw classes
Expand All @@ -24,6 +24,6 @@ actual interface Castor {
suspend fun verifySignature(
did: DID,
challenge: ByteArray,
signature: ByteArray
signature: ByteArray,
): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.iohk.atala.prism.walletsdk.domain.buildingBlocks

import io.iohk.atala.prism.walletsdk.domain.models.Message

actual interface Mercury {

actual fun packMessage(message: Message): String

actual fun unpackMessage(message: String): Message

@Throws() // TODO: Add throw classes
suspend fun sendMessage(message: Message): ByteArray?

@Throws() // TODO: Add throw classes
suspend fun sendMessageParseMessage(message: Message): Message?
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ expect interface Castor {

fun createPrismDID(
masterPublicKey: PublicKey,
services: Array<DIDDocument.Service>? = null
services: Array<DIDDocument.Service>? = null,
): DID

fun createPeerDID(
keyPairs: Array<KeyPair>,
services: Array<DIDDocument.Service>
services: Array<DIDDocument.Service>,
): DID
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@ package io.iohk.atala.prism.walletsdk.domain.buildingBlocks

import io.iohk.atala.prism.walletsdk.domain.models.Message

interface Mercury {
expect interface Mercury {
fun packMessage(message: Message): String

@Throws() // TODO: Add throw classes
suspend fun packMessage(message: Message): String

@Throws() // TODO: Add throw classes
suspend fun unpackMessage(message: String): Message

@Throws() // TODO: Add throw classes
suspend fun sendMessage(message: Message): ByteArray?

@Throws() // TODO: Add throw classes
suspend fun sendMessageParseMessage(message: Message): Message?
fun unpackMessage(message: String): Message
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.iohk.atala.prism.walletsdk.domain.buildingBlocks

import io.iohk.atala.prism.walletsdk.domain.models.DID
import io.iohk.atala.prism.walletsdk.domain.models.DIDPair
import io.iohk.atala.prism.walletsdk.domain.models.MediatorDID
import io.iohk.atala.prism.walletsdk.domain.models.Mediator
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
Expand Down Expand Up @@ -77,7 +77,7 @@ interface Pluto {

fun getMessage(id: String): Message?

fun getAllMediators(): Array<MediatorDID>
fun getAllMediators(): Array<Mediator>

fun getAllCredentials(): Array<VerifiableCredential>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import kotlin.js.JsExport
data class DIDPair(
val host: DID,
val receiver: DID,
val name: String?
val name: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data class DIDUrl(
val did: DID,
val path: Array<String>? = arrayOf(),
val parameters: Map<String, String>? = mapOf(),
val fragment: String? = null
val fragment: String? = null,
) {

fun string(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ sealed class PrismAgentError(message: String? = null) : Throwable(message) {
class invalidRequestPresentationMessageError(message: String? = null) : PrismAgentError(message)
class invalidProposePresentationMessageError(message: String? = null) : PrismAgentError(message)
class invalidMediationGrantMessageError(message: String? = null) : PrismAgentError(message)
class invalidMessageError(message: String? = null) : PrismAgentError(message)
class noMediatorAvailableError(message: String? = null) : PrismAgentError(message)
class mediationRequestFailedError(message: String? = null) : PrismAgentError(message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class JWTVerifiableCredential(
override val validFrom: VerifiableCredentialTypeContainer?,
override val validUntil: VerifiableCredentialTypeContainer?,
override val proof: String?,
override val aud: Set<String>
override val aud: Set<String>,
) : VerifiableCredential

data class JWTCredentialPayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.js.JsExport
data class KeyPair(
val keyCurve: KeyCurve? = KeyCurve(Curve.SECP256K1),
val privateKey: PrivateKey,
val publicKey: PublicKey
val publicKey: PublicKey,
)

@Serializable
Expand All @@ -20,7 +20,7 @@ data class KeyCurve(val curve: Curve, val index: Int? = 0)
enum class Curve(val value: String) {
X25519("X25519"),
ED25519("Ed25519"),
SECP256K1("secp256k1");
SECP256K1("secp256k1"),
}

@JsExport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlin.js.JsExport

@JsExport
@Serializable
data class MediatorDID(
data class Mediator(
val id: String,
val mediatorDID: DID,
val hostDID: DID,
val routingDID: DID
val routingDID: DID,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ data class Message(
val extraHeaders: Array<String>,
val createdTime: String,
val expiresTimePlus: String,
val attachments: Array<String>, // TODO: Change to AttachmentDescriptor
val attachments: Array<AttachmentDescriptor>,
val thid: String? = null,
val pthid: String? = null,
val ack: Array<String>,
val direction: Direction
val direction: Direction,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down Expand Up @@ -69,7 +69,7 @@ data class Message(

enum class Direction(val value: Int) {
SENT(0),
RECEIVED(1)
RECEIVED(1),
}
}

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

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

@JsExport
interface AttachmentData

@Serializable
@JsExport
data class AttachmentHeader(
val children: String
val children: String,
) : AttachmentData

@Serializable
@JsExport
data class AttachmentJws(
val header: AttachmentHeader,
val protected: String,
val signature: String
val signature: String,
) : AttachmentData

@Serializable
@JsExport
data class AttachmentJwsData(
val base64: String,
val jws: AttachmentJws
val jws: AttachmentJws,
) : AttachmentData

@Serializable
@JsExport
data class AttachmentBase64(
val base64: String
val base64: String,
) : AttachmentData

@Serializable
@JsExport
data class AttachmentLinkData(
val links: Array<String>,
val hash: String
val hash: String,
) : AttachmentData {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand All @@ -44,10 +58,14 @@ data class AttachmentLinkData(
}
}

@Serializable
@JsExport
data class AttachmentJsonData(
val data: String
val data: String,
) : AttachmentData

@Serializable
@JsExport
data class AttachmentDescriptor(
val id: String,
val mediaType: String? = null,
Expand All @@ -56,7 +74,7 @@ data class AttachmentDescriptor(
val format: String? = null,
val lastModTime: String? = null, // Date format
val byteCount: Int? = null,
val description: String? = null
val description: String? = null,
) : AttachmentData {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlin.js.JsExport
@JsExport
data class PeerDID(
val did: DID,
val privateKeys: Array<PrivateKey>
val privateKeys: Array<PrivateKey>,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ actual interface Castor {
actual fun parseDID(did: String): DID
actual fun createPrismDID(
masterPublicKey: PublicKey,
services: Array<DIDDocument.Service>?
services: Array<DIDDocument.Service>?,
): DID

actual fun createPeerDID(
keyPairs: Array<KeyPair>,
services: Array<DIDDocument.Service>
services: Array<DIDDocument.Service>,
): DID

fun resolveDID(did: String): Promise<DIDDocument>
fun verifySignature(
did: DID,
challenge: ByteArray,
signature: ByteArray
signature: ByteArray,
): Promise<Boolean>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.iohk.atala.prism.walletsdk.domain.buildingBlocks

import io.iohk.atala.prism.walletsdk.domain.models.Message
import kotlin.js.Promise

@OptIn(ExperimentalJsExport::class)
@JsExport
actual interface Mercury {
actual fun packMessage(message: Message): String

actual fun unpackMessage(message: String): Message

fun sendMessage(message: Message): Promise<ByteArray>

fun sendMessageParseMessage(message: Message): Promise<Message?>
}
Loading

0 comments on commit f7b5d7f

Please sign in to comment.