From b90cf9d992d6729f92daab65d653c2dbd04563be Mon Sep 17 00:00:00 2001 From: Cristian Gonzalez <113917899+cristianIOHK@users.noreply.github.com> Date: Wed, 7 Aug 2024 12:23:29 -0400 Subject: [PATCH] refactor: message attachment data (#183) Signed-off-by: Cristian G --- .../domain/models/MessageAttachment.kt | 62 +++++- .../identus/walletsdk/edgeagent/EdgeAgent.kt | 30 +-- .../walletsdk/edgeagent/EdgeAgentTests.kt | 184 ++++-------------- 3 files changed, 103 insertions(+), 173 deletions(-) diff --git a/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/domain/models/MessageAttachment.kt b/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/domain/models/MessageAttachment.kt index 65c48ef2d..f655e0a4d 100644 --- a/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/domain/models/MessageAttachment.kt +++ b/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/domain/models/MessageAttachment.kt @@ -13,6 +13,8 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonDecoder import kotlinx.serialization.json.JsonNames import kotlinx.serialization.json.jsonObject +import org.hyperledger.identus.apollo.base64.base64UrlDecoded +import org.hyperledger.identus.walletsdk.edgeagent.EdgeAgentError import java.util.UUID import kotlin.jvm.JvmOverloads @@ -22,6 +24,26 @@ import kotlin.jvm.JvmOverloads */ @Serializable sealed class AttachmentData { + + /** + * This method verifies the type of [AttachmentData] and returns the data as a json string. + */ + fun getDataAsJsonString(): String { + return when (this) { + is AttachmentBase64 -> { + this.base64.base64UrlDecoded + } + + is AttachmentJsonData -> { + this.data + } + + else -> { + throw EdgeAgentError.AttachmentTypeNotSupported() + } + } + } + /** * The [AttachmentHeader] data class represents the header for a DIDComm attachment. */ @@ -229,12 +251,35 @@ object AttachmentDataSerializer : KSerializer { */ override fun serialize(encoder: Encoder, value: AttachmentData) { when (value) { - is AttachmentData.AttachmentHeader -> encoder.encodeSerializableValue(AttachmentData.AttachmentHeader.serializer(), value) - is AttachmentData.AttachmentJws -> encoder.encodeSerializableValue(AttachmentData.AttachmentJws.serializer(), value) - is AttachmentData.AttachmentJwsData -> encoder.encodeSerializableValue(AttachmentData.AttachmentJwsData.serializer(), value) - is AttachmentData.AttachmentBase64 -> encoder.encodeSerializableValue(AttachmentData.AttachmentBase64.serializer(), value) - is AttachmentData.AttachmentLinkData -> encoder.encodeSerializableValue(AttachmentData.AttachmentLinkData.serializer(), value) - is AttachmentData.AttachmentJsonData -> encoder.encodeSerializableValue(AttachmentData.AttachmentJsonData.serializer(), value) + is AttachmentData.AttachmentHeader -> encoder.encodeSerializableValue( + AttachmentData.AttachmentHeader.serializer(), + value + ) + + is AttachmentData.AttachmentJws -> encoder.encodeSerializableValue( + AttachmentData.AttachmentJws.serializer(), + value + ) + + is AttachmentData.AttachmentJwsData -> encoder.encodeSerializableValue( + AttachmentData.AttachmentJwsData.serializer(), + value + ) + + is AttachmentData.AttachmentBase64 -> encoder.encodeSerializableValue( + AttachmentData.AttachmentBase64.serializer(), + value + ) + + is AttachmentData.AttachmentLinkData -> encoder.encodeSerializableValue( + AttachmentData.AttachmentLinkData.serializer(), + value + ) + + is AttachmentData.AttachmentJsonData -> encoder.encodeSerializableValue( + AttachmentData.AttachmentJsonData.serializer(), + value + ) } } @@ -255,9 +300,11 @@ object AttachmentDataSerializer : KSerializer { json.containsKey("children") -> { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentHeader.serializer(), json) } + json.containsKey("protected") && json.containsKey("signature") -> { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentJws.serializer(), json) } + json.containsKey("base64") -> { if (json.containsKey("jws")) { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentJwsData.serializer(), json) @@ -265,12 +312,15 @@ object AttachmentDataSerializer : KSerializer { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentBase64.serializer(), json) } } + json.containsKey("links") && json.containsKey("hash") -> { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentLinkData.serializer(), json) } + json.containsKey("data") -> { jsonSerializable.decodeFromJsonElement(AttachmentData.AttachmentJsonData.serializer(), json) } + else -> throw SerializationException("Unknown AttachmentData type") } } diff --git a/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgent.kt b/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgent.kt index 385ff5c1f..180b975b6 100644 --- a/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgent.kt +++ b/edge-agent-sdk/src/commonMain/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgent.kt @@ -56,7 +56,6 @@ import org.hyperledger.identus.walletsdk.domain.buildingblocks.Pollux import org.hyperledger.identus.walletsdk.domain.models.Api import org.hyperledger.identus.walletsdk.domain.models.ApiImpl import org.hyperledger.identus.walletsdk.domain.models.ApolloError -import org.hyperledger.identus.walletsdk.domain.models.AttachmentData import org.hyperledger.identus.walletsdk.domain.models.AttachmentData.AttachmentBase64 import org.hyperledger.identus.walletsdk.domain.models.AttachmentData.AttachmentJsonData import org.hyperledger.identus.walletsdk.domain.models.AttachmentDescriptor @@ -678,10 +677,7 @@ open class EdgeAgent { CredentialType.ANONCREDS_OFFER -> { val linkSecret = getLinkSecret() val offerDataString = offer.attachments.firstNotNullOf { - when (it.data) { - is AttachmentData.AttachmentBase64 -> it.data.base64 - else -> null - } + it.data.getDataAsJsonString() } if (offer.thid == null) { throw EdgeAgentError.MissingOrNullFieldError("thid", "OfferCredential") @@ -737,10 +733,9 @@ open class EdgeAgent { @Throws(UnknownError.SomethingWentWrongError::class) suspend fun processIssuedCredentialMessage(message: IssueCredential): Credential { val credentialType = pollux.extractCredentialFormatFromMessage(message.attachments) - val attachment = message.attachments.firstOrNull()?.data as? AttachmentBase64 + val attachmentData = message.attachments.firstOrNull()?.data?.getDataAsJsonString() - return attachment?.let { - val credentialData = it.base64.base64UrlDecoded + return attachmentData?.let { credentialData -> if (message.thid != null) { val linkSecret = if (credentialType == CredentialType.ANONCREDS_ISSUE) { getLinkSecret() @@ -970,8 +965,6 @@ open class EdgeAgent { var presentationString: String? when (attachmentFormat) { CredentialType.PRESENTATION_EXCHANGE_DEFINITIONS.type -> { - request.attachments.find { it.data::class == AttachmentBase64::class } - ?: throw EdgeAgentError.AttachmentTypeNotSupported() // Presentation Exchange return handlePresentationDefinitionRequest(request, credential) } @@ -1108,12 +1101,7 @@ open class EdgeAgent { throw EdgeAgentError.InvalidCredentialError(credential) } - val msgAttachmentDescriptor = - requestPresentation.attachments.find { it.data::class == AttachmentBase64::class } - ?: throw EdgeAgentError.AttachmentTypeNotSupported() - - val attachmentBase64 = msgAttachmentDescriptor.data as AttachmentBase64 - val presentationDefinitionRequestString = attachmentBase64.base64.base64UrlDecoded + val presentationDefinitionRequestString = requestPresentation.attachments.firstNotNullOf { it.data.getDataAsJsonString() } val didString = credential.subject ?: throw Exception("Credential must contain subject") @@ -1147,21 +1135,15 @@ open class EdgeAgent { throw EdgeAgentError.MissingOrNullFieldError("thid", "presentation message") } val presentation = Presentation.fromMessage(msg) - val msgAttachmentDescriptor = - presentation.attachments.find { it.data::class == AttachmentBase64::class } - ?: throw EdgeAgentError.AttachmentTypeNotSupported() - val attachmentBase64 = msgAttachmentDescriptor.data as AttachmentBase64 - val presentationSubmissionString = attachmentBase64.base64.base64UrlDecoded + val presentationSubmissionString = presentation.attachments.firstNotNullOf { it.data.getDataAsJsonString() } val presentationDefinitionRequest = pluto.getMessageByThidAndPiuri(msg.thid, ProtocolType.DidcommRequestPresentation.value) .firstOrNull() ?.let { message -> val requestPresentation = RequestPresentation.fromMessage(message) - val attachmentDescriptor = requestPresentation.attachments.first() - val base64 = (attachmentDescriptor.data as AttachmentBase64).base64 - base64.base64UrlDecoded + requestPresentation.attachments.firstNotNullOf { it.data.getDataAsJsonString() } } ?: throw EdgeAgentError.MissingOrNullFieldError("thid", "presentation message") return pollux.verifyPresentationSubmission( presentationSubmissionString = presentationSubmissionString, diff --git a/edge-agent-sdk/src/commonTest/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgentTests.kt b/edge-agent-sdk/src/commonTest/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgentTests.kt index 2ae61b7e6..bb48dcf4a 100644 --- a/edge-agent-sdk/src/commonTest/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgentTests.kt +++ b/edge-agent-sdk/src/commonTest/kotlin/org/hyperledger/identus/walletsdk/edgeagent/EdgeAgentTests.kt @@ -33,6 +33,7 @@ import org.hyperledger.identus.walletsdk.domain.buildingblocks.Pluto import org.hyperledger.identus.walletsdk.domain.buildingblocks.Pollux import org.hyperledger.identus.walletsdk.domain.models.Api import org.hyperledger.identus.walletsdk.domain.models.ApolloError +import org.hyperledger.identus.walletsdk.domain.models.AttachmentData import org.hyperledger.identus.walletsdk.domain.models.AttachmentData.AttachmentBase64 import org.hyperledger.identus.walletsdk.domain.models.AttachmentDescriptor import org.hyperledger.identus.walletsdk.domain.models.ClaimType @@ -94,6 +95,7 @@ import org.mockito.kotlin.spy import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertFalse +import kotlin.test.assertNotNull import kotlin.test.assertTrue @RunWith(JUnit4::class) @@ -1091,8 +1093,8 @@ class EdgeAgentTests { assertEquals(toDid, sentMessage.to.toString()) assertEquals(1, sentMessage.attachments.size) assertTrue(sentMessage.attachments.first().data::class == AttachmentBase64::class) - val base64Attachment = sentMessage.attachments.first().data as AttachmentBase64 - assertEquals(definitionJson, base64Attachment.base64.base64UrlDecoded) + val attachmentJsonData = sentMessage.attachments.first().data.getDataAsJsonString() + assertEquals(definitionJson, attachmentJsonData) } @Test @@ -1152,55 +1154,6 @@ class EdgeAgentTests { } } - @Test - fun testHandlePresentationDefinitionRequest_whenWrongAttachmentType_thenThrowPresentationRequestAttachmentNotSupported() = - runTest { - val apiMock = mock() - `when`(apiMock.request(any(), any(), any(), any(), any())) - .thenReturn(HttpResponse(200, "Ok")) - - val apolloMock = mock() - val castorMock = mock() - val plutoMock = mock() - val mercuryMock = mock() - val polluxMock = mock() - val connectionManagerMock = mock() - - val mediatorHandlerMock = mock() - `when`(connectionManagerMock.mediationHandler).thenReturn(mediatorHandlerMock) - val mediator = Mediator( - id = UUID.randomUUID().toString(), - mediatorDID = DID("did:peer:mediatordid"), - hostDID = DID("did:peer:hostdid"), - routingDID = DID("did:peer:routingdid") - ) - `when`(mediatorHandlerMock.mediator).thenReturn(mediator) - - val agent = EdgeAgent( - apollo = apolloMock, - castor = castorMock, - pluto = plutoMock, - mercury = mercuryMock, - pollux = polluxMock, - connectionManager = connectionManagerMock, - seed = seed, - api = apiMock, - logger = PrismLoggerMock() - ) - val msg = Json.decodeFromString( - "{\"id\":\"00000000-685c-4004-0000-000036ac64ee\",\"piuri\":\"https://didcomm.atalaprism.io/present-proof/3.0/request-presentation\",\"from\":{\"method\":\"peer\",\"methodId\":\"asdfasdf\"},\"to\":{\"method\":\"peer\",\"methodId\":\"fdsafdsa\"},\"fromPrior\":null,\"body\":\"{}\",\"createdTime\":\"2024-03-08T19:27:38.196506Z\",\"expiresTimePlus\":\"2024-03-09T19:27:38.196559Z\",\"attachments\":[{\"id\":\"00000000-9c2e-4249-0000-0000c1176949\",\"mediaType\":\"application/json\",\"data\":{\"type\":\"org.hyperledger.identus.walletsdk.domain.models.AttachmentJsonData\",\"data\":\"eyJwcmVzZW50YXRpb25fZGVmaW5pdGlvbiI6eyJpZCI6IjMyZjU0MTYzLTcxNjYtNDhmMS05M2Q4LWZmMjE3YmRiMDY1MyIsImlucHV0X2Rlc2NyaXB0b3JzIjpbeyJpZCI6IndhX2RyaXZlcl9saWNlbnNlIiwibmFtZSI6Ildhc2hpbmd0b24gU3RhdGUgQnVzaW5lc3MgTGljZW5zZSIsInB1cnBvc2UiOiJXZSBjYW4gb25seSBhbGxvdyBsaWNlbnNlZCBXYXNoaW5ndG9uIFN0YXRlIGJ1c2luZXNzIHJlcHJlc2VudGF0aXZlcyBpbnRvIHRoZSBXQSBCdXNpbmVzcyBDb25mZXJlbmNlIiwiY29uc3RyYWludHMiOnsiZmllbGRzIjpbeyJwYXRoIjpbIiQuY3JlZGVudGlhbFN1YmplY3QuZGF0ZU9mQmlydGgiLCIkLmNyZWRlbnRpYWxTdWJqZWN0LmRvYiIsIiQudmMuY3JlZGVudGlhbFN1YmplY3QuZGF0ZU9mQmlydGgiLCIkLnZjLmNyZWRlbnRpYWxTdWJqZWN0LmRvYiJdfV19fV0sImZvcm1hdCI6eyJqd3QiOnsiYWxnIjpbIkVTMjU2SyJdfX19LCAib3B0aW9ucyI6IHsiZG9tYWluIjogImRvbWFpbiIsICJjaGFsbGVuZ2UiOiAiY2hhbGxlbmdlIn19\"},\"format\":\"dif/presentation-exchange/definitions@v1.0\"}],\"thid\":\"00000000-ef9d-4722-0000-00003b1bc908\",\"ack\":[]}" - ) - val credential = JWTCredential.fromJwtString( - "eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6cHJpc206MjU3MTlhOTZiMTUxMjA3MTY5ODFhODQzMGFkMGNiOTY4ZGQ1MzQwNzM1OTNjOGNkM2YxZDI3YTY4MDRlYzUwZTpDcG9DQ3BjQ0Vsb0tCV3RsZVMweEVBSkNUd29KYzJWamNESTFObXN4RWlBRW9TQ241dHlEYTZZNnItSW1TcXBKOFkxbWo3SkMzX29VekUwTnl5RWlDQm9nc2dOYWVSZGNDUkdQbGU4MlZ2OXRKZk53bDZyZzZWY2hSM09xaGlWYlRhOFNXd29HWVhWMGFDMHhFQVJDVHdvSmMyVmpjREkxTm1zeEVpRE1rQmQ2RnRpb0prM1hPRnUtX2N5NVhtUi00dFVRMk5MR2lXOGFJU29ta1JvZzZTZGU5UHduRzBRMFNCVG1GU1REYlNLQnZJVjZDVExYcmpJSnR0ZUdJbUFTWEFvSGJXRnpkR1Z5TUJBQlFrOEtDWE5sWTNBe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FVSlBDZ2x6WldOd01qVTJhekVTSUhrb1B0amp0U1haNmMxRGdZcmN5SW5GM1g4M2dIRTMxZ0RmbUFucmdtOGlHaUNVT0JreU45TFdsWXNISVU5M3RKeTF3VXVOd2VJX1k1YkpTcU5tWlhWODR3In0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiXSwiQGNvbnRleHQiOlsiaHR0cHM6XC9cL3d3dy53My5vcmdcLzIwMThcL2NyZWRlbnRpYWxzXC92MSJdfX0.x0SF17Y0VCDmt7HceOdTxfHlofsZmY18Rn6VQb0-r-k_Bm3hTi1-k2vkdjB25hdxyTCvxam-AkAP-Ag3Ahn5Ng" - ) - assertFailsWith(EdgeAgentError.AttachmentTypeNotSupported::class) { - agent.preparePresentationForRequestProof( - RequestPresentation.fromMessage(msg), - credential - ) - } - } - @Test fun testHandlePresentation_whenWrongPresentationSubmission_thenThrowMissingOrNullFieldError() = runTest { @@ -1369,98 +1322,6 @@ class EdgeAgentTests { ) } - @Test - fun testHandlePresentationSubmission_whenAttachmentNotSupported_thenThrowsAttachmentTypeNotSupported() = runTest { - val apiMock = mock() - `when`(apiMock.request(any(), any(), any(), any(), any())) - .thenReturn(HttpResponse(200, "Ok")) - - val apolloMock = mock() - val castorMock = mock() - val plutoMock = mock() - val mercuryMock = mock() - val polluxMock = mock() - val connectionManagerMock = mock() - - val privateKey = - Secp256k1KeyPair.generateKeyPair( - seed = Seed(MnemonicHelper.createRandomSeed()), - curve = KeyCurve(Curve.SECP256K1) - ).privateKey - val storablePrivateKeys = listOf( - StorablePrivateKey( - id = UUID.randomUUID().toString(), - restorationIdentifier = "secp256k1+priv", - data = privateKey.raw.base64UrlEncoded, - keyPathIndex = 0 - ) - ) - // Mock getDIDPrivateKeysByDID response - `when`(plutoMock.getDIDPrivateKeysByDID(any())).thenReturn(flow { emit(storablePrivateKeys) }) - `when`( - apolloMock.restorePrivateKey( - storablePrivateKeys.first().restorationIdentifier, - storablePrivateKeys.first().data - ) - ).thenReturn(privateKey) - - val presentationSubmission = - "{\"presentation_submission\":{\"id\":\"00000000-c224-45d7-0000-0000732f4932\",\"definition_id\":\"32f54163-7166-48f1-93d8-ff217bdb0653\",\"descriptor_map\":[{\"id\":\"wa_driver_license\",\"format\":\"jwt\",\"path\":\"\$.verifiablePresentation[0]\"}]},\"verifiablePresentation\":[\"eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6cHJpc206MjU3MTlhOTZiMTUxMjA3MTY5ODFhODQzMGFkMGNiOTY4ZGQ1MzQwNzM1OTNjOGNkM2YxZDI3YTY4MDRlYzUwZTpDcG9DQ3BjQ0Vsb0tCV3RsZVMweEVBSkNUd29KYzJWamNESTFObXN4RWlBRW9TQ241dHlEYTZZNnItSW1TcXBKOFkxbWo3SkMzX29VekUwTnl5RWlDQm9nc2dOYWVSZGNDUkdQbGU4MlZ2OXRKZk53bDZyZzZWY2hSM09xaGlWYlRhOFNXd29HWVhWMGFDMHhFQVJDVHdvSmMyVmpjREkxTm1zeEVpRE1rQmQ2RnRpb0prM1hPRnUtX2N5NVhtUi00dFVRMk5MR2lXOGFJU29ta1JvZzZTZGU5UHduRzBRMFNCVG1GU1REYlNLQnZJVjZDVExYcmpJSnR0ZUdJbUFTWEFvSGJXRnpkR1Z5TUJBQlFrOEtDWE5sWTNBeU5UWnJNUklnTzcxMG10MVdfaXhEeVFNM3hJczdUcGpMQ05PRFF4Z1ZoeDVzaGZLTlgxb2FJSFdQcnc3SVVLbGZpYlF0eDZKazRUU2pnY1dOT2ZjT3RVOUQ5UHVaN1Q5dCIsInN1YiI6ImRpZDpwcmlzbTpiZWVhNTIzNGFmNDY4MDQ3MTRkOGVhOGVjNzdiNjZjYzdmM2U4MTVjNjhhYmI0NzVmMjU0Y2Y5YzMwNjI2NzYzOkNzY0JDc1FCRW1RS0QyRjFkR2hsYm5ScFkyRjBhVzl1TUJBRVFrOEtDWE5sWTNBeU5UWnJNUklnZVNnLTJPTzFKZG5welVPQml0eklpY1hk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\"]}" - - // Mock createPresentationSubmission response - `when`(polluxMock.createPresentationSubmission(any(), any(), any())).thenReturn( - presentationSubmission - ) - - val vmAuthentication = DIDDocument.VerificationMethod( - id = DIDUrl(DID("2", "1", "0")), - controller = DID("2", "2", "0"), - type = Curve.ED25519.value, - publicKeyJwk = mapOf("crv" to Curve.ED25519.value, "x" to "") - ) - - val vmKeyAgreement = DIDDocument.VerificationMethod( - id = DIDUrl(DID("3", "1", "0")), - controller = DID("3", "2", "0"), - type = Curve.X25519.value, - publicKeyJwk = mapOf("crv" to Curve.X25519.value, "x" to "") - ) - - val resolverMock = mock() - val didDoc = DIDDocument( - id = DID("did:prism:asdfasdf"), - coreProperties = arrayOf( - DIDDocument.Authentication( - urls = emptyArray(), - verificationMethods = arrayOf(vmAuthentication, vmKeyAgreement) - ) - ) - ) - // Mock resolve did response - `when`(castorMock.resolveDID(any())).thenReturn(didDoc) - `when`(resolverMock.resolve(any())).thenReturn(didDoc) - - val agent = EdgeAgent( - apollo = apolloMock, - castor = castorMock, - pluto = plutoMock, - mercury = mercuryMock, - pollux = polluxMock, - connectionManager = connectionManagerMock, - seed = seed, - api = apiMock, - logger = PrismLoggerMock() - ) - - val msgString = - "{\"id\":\"00000000-621a-4ae9-0000-00002ffb05bf\",\"piuri\":\"https://didcomm.atalaprism.io/present-proof/3.0/presentation\",\"from\":{\"method\":\"peer\",\"methodId\":\"fdsafdsa\"},\"to\":{\"method\":\"peer\",\"methodId\":\"asdfasdf\"},\"fromPrior\":null,\"body\":\"{}\",\"createdTime\":\"2024-03-18T17:11:58.053680Z\",\"expiresTimePlus\":\"2024-03-19T17:11:58.058523Z\",\"attachments\":[{\"id\":\"00000000-ef5f-40c0-0000-0000d2674b80\",\"mediaType\":\"application/json\",\"data\":{\"type\":\"org.hyperledger.identus.walletsdk.domain.models.AttachmentJsonData\",\"data\":\"eyJwcmVzZW50YXRpb25fc3VibWlzc2lvbiI6eyJpZCI6IjAwMDAwMDAwLWMyMjQtNDVkNy0wM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2V2xkT2QwMXFWVEpoZWtWVFNVaHJiMUIwYW1wMFUxaGFObU14UkdkWmNtTjVTVzVHTTFnNE0yZElSVE14WjBSbWJVRnVjbWR0T0dsSGFVTlZUMEpyZVU0NVRGZHNXWE5JU1ZVNU0zUktlVEYzVlhWT2QyVkpYMWsxWWtwVGNVNXRXbGhXT0RSM0luMHNJblI1Y0dVaU9sc2lWbVZ5YVdacFlXSnNaVU55WldSbGJuUnBZV3dpWFN3aVFHTnZiblJsZUhRaU9sc2lhSFIwY0hNNlhDOWNMM2QzZHk1M015NXZjbWRjTHpJd01UaGNMMk55WldSbGJuUnBZV3h6WEM5Mk1TSmRmWDAueDBTRjE3WTBWQ0RtdDdIY2VPZFR4Zkhsb2ZzWm1ZMThSbjZWUWIwLXIta19CbTNoVGkxLWsydmtkakIyNWhkeHlUQ3Z4YW0tQWtBUC1BZzNBaG41TmciLCJjaGFsbGVuZ2UiOiIzMDQ1MDIyMTAwYjE0MTJjMGYzZmJiYzVjODc2ZGRlNjExNDFmYTY4N2Y3ZjJmYWJhODM0YWJjZTA5Yzg2YzcwNWEwYjkwMjAwNTAyMjA2YjY3MjUzZmE1ZjgwMzQ0YzQyZGQ4NGQyMzZiYmJiMTVkNTBhODliODE2ZmE1NWQ1YTZhNzQyY2NjODYwZTIzIn19\"},\"format\":\"prism/jwt\"}],\"thid\":\"00000000-ef9d-4722-0000-00003b1bc908\",\"ack\":[]}" - val msg = Json.decodeFromString(msgString) - - assertFailsWith { - agent.handlePresentation(msg) - } - } - @Test fun testHandlePresentationSubmission_whenAllCorrect_thenReturnTrue() = runTest { val apiMock = mock() @@ -1738,6 +1599,43 @@ class EdgeAgentTests { assertEquals(EncryptionMethod.A256CBC_HS512, jweObject.header.encryptionMethod) } + @Test + fun `test AttachementData getDataAsString`() = runTest { + val message = Json.decodeFromString( + """{"id":"e430e4af-455e-4a15-9f2f-5bd8e5f350b8","piuri":"https://didcomm.org/issue-credential/3.0/offer-credential","from":{"method":"peer","methodId":"2.Ez6LSm5hETc4CS4X8RxYYKjoS2B3CM8TyzbgRrE7kGrdymHdq.Vz6MkoP2VXs4N7iNsKTzEKtZbnfu6yDH1x2ajGtCmNmc6qdMW.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjY4LjExMzo4MDAwL2RpZGNvbW0iLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19fQ"},"to":{"method":"peer","methodId":"2.Ez6LSd8irQSWjjMfvg53kcaDY6Q2doPEvQwscjSzidgWoFUVK.Vz6Mksu4QVe8oKwJEDPgxRg2bFa3QWrZR1EZGC9xq8xk9twYX.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6ImRpZDpwZWVyOjIuRXo2TFNnaHdTRTQzN3duREUxcHQzWDZoVkRVUXpTanNIemlucFgzWEZ2TWpSQW03eS5WejZNa2hoMWU1Q0VZWXE2SkJVY1RaNkNwMnJhbkNXUnJ2N1lheDNMZTRONTlSNmRkLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQnpPaTh2YzJsMExYQnlhWE50TFcxbFpHbGhkRzl5TG1GMFlXeGhjSEpwYzIwdWFXOGlMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDE5LlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW5kemN6b3ZMM05wZEMxd2NtbHpiUzF0WldScFlYUnZjaTVoZEdGc1lYQnlhWE50TG1sdkwzZHpJaXdpWVNJNld5SmthV1JqYjIxdEwzWXlJbDE5ZlEiLCJyIjpbXSwiYSI6W119fQ"},"fromPrior":"null","body":"{\"multiple_available\":null,\"goal_code\":\"Offer Credential\",\"credential_preview\":{\"schema_id\":\"http:\\/\\/192.168.68.113:8000\\/cloud-agent\\/schema-registry\\/schemas\\/5667190d-640c-36af-a9f1-f4ed2587e766\\/schema\",\"type\":\"https:\\/\\/didcomm.org\\/issue-credential\\/3.0\\/credential-credential\",\"body\":{\"attributes\":[{\"media_type\":null,\"name\":\"age\",\"value\":\"18\"},{\"media_type\":null,\"name\":\"name\",\"value\":\"Cristian\"}]}},\"replacement_id\":null,\"comment\":null}","created_time":"1721242264","expires_time_plus":"1721328667","attachments":[{"id":"ee903fe0-2c49-4356-9b41-cfccc979c0a1","data":{"base64":"eyJzY2hlbWFfaWQiOiJodHRwOi8vMTkyLjE2OC42OC4xMTM6ODAwMC9jbG91ZC1hZ2VudC9zY2hlbWEtcmVnaXN0cnkvc2NoZW1hcy81NjY3MTkwZC02NDBjLTM2YWYtYTlmMS1mNGVkMjU4N2U3NjYvc2NoZW1hIiwiY3JlZF9kZWZfaWQiOiJodHRwOi8vMTkyLjE2OC42OC4xMTM6ODAwMC9jbG91ZC1hZ2VudC9jcmVkZW50aWFsLWRlZmluaXRpb24tcmVnaXN0cnkvZGVmaW5pdGlvbnMvM2RhNmExZDgtMmIyMy0zMTM4LWIwMmEtYWIwYmI0OGY4MGY5L2RlZmluaXRpb24iLCJrZXlfY29ycmVjdG5lc3NfcHJvb2YiOnsiYyI6IjM0MjE0MzM4OTA5MDk4MTU5ODIyNTA3MjQ4Njk3NjUyNTIyMzc1NzM2ODM0OTM1MDg0NjM5MTYzNTUyNjgwMjc3MjQyOTcxODI5ODUwIiwieHpfY2FwIjoiODAwNzA3NDcxNzUyOTQ3MTI1NDIxNTU2ODI1ODYyNDc5NzE1OTE0OTE3ODE4NTY4MDI1NjU5Mzk1NDcyMTAzMzQ0NjAwMDI4NzU4MzczMTA5Mjg0NzEzNDg5MDg1OTk3NzE5NDcwOTc5MDQ1NzA3NTY1ODA4MDczNzYxMjI0OTI3MzcyMDk1MTU2MzAxODE3MzgzNDE5NzE4NzM0NDk2MDQwMjc1MzM2MTg0ODIzNzQ4NTg0NzgzNjIxNzE1NTQwOTI3Nzk0ODQyMTA2NDM1NDEwNzc4MDg2ODg1MTc5MzQzMjEzMjU3NTk2ODM2NjU5NzYwMTI4NzI5ODI5MTk2MzI0MjQwMzgyOTc3MzczNjU3MTA0Nj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Tc2NTg3MTU5NzQ5ODkxODg5MzU3Mjk0OTUyNDMwMDY2MTE5MjgzNzA1NTAwMTcxNTc3ODMzMzk3OTE1Mzc5OTA2NTA1MDExMjczODM2NTM3OTA2NjkyMjg2MTk5NDgzMjA3NDc1MzM2MjE1Njc4MTA1NDY5MDc3MTMyNDAwNDM4NTgyOTAyMjMwMzI5MDc4NjA4NTI4NDgzNDEwODI1NDkzNDcwMjI5MjA3MzA1NTk0ODUwMTg4ODUwMjEyNTQ0NzI0NDgyOTExOTQ3NTQ4NzIzMzMxMzYyNTI3MjA0Mzg3MzE1Mjk1MDU4Njk5MDk3NDc3MjQzMTczOTE0Njk5MDAzOTkzNTQiXV19LCJub25jZSI6IjM2MDY2NjE3NzQwNTA3NzY5NTI5NTMxNyJ9"},"format":"anoncreds/credential-offer@v1.0"}],"thid":"3a1c143b-7ab7-470d-99cf-bc5f31771388","ack":[]}""" + ) + + val expectedAttachmentDataString = + """{"schema_id":"http://192.168.68.113:8000/cloud-agent/schema-registry/schemas/5667190d-640c-36af-a9f1-f4ed2587e766/schema","cred_def_id":"http://192.168.68.113:8000/cloud-agent/credential-definition-registry/definitions/3da6a1d8-2b23-3138-b02a-ab0bb48f80f9/definition","key_correctness_proof":{"c":"34214338909098159822507248697652522375736834935084639163552680277242971829850","xz_cap":"800707471752947125421556825862479715914917818568025659395472103344600028758373109284713489085997719470979045707565808073761224927372095156301817383419718734496040275336184823748584783621715540927794842106435410778086885179343213257596836659760128729829196324240382977373657104649618254033098674991320376512152997384399364977038756870957572034534565039964163483412113774709156571271527866740755776323981519713645248679782937572928425744617230796360719007374880526808823886530316382925071963250382758009295325483822584922090170101969999185301005436262028421904659368957942500491729264133319784420644451152606026085090463703143473171287951134535064474649419353048340998166660492019842456439171636","xr_cap":[["age","720662800370023933960365144516641427050483880036121464720586097318814491699091752265838768517039207229415105089567415496003203438631336413004072984027137267852461465147145458838032693084467878730776789666951606567700724201024200058868117345168855901024258218816915265076878163228058282563726475010755644358273042121752898251930774480156256234357275841367576484096916751787269606503605538008667265301212109610994218563689701727948761247377845129121748784197562607322484522843599422618507542820798930021132993864131019927051460685941346571524269487489040349935192106893081586983946211402623736990031610476000079667195350127112723873942427684289064046766141384937971077168475856576606878066462728"],["master_secret","788484201830976958606627940060362361877157724549974931438255233321830789575809697765364707069901496895008499623040080893434534007236648946148809408299595725018959128644208813040900827938125302191417977910257062144405477166929964357088966584396680523588174594794844685506885885308614963120587012387548713460104080868634845090412812879525327325787863820157291104154847413303212213281164460368405909683665564312645450043618164129264814726185276962231929662445798672973071741251631264053491771071867613081112664019288862682657070595155282946676965157152693345266489951173489467796962498382718308660451441701608141679448002045683175263659577068084401422297621972388520158589404000714929000157823104"],["name","862178789530931194767495940822318988041354672296288962478021507847793159909932089276663861146293358768015484888116936957799552584640567245232217264817891018689076073623070400775590492255084429178099540275255450068556976307886945442776975437988970384343887223297422387936916392566766934295099923096544519093939973561519696635213034911441992019742220484617692753004749162570084947534379725406067710839195735400390273331302581969712317658715974989188935729495243006611928370550017157783339791537990650501127383653790669228619948320747533621567810546907713240043858290223032907860852848341082549347022920730559485018885021254472448291194754872333136252720438731529505869909747724317391469900399354"]]},"nonce":"360666177405077695295317"}""" + val attachments = message.attachments + val attachmentDataString = attachments.first().data.getDataAsJsonString() + assertNotNull(attachmentDataString) + assertEquals(expectedAttachmentDataString, attachmentDataString) + + val expectedJsonData = + """{"options":{"domain":"https://prism-verifier.com","challenge":"11c91493-01b3-4c4d-ac36-b336bab5bddf"},"presentation_definition":{"purpose":null,"format":null,"name":null,"input_descriptors":[],"id":"56108c4a-ca57-40b6-89f0-1e1a2fa186fd"}}""" + val requestPresentationJson = + """{"id":"581f9d51-bb0c-4bcd-a851-487a14d30cc6","piuri":"https://didcomm.atalaprism.io/present-proof/3.0/request-presentation","from":{"method":"peer","methodId":"2.Ez6LScuoWiuQHfk4Js2aMC4Qs8rD5zNUfmiNfWMCb2pWR3FAc.Vz6MkvKtf2JqqcxhC1MPmWbWPrxqt8A4v44zri36XHgNmsmgV.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly8xOTIuMTY4LjY4LjExMzo4MDAwL2RpZGNvbW0iLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19fQ"},"to":{"method":"peer","methodId":"2.Ez6LSmuL2dNc6wg5HpqDcDBXnNDG6TawcrBuxZbFkW9Hberjq.Vz6MkvcyMv5VAbTTttvNpo3YYku9Y8VMR9kRw8SFjAX8ic7JU.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6ImRpZDpwZWVyOjIuRXo2TFNnaHdTRTQzN3duREUxcHQzWDZoVkRVUXpTanNIemlucFgzWEZ2TWpSQW03eS5WejZNa2hoMWU1Q0VZWXE2SkJVY1RaNkNwMnJhbkNXUnJ2N1lheDNMZTRONTlSNmRkLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQnpPaTh2YzJsMExYQnlhWE50TFcxbFpHbGhkRzl5TG1GMFlXeGhjSEpwYzIwdWFXOGlMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDE5LlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW5kemN6b3ZMM05wZEMxd2NtbHpiUzF0WldScFlYUnZjaTVoZEdGc1lYQnlhWE50TG1sdkwzZHpJaXdpWVNJNld5SmthV1JqYjIxdEwzWXlJbDE5ZlEiLCJyIjpbXSwiYSI6W119fQ"},"fromPrior":"null","body":{"goal_code":"Request Proof Presentation","comment":null,"proof_types":[],"will_confirm":false},"createdTime":"1718228880","expiresTimePlus":"2024-06-13T21:48:02.636794Z","attachments":[{"id":"e784ac49-bb2d-4445-9cac-edd365664c73","data":{"type":"org.hyperledger.identus.walletsdk.domain.models.AttachmentJsonData","data":"{\"options\":{\"domain\":\"https://prism-verifier.com\",\"challenge\":\"11c91493-01b3-4c4d-ac36-b336bab5bddf\"},\"presentation_definition\":{\"purpose\":null,\"format\":null,\"name\":null,\"input_descriptors\":[],\"id\":\"56108c4a-ca57-40b6-89f0-1e1a2fa186fd\"}}"},"format":"prism/jwt"}],"thid":"c7cdff93-2706-4023-8d3c-3ce850ab0b2d","ack":[]}""" + val requestPresentation = json.decodeFromString(requestPresentationJson) + val attachmentDataString1 = requestPresentation.attachments.first().data.getDataAsJsonString() + assertNotNull(attachmentDataString1) + assertEquals(expectedJsonData, attachmentDataString1) + + val message1 = Message( + piuri = ProtocolType.DidcommRequestPresentation.value, + body = "", + attachments = arrayOf( + AttachmentDescriptor( + data = AttachmentData.AttachmentHeader("") + ) + ) + ) + val attachments1 = message1.attachments + assertFailsWith { + attachments1.first().data.getDataAsJsonString() + } + } + val getCredentialDefinitionResponse = "{\"schemaId\":\"http://host.docker.internal:8000/prism-agent/schema-registry/schemas/5e0d5a93-4bfd-3111-a956-5d5bc82f76cc\",\"type\":\"CL\",\"tag\":\"licence\",\"value\":{\"primary\":{\"n\":\"105195159277979097653318357586659371305119697478469834190626350283715795188687389523188659352120689851168860621983864738336838773213022505168653440146374011050277159372491059901432822905781969400722059341786498751125483895348734607382548396665339315322605154516776326303787844694026898270194867398625429469096229269732265502538641116512214652017416624138065704599041020588805936844771273861390913500753293895219370960892829297672575154196820931047049021760519166121287056337193413235473255257349024671869248216238831094979209384406168241010010012567685965827447177652200129684927663161550376084422586141212281146491949\",\"s\":\"85376740935726732134199731472843597191822272986425414914465211197069650618238336366149699822721009443794877925725075553195071288777117865451699414058058985000654277974066307286552934230286237253977472401290858765904161191229985245519871949378628131263513153683765553672655918133136828182050729012388157183851720391379381006921499997765191873729408614024320763554099291141052786589157823043612948619201525441997065264492145372001259366749278235381762443117203343617927241093647322654346302447381494008414208398219626199373278313446814209403507903682881070548386699522575055488393512785511441688197244526708647113340516\",\"r\":{\"dateofissuance\":\"16159515692057558658031632775257139859912833740243870833808276956469677196577164655991169139545328065546186056342530531355718904597216453319851305621683589202769847381737819412615902541110462703838858425423753481085962114120185123089078513531045426316918036549403698066078445947881055316312848598741184161901260446303171175343050250045452903485086185722998336149005743485268486377824763449026501058416292877646187105446333888525480394665310217044483841168928926515929150167890936706159800372381200383816724043496032886366767166850459338411710056171379538841845247931898550165532492578625954615979453881721709564750235\",\"drivingclass\":\"83649701835078373520097916558245060224505938113940626586910000950978790663411517512280043632278010831292224659523658613504637416710001103641231226266903556936380105758523760424939825687213460920436570466066231912959327201876189240504388424799892400351592593406285436824571943165913587899115814843543998396726679289422080229750418336051741708013580146373647528674381958028243228435161765957312248113519708734663989428761879029086059388435772829434952754093999424834120341657211221855300108096057633128467059590470639772605075954658131680801785637700237403873940041665483384938586320674338994185073499523485570537331062\",\"emailaddress\":\"96995643129591814391344614133120459563648002327749700279517548454036811217735867585059116635583558148259032071807493674533230465312311981127622542797279917256478867847832932893748528200469349058284133058865149153179959849308383505167342565738382180666525211256221655129861213392455759272915565057394420728271409215556596974900718332893753172173500744392522771654048192448229319313386967045678744665093451560743782910263014930200762027209565313884859542996067229707388839912195826334964819133016500346618083969320902775088800287566711941842968839787149808739739233388585677095545116231323172342995837636586249573194609\",\"drivinglicenseid\":\"102840929811153624977554462471309185033977661854754815794111114507549576719389525167082631547450413573293352276930065480432301200611396989595571202142654033217842162456070556560693402484110499573693863745648118310258284468114751958738878996458420605301017450868522680454545537837403398645500541915771765220093329728663621098538954397330411649083351383375839056527007892276284168437065687748085384178113959961057476582871100422859953560730152958588610850909069434658487744782540788968302663076149478487413357533660817020800754493642858564081116318655661240523146995256712471572605700346459123074377380656921337264554594\",\"familyname\":\"2428690037146701497427424649573806616639612325136606164619283916796880313617677563507218774958436668407050506838114136163250163675016510113975582318007560622124292458766639319715064358235569650961433812439763343736699708535945693241909905707497180931492818502593885932421170612418693515054756633264933222189766691632082890045477718331705366111669009551578289182848340651375008362238266590844461708981816856194045325523248527964502118319210042254240848590574645476930113881493472578612352948284862674703949781070309344526122291448990325949065193279599181502524961004046979227803224474342778516917124487012958845744311\",\"master_secret\":\"96236339155824229583363924057798366491998077727991424922911165403434522806469328114407334094535810942859512352089785125683335350062474092708044674085769524387654467267128528564551803293661877480971961092735622606052503557881856409855812611523475975566606131897917979412576797874632169829901968854843162299366867885636535326810998541141840561418097240137120398317445832694001031827068485975315937269024666370665530455146256019590700349556357390218401217383173228376078058967743472704019765210324846681867991543267171763037513180046865961560351035005185946817643006206395175857900512245900162751815626427008481585714891\"},\"rctxt\":\"54359809198312125478916383106913469635175253891208897419510030559787479974126666313900084654632259260010008369569778456071591398552341004538623276997178295939490854663263886825856426285604332554317424030793691008221895556474599466123873279022389276698551452690414982831059651505731449763128921782866843113361548859434294057249048041670761184683271568216202174527891374770703485794299697663353847310928998125365841476766767508733046891626759537001358973715760759776149482147060701775948253839125589216812475133616408444838011643485797584321993661048373877626880635937563283836661934456534313802815974883441215836680800\",\"z\":\"99592262675748359673042256590146366586480829950402370244401571195191609039150608482506917768910598228167758026656953725016982562881531475875469671976107506976812319765644401707559997823702387678953647104105378063905395973550729717937712350758544336716556268064226491839700352305793370980462034813589488455836259737325502578253339820590260554457468082536249525493340350556649403477875367398139579018197084796440810685458274393317299082017275568964540311198115802021902455672385575542594821996060452628805634468222196284384514736044680778624637228114693554834388824212714580770066729185685978935409859595244639193538156\"}},\"issuerId\":\"did:prism:604ba1764ab89993f9a74625cc4f3e04737919639293eb382cc7adc53767f550\"}"