Skip to content

Commit

Permalink
refactor: linting issues, dependency leaks and fix tests after all th…
Browse files Browse the repository at this point in the history
…e changes

Signed-off-by: Cristian G <[email protected]>
  • Loading branch information
cristianIOHK committed Jul 29, 2024
1 parent a0442c4 commit 5016bea
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.RawKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.SeedKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey

/**
* Apollo defines the set of cryptographic operations that are used in the Atala PRISM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import org.hyperledger.identus.walletsdk.domain.models.DID
import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
import org.hyperledger.identus.walletsdk.domain.models.DIDDocumentCoreProperty
import org.hyperledger.identus.walletsdk.domain.models.DIDResolver
import org.hyperledger.identus.walletsdk.domain.models.httpClient
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.domain.models.httpClient

class PrismDIDApiResolver(
private val apollo: Apollo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.hyperledger.identus.walletsdk.domain.models.PeerDID
import org.hyperledger.identus.walletsdk.domain.models.PrismDIDInfo
import org.hyperledger.identus.walletsdk.domain.models.StorableCredential
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.pluto.CredentialRecovery
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.pluto.CredentialRecovery
import org.hyperledger.identus.walletsdk.pluto.backup.models.BackupV0_0_1
import org.hyperledger.identus.walletsdk.pluto.data.AvailableClaims
import org.hyperledger.identus.walletsdk.pollux.models.CredentialRequestMeta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.hyperledger.identus.walletsdk.domain.models.PresentationClaims
import org.hyperledger.identus.walletsdk.domain.models.StorableCredential
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PrivateKey
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationOptions
import org.hyperledger.identus.walletsdk.pollux.models.PresentationSubmission
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptions
import java.security.interfaces.ECPublicKey

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hyperledger.identus.walletsdk.domain.models

import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import io.ktor.client.HttpClient as KtorClient

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.ktor.client.request.request
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpMethod
import io.ktor.http.Url
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.edgeagent.shared.PrismShared

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import kotlinx.serialization.Serializable
data class KeyValue(
val key: String,
val value: String
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import org.hyperledger.identus.walletsdk.apollo.utils.Secp256k1KeyPair
import org.hyperledger.identus.walletsdk.apollo.utils.Secp256k1PrivateKey
import org.hyperledger.identus.walletsdk.apollo.utils.X25519KeyPair
import org.hyperledger.identus.walletsdk.apollo.utils.X25519PrivateKey
import org.hyperledger.identus.walletsdk.domain.DIDCOMM_MESSAGING
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Apollo
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Castor
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Mercury
Expand Down Expand Up @@ -110,10 +111,7 @@ import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.pluto.PlutoBackupTask
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask
import org.hyperledger.identus.walletsdk.pluto.backup.models.BackupV0_0_1
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
import org.hyperledger.identus.walletsdk.pollux.models.CredentialRequestMeta
import org.hyperledger.identus.walletsdk.pollux.models.JWTCredential
import org.hyperledger.identus.walletsdk.pollux.models.SDJWTCredential
import org.kotlincrypto.hash.sha2.SHA256
import kotlin.text.encodeToByteArray

Expand Down Expand Up @@ -967,101 +965,102 @@ class EdgeAgent {
credential: T
): Presentation where T : Credential, T : ProvableCredential {
val attachmentFormat = request.attachments.first().format ?: CredentialType.Unknown.type
if (attachmentFormat == CredentialType.PRESENTATION_EXCHANGE_DEFINITIONS.type) {
request.attachments.find { it.data::class == AttachmentBase64::class }
?: throw EdgeAgentError.AttachmentTypeNotSupported()
// Presentation Exchange
return handlePresentationDefinitionRequest(request, credential)
} else {
// Presentation request from agent
var mediaType: String? = null
var presentationString: String?
when (credential::class) {
JWTCredential::class -> {
val subjectDID = credential.subject?.let {
DID(it)
} ?: DID("")
if (subjectDID.method != PRISM) {
throw PolluxError.InvalidPrismDID()
}
// Presentation request from agent
var mediaType: String? = null
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)
}

val privateKeyKeyPath = pluto.getPrismDIDKeyPathIndex(subjectDID).first()
val keyPair =
Secp256k1KeyPair.generateKeyPair(
seed,
KeyCurve(Curve.SECP256K1, privateKeyKeyPath)
)
val requestData = request.attachments.firstNotNullOf {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
CredentialType.ANONCREDS_PROOF_REQUEST.type -> {
val format = pollux.extractCredentialFormatFromMessage(request.attachments)
if (format != CredentialType.ANONCREDS_PROOF_REQUEST) {
throw EdgeAgentError.InvalidCredentialFormatError(CredentialType.ANONCREDS_PROOF_REQUEST)
}
val requestData = request.attachments.mapNotNull {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
presentationString = credential.presentation(
requestData.encodeToByteArray(),
listOf(
CredentialOperationsOptions.SubjectDID(subjectDID),
CredentialOperationsOptions.ExportableKey(keyPair.privateKey)
)
}.first()
val linkSecret = getLinkSecret()
presentationString = credential.presentation(
requestData.encodeToByteArray(),
listOf(
CredentialOperationsOptions.LinkSecret("", linkSecret.getValue()),
CredentialOperationsOptions.SchemaDownloader(api),
CredentialOperationsOptions.CredentialDefinitionDownloader(api)
)
mediaType = JWT_MEDIA_TYPE
)
}

CredentialType.JWT.type -> {
val subjectDID = credential.subject?.let {
DID(it)
} ?: DID("")
if (subjectDID.method != PRISM) {
throw PolluxError.InvalidPrismDID()
}

AnonCredential::class -> {
val format = pollux.extractCredentialFormatFromMessage(request.attachments)
if (format != CredentialType.ANONCREDS_PROOF_REQUEST) {
throw EdgeAgentError.InvalidCredentialFormatError(CredentialType.ANONCREDS_PROOF_REQUEST)
}
val requestData = request.attachments.mapNotNull {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
}.first()
val linkSecret = getLinkSecret()
presentationString = credential.presentation(
requestData.encodeToByteArray(),
listOf(
CredentialOperationsOptions.LinkSecret("", linkSecret.getValue()),
CredentialOperationsOptions.SchemaDownloader(api),
CredentialOperationsOptions.CredentialDefinitionDownloader(api)
)
val privateKeyKeyPath = pluto.getPrismDIDKeyPathIndex(subjectDID).first()
val keyPair =
Secp256k1KeyPair.generateKeyPair(
seed,
KeyCurve(Curve.SECP256K1, privateKeyKeyPath)
)
val requestData = request.attachments.firstNotNullOf {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
}

SDJWTCredential::class -> {
val requestData = request.attachments.mapNotNull {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
}.first().encodeToByteArray()
presentationString = credential.presentation(
requestData,
listOf(CredentialOperationsOptions.DisclosingClaims(listOf(credential.claims.toString())))
presentationString = credential.presentation(
requestData.encodeToByteArray(),
listOf(
CredentialOperationsOptions.SubjectDID(subjectDID),
CredentialOperationsOptions.ExportableKey(keyPair.privateKey)
)
)
mediaType = JWT_MEDIA_TYPE
}

mediaType = SD_JWT_VC_TYPE
}
CredentialType.SDJWT.type -> {
val requestData = request.attachments.mapNotNull {
when (it.data) {
is AttachmentJsonData -> it.data.data
else -> null
}
}.first().encodeToByteArray()
presentationString = credential.presentation(
requestData,
listOf(CredentialOperationsOptions.DisclosingClaims(listOf(credential.claims.toString())))
)

else -> {
throw EdgeAgentError.InvalidCredentialError(credential)
}
mediaType = SD_JWT_VC_TYPE
}

val attachmentDescriptor =
AttachmentDescriptor(
mediaType = mediaType,
data = AttachmentBase64(presentationString.base64UrlEncoded)
)
return Presentation(
from = request.to,
to = request.from,
thid = request.thid,
body = Presentation.Body(request.body.goalCode, request.body.comment),
attachments = arrayOf(attachmentDescriptor)
)
else -> {
throw EdgeAgentError.InvalidCredentialError(credential)
}
}

val attachmentDescriptor =
AttachmentDescriptor(
mediaType = mediaType,
data = AttachmentBase64(presentationString.base64UrlEncoded)
)

return Presentation(
from = request.to,
to = request.from,
thid = request.thid,
body = Presentation.Body(request.body.goalCode, request.body.comment),
attachments = arrayOf(attachmentDescriptor)
)
}

suspend fun initiatePresentationRequest(
Expand Down Expand Up @@ -1105,7 +1104,7 @@ class EdgeAgent {
requestPresentation: RequestPresentation,
credential: Credential
): Presentation {
if (credential::class != JWTCredential::class) {
if (credential !is ProvableCredential) {
throw EdgeAgentError.InvalidCredentialError(credential)
}

Expand All @@ -1132,7 +1131,7 @@ class EdgeAgent {
val attachmentDescriptor = AttachmentDescriptor(
mediaType = "application/json",
format = CredentialType.PRESENTATION_EXCHANGE_SUBMISSION.type,
data = AttachmentBase64(Json.encodeToString(presentationSubmissionProof).base64UrlEncoded)
data = AttachmentBase64(presentationSubmissionProof.base64UrlEncoded)
)
return Presentation(
body = Presentation.Body(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import org.hyperledger.identus.walletsdk.domain.buildingblocks.Mercury
import org.hyperledger.identus.walletsdk.domain.models.Api
import org.hyperledger.identus.walletsdk.domain.models.DID
import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.domain.models.MercuryError
import org.hyperledger.identus.walletsdk.domain.models.Message
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.didcommx.didcomm.diddoc.DIDCommService
import org.didcommx.didcomm.diddoc.DIDDoc
import org.didcommx.didcomm.diddoc.DIDDocResolver
import org.didcommx.didcomm.diddoc.VerificationMethod
import org.hyperledger.identus.walletsdk.domain.DIDCOMM_MESSAGING
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Castor
import org.hyperledger.identus.walletsdk.domain.models.CastorError
import org.hyperledger.identus.walletsdk.domain.models.Curve
Expand All @@ -21,8 +22,7 @@ import org.hyperledger.identus.walletsdk.domain.models.OctetPublicKey
import org.hyperledger.identus.walletsdk.mercury.CRV
import org.hyperledger.identus.walletsdk.mercury.MULTIBASE_BYTES_SIZE
import org.hyperledger.identus.walletsdk.mercury.X
import java.util.Optional
import org.hyperledger.identus.walletsdk.domain.DIDCOMM_MESSAGING
import java.util.*

/**
* A resolver that resolves a Decentralized Identifier (DID) to its corresponding DID Document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import org.hyperledger.identus.walletsdk.domain.models.Claim
import org.hyperledger.identus.walletsdk.domain.models.ClaimType
import org.hyperledger.identus.walletsdk.domain.models.Credential
import org.hyperledger.identus.walletsdk.domain.models.CredentialOperationsOptions
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.domain.models.PolluxError
import org.hyperledger.identus.walletsdk.domain.models.ProvableCredential
import org.hyperledger.identus.walletsdk.domain.models.StorableCredential
import org.hyperledger.identus.walletsdk.domain.models.UnknownError
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask.AnonCredentialBackUp.RevocationRegistry

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import org.hyperledger.identus.apollo.base64.base64UrlDecodedBytes
import org.hyperledger.identus.walletsdk.apollo.ApolloImpl
import org.hyperledger.identus.walletsdk.apollo.utils.Ed25519KeyPair
import org.hyperledger.identus.walletsdk.apollo.utils.X25519KeyPair
import org.hyperledger.identus.walletsdk.domain.DIDCOMM_MESSAGING
import org.hyperledger.identus.walletsdk.domain.models.Curve
import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.CurveKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.KeyPair
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.KeyTypes
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.RawKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey
import org.hyperledger.identus.walletsdk.edgeagent.DIDCOMM_MESSAGING
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hyperledger.identus.walletsdk.edgeagent

import org.hyperledger.identus.walletsdk.domain.DIDCOMM_MESSAGING
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Castor
import org.hyperledger.identus.walletsdk.domain.models.DID
import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
Expand Down
Loading

0 comments on commit 5016bea

Please sign in to comment.