diff --git a/build.sbt b/build.sbt index ace4154ca6..fd35bd175d 100644 --- a/build.sbt +++ b/build.sbt @@ -70,7 +70,7 @@ lazy val V = new { val testContainersJavaKeycloak = "3.2.0" // scala-steward:off val doobie = "1.0.0-RC5" - val quill = "4.8.4" + val quill = "4.8.5" val flyway = "9.22.3" val postgresDriver = "42.7.3" val logback = "1.4.14" @@ -125,6 +125,7 @@ lazy val D = new { val jakartaJson: ModuleID = "org.glassfish" % "jakarta.json" % "2.0.1" val ironVC: ModuleID = "com.apicatalog" % "iron-verifiable-credentials" % "0.14.0" val scodecBits: ModuleID = "org.scodec" %% "scodec-bits" % "1.1.38" + val jaywayJsonPath: ModuleID = "com.jayway.jsonpath" % "json-path" % "2.9.0" // https://mvnrepository.com/artifact/org.didcommx/didcomm/0.3.2 val didcommx: ModuleID = "org.didcommx" % "didcomm" % "0.3.2" @@ -201,7 +202,8 @@ lazy val D_SharedJson = new { D.jakartaJson, D.ironVC, D.scodecBits, - D.networkntJsonSchemaValidator + D.networkntJsonSchemaValidator, + D.jaywayJsonPath ) } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala index dbaf3e7676..ec78799452 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/BackgroundJobsHelper.scala @@ -16,8 +16,7 @@ import org.hyperledger.identus.castor.core.service.DIDService import org.hyperledger.identus.mercury.{AgentPeerService, DidAgent} import org.hyperledger.identus.mercury.model.DidId import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation -import org.hyperledger.identus.pollux.core.model.error.CredentialServiceError -import org.hyperledger.identus.pollux.core.model.error.PresentationError +import org.hyperledger.identus.pollux.core.model.error.{CredentialServiceError, PresentationError} import org.hyperledger.identus.pollux.core.model.DidCommID import org.hyperledger.identus.pollux.core.service.CredentialService import org.hyperledger.identus.pollux.sdjwt.SDJWT.* diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala index 0bf8f7fb61..85106e084f 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/agent/server/jobs/PresentBackgroundJobs.scala @@ -106,7 +106,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, InvitationGenerated, _, _, @@ -124,15 +123,15 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _ ) => ZIO.unit - case PresentationRecord(_, _, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(_, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.unit - case PresentationRecord(id, _, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.fail(NotImplemented) - case PresentationRecord(id, _, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.fail(NotImplemented) - case PresentationRecord(id, _, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.fail(NotImplemented) - case PresentationRecord(id, _, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.fail(NotImplemented) case PresentationRecord( id, @@ -142,7 +141,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, RequestPending, _, _, @@ -168,7 +166,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, RequestPending, _, _, @@ -194,7 +191,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, RequestSent, _, _, @@ -220,7 +216,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, RequestReceived, _, _, @@ -246,7 +241,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, RequestRejected, _, _, @@ -272,7 +266,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, ProblemReportPending, _, _, @@ -290,7 +283,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _ ) => ZIO.fail(NotImplemented) - case PresentationRecord(id, _, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.fail(NotImplemented) case PresentationRecord( id, @@ -300,7 +293,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, ProblemReportReceived, _, _, @@ -326,7 +318,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationPending, _, _, @@ -353,7 +344,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationPending, credentialFormat, _, @@ -386,7 +376,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationGenerated, _, _, @@ -413,7 +402,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationGenerated, _, _, @@ -433,7 +421,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { ZIO.logDebug("PresentationRecord: PresentationGenerated") *> ZIO.unit Prover.handlePresentationGenerated(id, presentation) - case PresentationRecord(id, _, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => + case PresentationRecord(id, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => ZIO.logDebug("PresentationRecord: PresentationSent") *> ZIO.unit case PresentationRecord( id, @@ -443,7 +431,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationReceived, _, _, @@ -469,7 +456,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationReceived, _, _, @@ -495,7 +481,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationReceived, credentialFormat, invitation, @@ -523,7 +508,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationVerificationFailed, _, _, @@ -549,7 +533,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationAccepted, _, _, @@ -575,7 +558,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationVerified, _, _, @@ -601,7 +583,6 @@ object PresentBackgroundJobs extends BackgroundJobsHelper { _, _, _, - _, PresentationRejected, _, _, diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/IssueControllerImpl.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/IssueControllerImpl.scala index 01e73794ce..48a5a5619d 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/IssueControllerImpl.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/IssueControllerImpl.scala @@ -24,8 +24,7 @@ import org.hyperledger.identus.pollux.core.model.CredentialFormat.{AnonCreds, JW import org.hyperledger.identus.pollux.core.model.IssueCredentialRecord.Role import org.hyperledger.identus.pollux.core.service.CredentialService import org.hyperledger.identus.shared.models.{KeyId, WalletAccessContext} -import zio.{URLayer, ZIO, ZLayer} -import zio.Duration +import zio.{Duration, URLayer, ZIO, ZLayer} import scala.language.implicitConversions class IssueControllerImpl( diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialOfferInvitation.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialOfferInvitation.scala index 720abed0c5..aa7a4c724f 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialOfferInvitation.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/issue/controller/http/IssueCredentialOfferInvitation.scala @@ -58,7 +58,7 @@ object IssueCredentialOfferInvitation { description = "The invitation message encoded as a URL. This URL follows the Out of [Band 2.0 protocol](https://identity.foundation/didcomm-messaging/spec/v2.0/#out-of-band-messages) and can be used to generate a QR code for example.", example = - "https://my.domain.com/path?_oob=eyJAaWQiOiIzZmE4NWY2NC01NzE3LTQ1NjItYjNmYy0yYzk2M2Y2NmFmYTYiLCJAdHlwZSI6Imh0dHBzOi8vZGlkY29tbS5vcmcvbXktZmFtaWx5LzEuMC9teS1tZXNzYWdlLXR5cGUiLCJkaWQiOiJXZ1d4cXp0ck5vb0c5MlJYdnhTVFd2IiwiaW1hZ2VVcmwiOiJodHRwOi8vMTkyLjE2OC41Ni4xMDEvaW1nL2xvZ28uanBnIiwibGFiZWwiOiJCb2IiLCJyZWNpcGllbnRLZXlzIjpbIkgzQzJBVnZMTXY2Z21NTmFtM3VWQWpacGZrY0pDd0R3blpuNnozd1htcVBWIl0sInJvdXRpbmdLZXlzIjpbIkgzQzJBVnZMTXY2Z21NTmFtM3VWQWpacGZrY0pDd0R3blpuNnozd1htcVBWIl0sInNlcnZpY2VFbmRwb2ludCI6Imh0dHA6Ly8xOTIuMTY4LjU2LjEwMTo4MDIwIn0=" + "https://my.domain.com/path?_oob=e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c0tNZTh2U1NXa1lkWkNwbjRZVmlQRVJmZEdBaGRMQUdIZ3gyTEdKd2ZtQS5WejZNa3B3MWtTYWJCTXprQTN2NTl0UUZuaDNGdGtLeTZ4TGhMeGQ5UzZCQW9hQmcyLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQTZMeTh4T1RJdU1UWTRMakV1TXpjNk9EQTRNQzlrYVdSamIyMXRJaXdpY2lJNlcxMHNJbUVpT2xzaVpHbGtZMjl0YlM5Mk1pSmRmWDAifX19XSwiY3JlYXRlZF90aW1lIjoxNzI0ODUxMTM5LCJleHBpcmVzX3RpbWUiOjE3MjQ4NTE0Mzl9=" ) } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/OOBPresentationInvitation.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/OOBPresentationInvitation.scala index 2061a3a4db..21897165d1 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/OOBPresentationInvitation.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/presentproof/controller/http/OOBPresentationInvitation.scala @@ -58,7 +58,7 @@ object OOBPresentationInvitation { description = "The invitation message encoded as a URL. This URL follows the Out of [Band 2.0 protocol](https://identity.foundation/didcomm-messaging/spec/v2.0/#out-of-band-messages) and can be used to generate a QR code for example.", example = - "https://my.domain.com/path?_oob=eyJAaWQiOiIzZmE4NWY2NC01NzE3LTQ1NjItYjNmYy0yYzk2M2Y2NmFmYTYiLCJAdHlwZSI6Imh0dHBzOi8vZGlkY29tbS5vcmcvbXktZmFtaWx5LzEuMC9teS1tZXNzYWdlLXR5cGUiLCJkaWQiOiJXZ1d4cXp0ck5vb0c5MlJYdnhTVFd2IiwiaW1hZ2VVcmwiOiJodHRwOi8vMTkyLjE2OC41Ni4xMDEvaW1nL2xvZ28uanBnIiwibGFiZWwiOiJCb2IiLCJyZWNpcGllbnRLZXlzIjpbIkg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cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authentication/oidc/KeycloakAuthenticatorSpec.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authentication/oidc/KeycloakAuthenticatorSpec.scala index 412147bfa9..fc290d5269 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authentication/oidc/KeycloakAuthenticatorSpec.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authentication/oidc/KeycloakAuthenticatorSpec.scala @@ -83,12 +83,11 @@ object KeycloakAuthenticatorSpec suite("KeycloakAuthenticatorSpec")( basicSpec - .provide( + .provideSome[KeycloakContainerCustom]( KeycloakAuthenticatorImpl.layer, ZLayer.fromZIO(initializeClient) >>> KeycloakClientImpl.authzClientLayer >+> KeycloakClientImpl.layer, keycloakConfigLayer(), keycloakAdminClientLayer, - keycloakContainerLayer, Client.default, KeycloakPermissionManagementService.layer, WalletManagementServiceImpl.layer, @@ -100,12 +99,11 @@ object KeycloakAuthenticatorSpec ZLayer.succeed(WalletAdministrationContext.Admin()) ), disabledAutoRptSpec - .provide( + .provideSome[KeycloakContainerCustom]( KeycloakAuthenticatorImpl.layer, ZLayer.fromZIO(initializeClient) >>> KeycloakClientImpl.authzClientLayer >+> KeycloakClientImpl.layer, keycloakConfigLayer(authUpgradeToRPT = false), keycloakAdminClientLayer, - keycloakContainerLayer, Client.default, KeycloakPermissionManagementService.layer, WalletManagementServiceImpl.layer, @@ -117,6 +115,7 @@ object KeycloakAuthenticatorSpec ZLayer.succeed(WalletAdministrationContext.Admin()) ) ) + .provideLayerShared(keycloakContainerLayer) .provide(Runtime.removeDefaultLoggers) @@ TestAspect.sequential } diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authorization/keycloak/admin/KeycloakPermissionManagementServiceSpec.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authorization/keycloak/admin/KeycloakPermissionManagementServiceSpec.scala index c4e98d6d17..1e0001b2b3 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authorization/keycloak/admin/KeycloakPermissionManagementServiceSpec.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/iam/authorization/keycloak/admin/KeycloakPermissionManagementServiceSpec.scala @@ -39,22 +39,24 @@ object KeycloakPermissionManagementServiceSpec multitenantSuite ) @@ sequential @@ TestAspect.before(DBTestUtils.runMigrationAgentDB) - s.provide( - Client.default, - keycloakContainerLayer, - keycloakAdminConfigLayer, - KeycloakAdmin.layer, - KeycloakPermissionManagementService.layer, - KeycloakAuthenticatorImpl.layer, - ZLayer.fromZIO(initializeClient) >>> KeycloakClientImpl.authzClientLayer >+> KeycloakClientImpl.layer, - keycloakConfigLayer(), - WalletManagementServiceImpl.layer, - JdbcWalletNonSecretStorage.layer, - JdbcWalletSecretStorage.layer, - contextAwareTransactorLayer, - pgContainerLayer, - apolloLayer - ).provide(Runtime.removeDefaultLoggers) + s + .provideSome[KeycloakContainerCustom]( + Client.default, + keycloakAdminConfigLayer, + KeycloakAdmin.layer, + KeycloakPermissionManagementService.layer, + KeycloakAuthenticatorImpl.layer, + ZLayer.fromZIO(initializeClient) >>> KeycloakClientImpl.authzClientLayer >+> KeycloakClientImpl.layer, + keycloakConfigLayer(), + WalletManagementServiceImpl.layer, + JdbcWalletNonSecretStorage.layer, + JdbcWalletSecretStorage.layer, + contextAwareTransactorLayer, + pgContainerLayer, + apolloLayer + ) + .provideLayerShared(keycloakContainerLayer) + .provide(Runtime.removeDefaultLoggers) } private val successfulCasesSuite = suite("Successful Cases")( diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala index 44ef28be22..7e37850272 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/oid4vci/domain/OIDCCredentialIssuerServiceSpec.scala @@ -74,7 +74,7 @@ object OIDCCredentialIssuerServiceSpec MockDIDService.resolveDIDExpectation(issuerDidMetadata, issuerDidData) private val issuerManagedDIDServiceExpectations = - MockManagedDIDService.javaKeyPairWithDIDExpectation(issuerKp) + MockManagedDIDService.findDIDKeyPairExpectation(issuerKp) private val getIssuerPrismDidWalletIdExpectations = MockDIDNonSecretStorage.getPrismDidWalletIdExpectation(issuerDidData.id, WalletId.default) @@ -139,7 +139,6 @@ object OIDCCredentialIssuerServiceSpec None, credentialDefinition ) - _ <- zio.Console.printLine(jwt) jwtObject <- ZIO.fromTry(Try(JWSObject.parse(jwt.value))) payload <- ZIO.fromEither(Json.decoder.decodeJson(jwtObject.getPayload.toString).flatMap(_.as[Json.Obj])) vc <- ZIO.fromEither(payload.get("vc").get.as[Json.Obj]) diff --git a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionLookupAndPaginationSpec.scala b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionLookupAndPaginationSpec.scala index f4d844dd54..6da8f500fb 100644 --- a/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionLookupAndPaginationSpec.scala +++ b/cloud-agent/service/server/src/test/scala/org/hyperledger/identus/pollux/credentialdefinition/CredentialDefinitionLookupAndPaginationSpec.scala @@ -73,7 +73,7 @@ object CredentialDefinitionLookupAndPaginationSpec ) ).provideSomeLayerShared( mockManagedDIDServiceLayer.exactly(20).toLayer >+> testEnvironmentLayer - ) + ).provide(Runtime.removeDefaultLoggers) private val credentialDefinitionPaginationSpec = suite("credential-definition-registry pagination logic")( test("pagination of the first page with the empty query params") { diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDService.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDService.scala index bab1a9933c..e8cba848c1 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDService.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDService.scala @@ -10,8 +10,6 @@ import org.hyperledger.identus.shared.crypto.{Ed25519KeyPair, Secp256k1KeyPair, import org.hyperledger.identus.shared.models.WalletAccessContext import zio.* -import java.security.{PrivateKey as JavaPrivateKey, PublicKey as JavaPublicKey} - /** A wrapper around Castor's DIDService providing key-management capability. Analogous to the secretAPI in * indy-wallet-sdk. */ @@ -23,12 +21,6 @@ trait ManagedDIDService { def syncUnconfirmedUpdateOperations: ZIO[WalletAccessContext, GetManagedDIDError, Unit] - @deprecated("will be dropped in favor of findDIDKeyPair") - def javaKeyPairWithDID( - did: CanonicalPrismDID, - keyId: String - ): URIO[WalletAccessContext, Option[(JavaPrivateKey, JavaPublicKey)]] - def findDIDKeyPair( did: CanonicalPrismDID, keyId: String diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala index 7f0614abe9..b021c28d33 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceImpl.scala @@ -17,7 +17,6 @@ import org.hyperledger.identus.shared.crypto.{Apollo, Ed25519KeyPair, Secp256k1K import org.hyperledger.identus.shared.models.WalletAccessContext import zio.* -import java.security.{PrivateKey as JavaPrivateKey, PublicKey as JavaPublicKey} import scala.collection.immutable.ArraySeq import scala.language.implicitConversions @@ -55,23 +54,6 @@ class ManagedDIDServiceImpl private[walletapi] ( def syncUnconfirmedUpdateOperations: ZIO[WalletAccessContext, GetManagedDIDError, Unit] = syncUnconfirmedUpdateOperationsByDID(did = None) - def javaKeyPairWithDID( - did: CanonicalPrismDID, - keyId: String - ): URIO[WalletAccessContext, Option[(JavaPrivateKey, JavaPublicKey)]] = { - findDIDKeyPair(did, keyId) - .flatMap { - case None => ZIO.none - case Some(keyPair: Secp256k1KeyPair) => ZIO.some(keyPair) - case _ => ZIO.dieMessage("Only secp256k1 keypair is supported for Java KeyPair conversion") - } - .map( - _.map { keyPair => - (keyPair.privateKey.toJavaPrivateKey, keyPair.publicKey.toJavaPublicKey) - } - ) - } - override def findDIDKeyPair( did: CanonicalPrismDID, keyId: String diff --git a/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/service/MockManagedDIDService.scala b/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/service/MockManagedDIDService.scala index 7ab0b0e395..98c2d01969 100644 --- a/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/service/MockManagedDIDService.scala +++ b/cloud-agent/service/wallet-api/src/test/scala/org/hyperledger/identus/agent/walletapi/service/MockManagedDIDService.scala @@ -16,13 +16,11 @@ import zio.* import zio.mock.* import zio.test.Assertion -import java.security.{PrivateKey as JavaPrivateKey, PublicKey as JavaPublicKey} - object MockManagedDIDService extends Mock[ManagedDIDService] { object GetManagedDIDState extends Effect[CanonicalPrismDID, GetManagedDIDError, Option[ManagedDIDState]] - object JavaKeyPairWithDID - extends Effect[(CanonicalPrismDID, String), Nothing, Option[(JavaPrivateKey, JavaPublicKey)]] + object FindDIDKeyPair + extends Effect[(CanonicalPrismDID, String), Nothing, Option[Secp256k1KeyPair | Ed25519KeyPair | X25519KeyPair]] override val compose: URLayer[mock.Proxy, ManagedDIDService] = ZLayer { @@ -35,16 +33,11 @@ object MockManagedDIDService extends Mock[ManagedDIDService] { override def syncUnconfirmedUpdateOperations: IO[GetManagedDIDError, Unit] = ??? - override def javaKeyPairWithDID( - did: CanonicalPrismDID, - keyId: String - ): UIO[Option[(JavaPrivateKey, JavaPublicKey)]] = - proxy(JavaKeyPairWithDID, did, keyId) - override def findDIDKeyPair( did: CanonicalPrismDID, keyId: String - ): UIO[Option[Secp256k1KeyPair | Ed25519KeyPair | X25519KeyPair]] = ??? + ): UIO[Option[Secp256k1KeyPair | Ed25519KeyPair | X25519KeyPair]] = + proxy(FindDIDKeyPair, (did, keyId)) override def getManagedDIDState( did: CanonicalPrismDID @@ -98,11 +91,9 @@ object MockManagedDIDService extends Mock[ManagedDIDService] { ) ) - def javaKeyPairWithDIDExpectation(ecKeyPair: Secp256k1KeyPair): Expectation[ManagedDIDService] = - MockManagedDIDService.JavaKeyPairWithDID( + def findDIDKeyPairExpectation(keyPair: Secp256k1KeyPair): Expectation[ManagedDIDService] = + MockManagedDIDService.FindDIDKeyPair( assertion = Assertion.anything, - result = Expectation.value( - Some((ecKeyPair.privateKey.toJavaPrivateKey, ecKeyPair.publicKey.toJavaPublicKey)) - ) + result = Expectation.value(Some(keyPair)) ) } diff --git a/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/ConnectionRecord.scala b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/ConnectionRecord.scala index 64d6a287cf..026e651312 100644 --- a/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/ConnectionRecord.scala +++ b/connect/core/src/main/scala/org/hyperledger/identus/connect/core/model/ConnectionRecord.scala @@ -3,8 +3,7 @@ package org.hyperledger.identus.connect.core.model import org.hyperledger.identus.connect.core.model.ConnectionRecord.{ProtocolState, Role} import org.hyperledger.identus.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse} import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation -import org.hyperledger.identus.shared.models.Failure -import org.hyperledger.identus.shared.models.WalletId +import org.hyperledger.identus.shared.models.{Failure, WalletId} import java.time.temporal.ChronoUnit import java.time.Instant diff --git a/mercury/agent/src/main/scala/org/hyperledger/identus/mercury/CoordinateMediationPrograms.scala b/mercury/agent/src/main/scala/org/hyperledger/identus/mercury/CoordinateMediationPrograms.scala index c686ff9ce0..800a0a772c 100644 --- a/mercury/agent/src/main/scala/org/hyperledger/identus/mercury/CoordinateMediationPrograms.scala +++ b/mercury/agent/src/main/scala/org/hyperledger/identus/mercury/CoordinateMediationPrograms.scala @@ -1,6 +1,6 @@ package org.hyperledger.identus.mercury -import io.circe._ +import io.circe.* import io.circe.parser.* import org.hyperledger.identus.* import org.hyperledger.identus.mercury.model.* diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/PresentationRecord.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/PresentationRecord.scala index 47993a370b..88c03788de 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/PresentationRecord.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/PresentationRecord.scala @@ -1,6 +1,5 @@ package org.hyperledger.identus.pollux.core.model -import org.hyperledger.identus.mercury.model.DidId import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation import org.hyperledger.identus.mercury.protocol.presentproof.{Presentation, ProposePresentation, RequestPresentation} import org.hyperledger.identus.shared.models.{Failure, WalletAccessContext, WalletId} @@ -20,7 +19,6 @@ final case class PresentationRecord( schemaId: Option[String], connectionId: Option[String], role: PresentationRecord.Role, - subjectId: DidId, // TODO Remove protocolState: PresentationRecord.ProtocolState, credentialFormat: CredentialFormat, invitation: Option[Invitation], @@ -55,7 +53,6 @@ object PresentationRecord { schemaId: Option[String], connectionId: Option[String], role: Role, - subjectId: DidId, protocolState: ProtocolState, credentialFormat: CredentialFormat, invitation: Option[Invitation], @@ -80,7 +77,6 @@ object PresentationRecord { schemaId, connectionId, role, - subjectId, protocolState, credentialFormat, invitation, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala index cd4d35ffbc..ea153627e7 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImpl.scala @@ -4,7 +4,6 @@ import cats.implicits.* import io.circe.* import io.circe.parser.* import io.circe.syntax.* -import io.circe.Json import org.hyperledger.identus.agent.walletapi.model.{ManagedDIDState, PublicationState} import org.hyperledger.identus.agent.walletapi.service.ManagedDIDService import org.hyperledger.identus.agent.walletapi.storage.GenericSecretStorage @@ -561,14 +560,18 @@ class CredentialServiceImpl( for { issuingKeyId <- getKeyId(jwtIssuerDID, verificationRelationship, EllipticCurve.SECP256K1) ecKeyPair <- managedDIDService - .javaKeyPairWithDID(jwtIssuerDID.asCanonical, issuingKeyId) + .findDIDKeyPair(jwtIssuerDID.asCanonical, issuingKeyId) + .flatMap { + case Some(keyPair: Secp256k1KeyPair) => ZIO.some(keyPair) + case _ => ZIO.none + } .someOrFail(KeyPairNotFoundInWallet(jwtIssuerDID, issuingKeyId, "Secp256k1")) .orDieAsUnmanagedFailure - (privateKey, publicKey) = ecKeyPair + Secp256k1KeyPair(publicKey, privateKey) = ecKeyPair jwtIssuer = JwtIssuer( org.hyperledger.identus.pollux.vc.jwt.DID(jwtIssuerDID.toString), - ES256KSigner(privateKey, keyId), - publicKey + ES256KSigner(privateKey.toJavaPrivateKey, keyId), + publicKey.toJavaPublicKey ) } yield jwtIssuer } diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala index 3e8c8a5784..48afbdfa78 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceImpl.scala @@ -421,7 +421,6 @@ private class PresentationServiceImpl( connectionId = connectionId, schemaId = None, // TODO REMOVE from DB role = PresentationRecord.Role.Verifier, - subjectId = pairwiseProverDID.getOrElse(DidId("TODO REMOVE")), // TODO REMOVE from DB protocolState = invitation.fold(PresentationRecord.ProtocolState.RequestPending)(_ => PresentationRecord.ProtocolState.InvitationGenerated ), @@ -499,8 +498,6 @@ private class PresentationServiceImpl( connectionId = connectionId, schemaId = None, role = Role.Prover, - subjectId = - request.to.getOrElse(throw RuntimeException(s"RequestPresentation from field is missing")), // TODO REMOVE protocolState = PresentationRecord.ProtocolState.RequestReceived, credentialFormat = format, invitation = None, diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/model/presentation/PresentationAttachmentSpec.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/model/presentation/PresentationAttachmentSpec.scala index b4e77143e7..725e81271d 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/model/presentation/PresentationAttachmentSpec.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/model/presentation/PresentationAttachmentSpec.scala @@ -6,6 +6,8 @@ import io.circe.Json import munit.* import org.hyperledger.identus.pollux.prex.* +import scala.language.implicitConversions + class PresentationAttachmentSpec extends ZSuite { test("Verifier Request Presentation Attachment") { diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/PresentationRepositorySpecSuite.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/PresentationRepositorySpecSuite.scala index 5ebfe3233e..3491c070db 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/PresentationRepositorySpecSuite.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/PresentationRepositorySpecSuite.scala @@ -25,7 +25,6 @@ object PresentationRepositorySpecSuite { schemaId = None, connectionId = None, role = PresentationRecord.Role.Verifier, - subjectId = DidId("did:prism:aaa"), protocolState = PresentationRecord.ProtocolState.RequestPending, credentialFormat = CredentialFormat.JWT, invitation = None, diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala index 6cc1ac6efa..3f1fde1906 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala @@ -11,12 +11,7 @@ import org.hyperledger.identus.mercury.protocol.issuecredential.* import org.hyperledger.identus.pollux.anoncreds.AnoncredCredential import org.hyperledger.identus.pollux.core.model.* import org.hyperledger.identus.pollux.core.model.error.CredentialServiceError -import org.hyperledger.identus.pollux.core.model.error.CredentialServiceError.{ - RecordNotFound, - RecordNotFoundForThreadIdAndStates, - UnsupportedDidFormat, - * -} +import org.hyperledger.identus.pollux.core.model.error.CredentialServiceError.* import org.hyperledger.identus.pollux.core.model.schema.CredentialDefinition import org.hyperledger.identus.pollux.core.model.IssueCredentialRecord.{ProtocolState, Role} import org.hyperledger.identus.shared.models.{KeyId, UnmanagedFailureException, WalletAccessContext, WalletId} @@ -57,11 +52,11 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS private val holderManagedDIDServiceExpectations = MockManagedDIDService.getManagedDIDStateExpectation(holderOp) - ++ MockManagedDIDService.javaKeyPairWithDIDExpectation(holderKp) + ++ MockManagedDIDService.findDIDKeyPairExpectation(holderKp) private val issuerManagedDIDServiceExpectations = MockManagedDIDService.getManagedDIDStateExpectation(issuerOp) - ++ MockManagedDIDService.javaKeyPairWithDIDExpectation(issuerKp) + ++ MockManagedDIDService.findDIDKeyPairExpectation(issuerKp) private val singleWalletJWTCredentialSpec = suite("Single Wallet JWT Credential")( diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifierSpec.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifierSpec.scala index d76a00d35c..eeb66d593d 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifierSpec.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceNotifierSpec.scala @@ -28,7 +28,6 @@ object PresentationServiceNotifierSpec extends ZIOSpecDefault with PresentationS None, None, PresentationRecord.Role.Verifier, - DidId(""), ProtocolState.RequestPending, CredentialFormat.JWT, None, diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/verification/VcVerificationServiceSpecHelper.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/verification/VcVerificationServiceSpecHelper.scala index ed178729fd..3ae6b795dd 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/verification/VcVerificationServiceSpecHelper.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/verification/VcVerificationServiceSpecHelper.scala @@ -28,7 +28,7 @@ trait VcVerificationServiceSpecHelper { protected val issuerManagedDIDServiceExpectations: Expectation[ManagedDIDService] = MockManagedDIDService.getManagedDIDStateExpectation(issuerOp) - ++ MockManagedDIDService.javaKeyPairWithDIDExpectation(issuerKp) + ++ MockManagedDIDService.findDIDKeyPairExpectation(issuerKp) protected val issuerDidResolverLayer: ZLayer[Any, Nothing, PrismDidResolver] = (issuerDidServiceExpectations ++ issuerManagedDIDServiceExpectations).toLayer >>> ZLayer.fromFunction(PrismDidResolver(_)) diff --git a/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinition.scala b/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinition.scala index 5789c214c0..7a5b8ac47f 100644 --- a/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinition.scala +++ b/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinition.scala @@ -4,12 +4,22 @@ import com.networknt.schema.{JsonSchema, SpecVersion} import io.circe.* import io.circe.generic.semiauto.* import io.circe.Json as CirceJson -import org.hyperledger.identus.shared.json.{JsonInterop, JsonSchemaError, JsonSchemaUtils} +import org.hyperledger.identus.shared.json.{JsonInterop, JsonPath, JsonPathError, JsonSchemaError, JsonSchemaUtils} import zio.* import zio.json.ast.Json as ZioJson -// TODO: define proper type -type JsonPath = String +opaque type JsonPathValue = String + +object JsonPathValue { + given Encoder[JsonPathValue] = Encoder.encodeString + given Decoder[JsonPathValue] = Decoder.decodeString + given Conversion[String, JsonPathValue] = identity + + extension (jpv: JsonPathValue) { + def toJsonPath: IO[JsonPathError, JsonPath] = JsonPath.compile(jpv) + def value: String = jpv + } +} opaque type FieldFilter = ZioJson @@ -29,10 +39,11 @@ object FieldFilter { case class Field( id: Option[String] = None, - path: Seq[JsonPath] = Seq.empty, + path: Seq[JsonPathValue] = Seq.empty, name: Option[String] = None, purpose: Option[String] = None, - filter: Option[FieldFilter] = None + filter: Option[FieldFilter] = None, + optional: Option[Boolean] = None ) object Field { diff --git a/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidator.scala b/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidator.scala index 3160d373dc..9b47a914ae 100644 --- a/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidator.scala +++ b/pollux/prex/src/main/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidator.scala @@ -1,10 +1,16 @@ package org.hyperledger.identus.pollux.prex import org.hyperledger.identus.pollux.prex.PresentationDefinitionError.{ + InvalidFilterJsonPath, InvalidFilterJsonSchema, JsonSchemaOptionNotSupported } -import org.hyperledger.identus.shared.json.{JsonSchemaError, JsonSchemaValidator, JsonSchemaValidatorImpl} +import org.hyperledger.identus.shared.json.{ + JsonPathError, + JsonSchemaError, + JsonSchemaValidator, + JsonSchemaValidatorImpl +} import org.hyperledger.identus.shared.models.{Failure, StatusCode} import zio.* @@ -15,6 +21,12 @@ sealed trait PresentationDefinitionError extends Failure { } object PresentationDefinitionError { + final case class InvalidFilterJsonPath(path: String, error: JsonPathError) extends PresentationDefinitionError { + override def statusCode: StatusCode = StatusCode.BadRequest + override def userFacingMessage: String = + s"PresentationDefinition input_descriptors path '$path' is not a valid JsonPath" + } + final case class InvalidFilterJsonSchema(json: String, error: JsonSchemaError) extends PresentationDefinitionError { override def statusCode: StatusCode = StatusCode.BadRequest override def userFacingMessage: String = @@ -47,17 +59,28 @@ object PresentationDefinitionValidatorImpl { class PresentationDefinitionValidatorImpl(filterSchemaValidator: JsonSchemaValidator) extends PresentationDefinitionValidator { override def validate(pd: PresentationDefinition): IO[PresentationDefinitionError, Unit] = { - val filters = pd.input_descriptors + val fields = pd.input_descriptors .flatMap(_.constraints.fields) .flatten - .flatMap(_.filter) + + val paths = fields.flatMap(_.path) + val filters = fields.flatMap(_.filter) for { + _ <- validateJsonPaths(paths) _ <- validateFilters(filters) _ <- validateAllowedFilterSchemaKeys(filters) } yield () } + private def validateJsonPaths(paths: Seq[JsonPathValue]): IO[PresentationDefinitionError, Unit] = { + ZIO + .foreach(paths) { path => + path.toJsonPath.mapError(InvalidFilterJsonPath(path.value, _)) + } + .unit + } + // while we use full-blown json-schema library, we limit the schema optiton // to make sure verfier don't go crazy on schema causing problem with holder interoperability // see SDK supported keys https://github.com/hyperledger/identus-edge-agent-sdk-ts/blob/da27890ad4ff3d32576bda8bc99a1185e7239a4c/src/domain/models/VerifiableCredential.ts#L120 diff --git a/pollux/prex/src/test/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidatorSpec.scala b/pollux/prex/src/test/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidatorSpec.scala index bd57c15230..108168ae62 100644 --- a/pollux/prex/src/test/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidatorSpec.scala +++ b/pollux/prex/src/test/scala/org/hyperledger/identus/pollux/prex/PresentationDefinitionValidatorSpec.scala @@ -4,6 +4,7 @@ import io.circe.* import io.circe.generic.auto.* import io.circe.parser.* import org.hyperledger.identus.pollux.prex.PresentationDefinitionError.{ + InvalidFilterJsonPath, InvalidFilterJsonSchema, JsonSchemaOptionNotSupported } @@ -68,9 +69,6 @@ object PresentationDefinitionValidatorSpec extends ZIOSpecDefault { pd <- ZIO .fromEither(decode[ExampleTransportEnvelope](pdJson)) .map(_.presentation_definition) - filters <- ZIO - .succeed(pd.input_descriptors.flatMap(_.constraints.fields.getOrElse(Nil))) - .map(_.flatMap(_.filter)) exit <- validator.validate(pd).exit } yield assert(exit)(failsWithA[InvalidFilterJsonSchema]) }, @@ -103,11 +101,39 @@ object PresentationDefinitionValidatorSpec extends ZIOSpecDefault { pd <- ZIO .fromEither(decode[ExampleTransportEnvelope](pdJson)) .map(_.presentation_definition) - filters <- ZIO - .succeed(pd.input_descriptors.flatMap(_.constraints.fields.getOrElse(Nil))) - .map(_.flatMap(_.filter)) exit <- validator.validate(pd).exit } yield assert(exit)(failsWithA[JsonSchemaOptionNotSupported]) + }, + test("reject when path is not a valid json path") { + val pdJson = + """{ + | "presentation_definition": { + | "id": "32f54163-7166-48f1-93d8-ff217bdb0653", + | "input_descriptors": [ + | { + | "id": "wa_driver_license", + | "name": "Washington State Business License", + | "purpose": "We can only allow licensed Washington State business representatives into the WA Business Conference", + | "constraints": { + | "fields": [ + | { + | "path": ["$$"] + | } + | ] + | } + | } + | ] + | } + |} + """.stripMargin + + for { + validator <- ZIO.service[PresentationDefinitionValidator] + pd <- ZIO + .fromEither(decode[ExampleTransportEnvelope](pdJson)) + .map(_.presentation_definition) + exit <- validator.validate(pd).exit + } yield assert(exit)(failsWithA[InvalidFilterJsonPath]) } ) .provide(PresentationDefinitionValidatorImpl.layer) diff --git a/pollux/sql-doobie/src/main/resources/sql/pollux/V26__remove_subject_id_column_presentation_record.sql b/pollux/sql-doobie/src/main/resources/sql/pollux/V26__remove_subject_id_column_presentation_record.sql new file mode 100644 index 0000000000..31d7ad010c --- /dev/null +++ b/pollux/sql-doobie/src/main/resources/sql/pollux/V26__remove_subject_id_column_presentation_record.sql @@ -0,0 +1,4 @@ +-- presentation_records +-- Remove subject_id column +ALTER TABLE public.presentation_records + DROP COLUMN "subject_id"; \ No newline at end of file diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala index 1a4a962d3a..d91de29b62 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcPresentationRepository.scala @@ -184,7 +184,6 @@ class JdbcPresentationRepository( | connection_id, | schema_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, @@ -206,7 +205,6 @@ class JdbcPresentationRepository( | ${record.connectionId}, | ${record.schemaId}, | ${record.role}, - | ${record.subjectId}, | ${record.protocolState}, | ${record.credentialFormat}, | ${record.invitation}, @@ -244,7 +242,6 @@ class JdbcPresentationRepository( | schema_id, | connection_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, @@ -297,7 +294,6 @@ class JdbcPresentationRepository( | schema_id, | connection_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, @@ -347,7 +343,6 @@ class JdbcPresentationRepository( | schema_id, | connection_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, @@ -386,7 +381,6 @@ class JdbcPresentationRepository( | schema_id, | connection_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, @@ -423,7 +417,6 @@ class JdbcPresentationRepository( | schema_id, | connection_id, | role, - | subject_id, | protocol_state, | credential_format, | invitation, diff --git a/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala b/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala index 0019db7792..e464b5ab70 100644 --- a/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala +++ b/pollux/vc-jwt/src/main/scala/org/hyperledger/identus/pollux/vc/jwt/VerifiableCredentialPayload.scala @@ -252,7 +252,9 @@ object CredentialPayload { ("credentialStatus", w3cCredentialPayload.maybeCredentialStatus.asJson), ("refreshService", w3cCredentialPayload.maybeRefreshService.asJson), ("evidence", w3cCredentialPayload.maybeEvidence.asJson), - ("termsOfUse", w3cCredentialPayload.maybeTermsOfUse.asJson) + ("termsOfUse", w3cCredentialPayload.maybeTermsOfUse.asJson), + ("validFrom", w3cCredentialPayload.maybeValidFrom.asJson), + ("validUntil", w3cCredentialPayload.maybeValidUntil.asJson) ) .deepDropNullValues .dropEmptyValues @@ -268,7 +270,9 @@ object CredentialPayload { ("credentialStatus", jwtVc.maybeCredentialStatus.asJson), ("refreshService", jwtVc.maybeRefreshService.asJson), ("evidence", jwtVc.maybeEvidence.asJson), - ("termsOfUse", jwtVc.maybeTermsOfUse.asJson) + ("termsOfUse", jwtVc.maybeTermsOfUse.asJson), + ("validFrom", jwtVc.maybeValidFrom.asJson), + ("validUntil", jwtVc.maybeValidUntil.asJson) ) .deepDropNullValues .dropEmptyValues @@ -360,8 +364,8 @@ object CredentialPayload { issuer <- c.downField("issuer").as[String] issuanceDate <- c.downField("issuanceDate").as[Instant] maybeExpirationDate <- c.downField("expirationDate").as[Option[Instant]] - maybeValidFrom <- c.downField("maybeValidFrom").as[Option[Instant]] - maybeValidUntil <- c.downField("maybeValidUntil").as[Option[Instant]] + maybeValidFrom <- c.downField("validFrom").as[Option[Instant]] + maybeValidUntil <- c.downField("validUntil").as[Option[Instant]] maybeCredentialSchema <- c.downField("credentialSchema").as[Option[CredentialSchema]] credentialSubject <- c.downField("credentialSubject").as[Json] maybeCredentialStatus <- c.downField("credentialStatus").as[Option[CredentialStatus]] @@ -405,8 +409,8 @@ object CredentialPayload { maybeRefreshService <- c.downField("refreshService").as[Option[RefreshService]] maybeEvidence <- c.downField("evidence").as[Option[Json]] maybeTermsOfUse <- c.downField("termsOfUse").as[Option[Json]] - maybeValidFrom <- c.downField("maybeValidFrom").as[Option[Instant]] - maybeValidUntil <- c.downField("maybeValidUntil").as[Option[Instant]] + maybeValidFrom <- c.downField("validFrom").as[Option[Instant]] + maybeValidUntil <- c.downField("validUntil").as[Option[Instant]] } yield { JwtVc( `@context` = `@context`, @@ -751,12 +755,6 @@ object JwtCredential { .mapError(_.getMessage) } - def verifyDates(jwtPayload: JwtVerifiableCredentialPayload, leeway: TemporalAmount)(implicit - clock: Clock - ): Validation[String, Unit] = { - verifyDates(jwtPayload.jwt, leeway)(clock) - } - def verifyDates(jwt: JWT, leeway: TemporalAmount)(implicit clock: Clock): Validation[String, Unit] = { val decodeJWT = Validation diff --git a/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala b/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala index da506bbff2..3f05de0c35 100644 --- a/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala +++ b/pollux/vc-jwt/src/test/scala/org/hyperledger/identus/pollux/vc/jwt/JWTVerificationTest.scala @@ -9,11 +9,12 @@ import org.hyperledger.identus.castor.core.model.did.VerificationRelationship import org.hyperledger.identus.pollux.vc.jwt.CredentialPayload.Implicits.* import org.hyperledger.identus.shared.http.* import zio.* +import zio.prelude.Validation import zio.test.* import zio.test.Assertion.* import java.security.Security -import java.time.Instant +import java.time.{Clock, Instant, ZoneId} object JWTVerificationTest extends ZIOSpecDefault { @@ -62,7 +63,9 @@ object JWTVerificationTest extends ZIOSpecDefault { |""".stripMargin private def createJwtCredential(issuer: IssuerWithKey): JWT = { + val validFrom = Instant.parse("2010-01-05T00:00:00Z") // ISSUANCE DATE val jwtCredentialNbf = Instant.parse("2010-01-01T00:00:00Z") // ISSUANCE DATE + val validUntil = Instant.parse("2010-01-09T00:00:00Z") // EXPIRATION DATE val jwtCredentialExp = Instant.parse("2010-01-12T00:00:00Z") // EXPIRATION DATE val jwtCredentialPayload = JwtCredentialPayload( iss = issuer.issuer.did.value, @@ -76,8 +79,8 @@ object JWTVerificationTest extends ZIOSpecDefault { maybeRefreshService = None, maybeEvidence = None, maybeTermsOfUse = None, - maybeValidFrom = None, - maybeValidUntil = None + maybeValidFrom = Some(validFrom), + maybeValidUntil = Some(validUntil) ), nbf = jwtCredentialNbf, // ISSUANCE DATE aud = Set.empty, @@ -183,6 +186,42 @@ object JWTVerificationTest extends ZIOSpecDefault { ) ) }, + test("validate dates happy path") { + val issuer = createUser(DID("did:prism:issuer")) + val jwtCredential = createJwtCredential(issuer) + for { + validation <- ZIO.succeed( + JwtCredential + .verifyDates(jwtCredential, java.time.Duration.ZERO)( + Clock.fixed(Instant.parse("2010-01-08T00:00:00Z"), ZoneId.systemDefault()) + ) + ) + } yield assertTrue(validation.fold(_ => false, _ => true)) + }, + test("validate dates should fail given after valid until") { + val issuer = createUser(DID("did:prism:issuer")) + val jwtCredential = createJwtCredential(issuer) + for { + validation <- ZIO.succeed( + JwtCredential + .verifyDates(jwtCredential, java.time.Duration.ZERO)( + Clock.fixed(Instant.parse("2010-01-10T00:00:00Z"), ZoneId.systemDefault()) + ) + ) + } yield assertTrue(validation.fold(_ => true, _ => false)) + }, + test("validate dates should fail given before valid from") { + val issuer = createUser(DID("did:prism:issuer")) + val jwtCredential = createJwtCredential(issuer) + for { + validation <- ZIO.succeed( + JwtCredential + .verifyDates(jwtCredential, java.time.Duration.ZERO)( + Clock.fixed(Instant.parse("2010-01-02T00:00:00Z"), ZoneId.systemDefault()) + ) + ) + } yield assertTrue(validation.fold(_ => true, _ => false)) + }, test("validate PrismDID issued JWT VC using verification publicKeys") { val issuer = createUser(DID("did:prism:issuer")) val jwtCredential = createJwtCredential(issuer) diff --git a/shared/json/src/main/scala/org/hyperledger/identus/shared/json/JsonPath.scala b/shared/json/src/main/scala/org/hyperledger/identus/shared/json/JsonPath.scala new file mode 100644 index 0000000000..48770dd784 --- /dev/null +++ b/shared/json/src/main/scala/org/hyperledger/identus/shared/json/JsonPath.scala @@ -0,0 +1,53 @@ +package org.hyperledger.identus.shared.json + +import com.jayway.jsonpath.{InvalidPathException, JsonPath as JaywayJsonPath, PathNotFoundException} +import com.jayway.jsonpath.spi.json.JacksonJsonProvider +import org.hyperledger.identus.shared.models.{Failure, StatusCode} +import zio.* +import zio.json.* +import zio.json.ast.Json + +sealed trait JsonPathError extends Failure { + override def namespace: String = "JsonPathError" +} + +object JsonPathError { + final case class InvalidPathInput(msg: String) extends JsonPathError { + override def statusCode: StatusCode = StatusCode.BadRequest + override def userFacingMessage: String = s"The JsonPath input is not valid: $msg" + } + + final case class PathNotFound(path: String) extends JsonPathError { + override def statusCode: StatusCode = StatusCode.BadRequest + override def userFacingMessage: String = s"The json path '$path' cannot be found in a json" + } +} + +opaque type JsonPath = JaywayJsonPath + +object JsonPath { + def compile(path: String): IO[JsonPathError, JsonPath] = { + ZIO + .attempt(JaywayJsonPath.compile(path)) + .refineOrDie { + case e: IllegalArgumentException => JsonPathError.InvalidPathInput(e.getMessage()) + case e: InvalidPathException => JsonPathError.InvalidPathInput(e.getMessage()) + } + } + + extension (jsonPath: JsonPath) { + def read(json: Json): IO[JsonPathError, Json] = { + val jsonProvider = JacksonJsonProvider() + val document = JaywayJsonPath.parse(json.toString()) + for { + queriedObj <- ZIO + .attempt(document.read[java.lang.Object](jsonPath)) + .refineOrDie { case e: PathNotFoundException => + JsonPathError.PathNotFound(jsonPath.getPath()) + } + queriedJsonStr = jsonProvider.toJson(queriedObj) + queriedJson <- ZIO.fromEither(queriedJsonStr.fromJson[Json]).orDieWith(Exception(_)) + } yield queriedJson + } + } +} diff --git a/shared/json/src/test/scala/org/hyperledger/identus/shared/json/JsonPathSpec.scala b/shared/json/src/test/scala/org/hyperledger/identus/shared/json/JsonPathSpec.scala new file mode 100644 index 0000000000..5f4d41c612 --- /dev/null +++ b/shared/json/src/test/scala/org/hyperledger/identus/shared/json/JsonPathSpec.scala @@ -0,0 +1,111 @@ +package org.hyperledger.identus.shared.json + +import org.hyperledger.identus.shared.json.JsonPathError.{InvalidPathInput, PathNotFound} +import zio.* +import zio.json.* +import zio.json.ast.Json +import zio.test.* +import zio.test.Assertion.* + +object JsonPathSpec extends ZIOSpecDefault { + + override def spec = suite("JsonPathSpec")( + test("sucessfully compile a valid json path") { + val paths = Seq( + "$.store.book[*].author", + "$..author", + "$.store.*", + "$.store..price", + "$..book[2]", + "$..book[-1:]", + "$..book[0,1]", + "$..book[:2]", + "$..book[?(@.isbn)]", + "$..book[?(@.price<10)]", + "$..book[?(@.price==8.95)]", + "$..book[?(@.price<30 && @.category==\"fiction\")]", + "$..*", + "$['foo']['bar']" + ) + ZIO + .foreach(paths)(JsonPath.compile) + .as(assertCompletes) + }, + test("do not accept invalid json path") { + val paths = Seq( + "", + " ", + " $ ", + "$$", + "hello world", + ) + ZIO + .foreach(paths)(p => JsonPath.compile(p).flip) + .map { errors => + assert(errors)(forall(isSubtype[InvalidPathInput](anything))) + } + }, + test("query valid path inside json structure") { + val jsonStr = + """{ + | "vc": { + | "name": "alice", + | "age": 42, + | "degree": null, + | "pets": ["dog", "cat"], + | "isEmployed": false, + | "languages": {"english": "native", "chinese": "fluent"} + | } + |} + """.stripMargin + for { + json <- ZIO.fromEither(jsonStr.fromJson[Json]) + namePath <- JsonPath.compile("$.vc.name") + agePath <- JsonPath.compile("$.vc.age") + degreePath <- JsonPath.compile("$.vc.degree") + petPath <- JsonPath.compile("$.vc.pets") + firstPetPath <- JsonPath.compile("$.vc.pets[0]") + isEmployedPath <- JsonPath.compile("$.vc.isEmployed") + languagesPath <- JsonPath.compile("$.vc.languages") + name <- namePath.read(json) + age <- agePath.read(json) + degree <- degreePath.read(json) + pet <- petPath.read(json) + firstPet <- firstPetPath.read(json) + isEmployed <- isEmployedPath.read(json) + languages <- languagesPath.read(json) + } yield assert(name.asString)(isSome(equalTo("alice"))) + && assert(age.asNumber)(isSome(equalTo(Json.Num(42)))) + && assert(degree.asNull)(isSome(anything)) + && assert(pet.asArray)(isSome(hasSize((equalTo(2))))) + && assert(firstPet.asString)(isSome(equalTo("dog"))) + && assert(isEmployed.asBoolean)(isSome(isFalse)) + && assert(languages.asObject)(isSome(anything)) + }, + test("query invalid path inside json structure") { + val jsonStr = + """{ + | "vc": { + | "name": "alice", + | "pets": ["dog", "cat"] + | } + |} + """.stripMargin + for { + json <- ZIO.fromEither(jsonStr.fromJson[Json]) + nonExistingPath <- JsonPath.compile("$.vc2.name") + invalidTypeArrayPath <- JsonPath.compile("$.vc.name[0]") + outOfBoundArrayPath <- JsonPath.compile("$.vc.name[5]") + outOfBoundSlicePath <- JsonPath.compile("$.vc.name[1:4]") + exit1 <- nonExistingPath.read(json).exit + exit2 <- invalidTypeArrayPath.read(json).exit + exit3 <- outOfBoundArrayPath.read(json).exit + exit4 <- outOfBoundSlicePath.read(json).exit + } yield assert(exit1)(failsWithA[PathNotFound]) + && assert(exit2)(failsWithA[PathNotFound]) + && assert(exit3)(failsWithA[PathNotFound]) + && assert(exit4)(failsWithA[PathNotFound]) + } + ) + +} diff --git a/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/KeycloakTestContainerSupport.scala b/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/KeycloakTestContainerSupport.scala index 506d4673f4..34870de890 100644 --- a/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/KeycloakTestContainerSupport.scala +++ b/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/KeycloakTestContainerSupport.scala @@ -1,5 +1,6 @@ package org.hyperledger.identus.sharedtest.containers +import jakarta.ws.rs.NotFoundException import org.keycloak.admin.client.Keycloak import org.keycloak.representations.idm.{ ClientRepresentation, @@ -9,8 +10,6 @@ import org.keycloak.representations.idm.{ UserRepresentation } import zio.* -import zio.test.TestAspect.beforeAll -import zio.test.TestAspectAtLeastR import java.util.UUID import scala.jdk.CollectionConverters.* @@ -18,6 +17,7 @@ import scala.jdk.CollectionConverters.* type KeycloakAdminClient = Keycloak trait KeycloakTestContainerSupport { + protected val keycloakContainerLayer: TaskLayer[KeycloakContainerCustom] = KeycloakContainerCustom.layer @@ -50,11 +50,19 @@ trait KeycloakTestContainerSupport { protected def initializeClient = for { adminClient <- adminClientZIO - _ <- ZIO.attemptBlocking( - adminClient - .realms() - .create(realmRepresentation) - ) + _ <- ZIO + .attemptBlocking( + adminClient + .realm(realmName) + .remove() + ) + .catchSome { case _: NotFoundException => ZIO.unit } + _ <- ZIO + .attemptBlocking( + adminClient + .realms() + .create(realmRepresentation) + ) _ <- ZIO .attemptBlocking( adminClient @@ -64,24 +72,6 @@ trait KeycloakTestContainerSupport { ) } yield () - def bootstrapKeycloakRealm = adminClientZIO.flatMap(keycloak => - ZIO.attemptBlocking { - keycloak.realms().create(realmRepresentation) - keycloak.realm(realmName).clients().create(agentClientRepresentation) - () - } - ) - - def bootstrapKeycloakRealmAspect: TestAspectAtLeastR[KeycloakAdminClient] = { - val run = for { - _ <- ZIO.log("Bootstrapping the Keycloak realm...") - _ <- bootstrapKeycloakRealm - _ <- ZIO.log("Bootstrap finished") - } yield () - - beforeAll(run.orDie) - } - def createUser(username: String, password: String): RIO[KeycloakAdminClient, UserRepresentation] = val userRepresentation = { val creds = new CredentialRepresentation() diff --git a/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/VaultContainerCustom.scala b/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/VaultContainerCustom.scala index 9768c6828e..f5ff0bb4c8 100644 --- a/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/VaultContainerCustom.scala +++ b/shared/test/src/test/scala/org/hyperledger/identus/sharedtest/containers/VaultContainerCustom.scala @@ -1,6 +1,6 @@ package org.hyperledger.identus.sharedtest.containers -import com.dimafeng.testcontainers.{SingleContainer, VaultContainer} +import com.dimafeng.testcontainers.SingleContainer import org.testcontainers.utility.DockerImageName import org.testcontainers.vault.VaultContainer as JavaVaultContainer @@ -8,7 +8,6 @@ import org.testcontainers.vault.VaultContainer as JavaVaultContainer class VaultContainerCustom( dockerImageNameOverride: DockerImageName, vaultToken: Option[String] = None, - secrets: Option[VaultContainer.Secrets] = None, isOnGithubRunner: Boolean = false, useFileBackend: Boolean = false ) extends SingleContainer[JavaVaultContainer[?]] { @@ -41,9 +40,6 @@ class VaultContainerCustom( } if (vaultToken.isDefined) vaultContainer.withVaultToken(vaultToken.get) - secrets.foreach { x => - vaultContainer.withSecretInVault(x.path, x.firstSecret, x.secrets*) - } override val container: JavaVaultContainer[?] = { val con = vaultContainer