Skip to content

Commit

Permalink
fix(prism-agent): return relevant errors on offer creation (#754)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Voiturier <[email protected]>
  • Loading branch information
bvoiturier authored Oct 12, 2023
1 parent 17def3f commit d36533f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ trait ControllerHelper {
}

protected def getPairwiseDIDs(
connectionId: String
connectionId: UUID

This comment has been minimized.

Copy link
@yshyn-iohk

yshyn-iohk Aug 26, 2024

Member

if would be nice if @FabioPinheiro review this PR.
AFAK, according to some spec, the connectionId should be a string

): ZIO[WalletAccessContext & ConnectionService, ConnectionServiceError, DidIdPair] = {
val lookupId = UUID.fromString(connectionId)
for {
connectionService <- ZIO.service[ConnectionService]
maybeConnection <- connectionService.getConnectionRecord(lookupId)
maybeConnection <- connectionService.getConnectionRecord(connectionId)
didIdPair <- maybeConnection match
case Some(connRecord: ConnectionRecord) =>
extractDidIdPairFromValidConnection(connRecord) match {
case Some(didIdPair: DidIdPair) => ZIO.succeed(didIdPair)
case None =>
ZIO.fail(ConnectionServiceError.UnexpectedError("Invalid connection record state for operation"))
}
case _ => ZIO.fail(ConnectionServiceError.RecordIdNotFound(lookupId))
case _ => ZIO.fail(ConnectionServiceError.RecordIdNotFound(connectionId))
} yield didIdPair
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class IssueControllerImpl(
for {
issuingDID <- ZIO
.fromOption(request.issuingDID)
.flatMap(extractPrismDIDFromString)
.mapError(_ => ErrorResponse.badRequest(detail = Some("Missing request parameter: issuingDID")))
.flatMap(extractPrismDIDFromString)
_ <- validatePrismDID(issuingDID, allowUnpublished = true)
record <- credentialService
.createJWTIssueCredentialRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final case class CreateIssueCredentialRecordRequest(
issuingDID: Option[String],
@description(annotations.connectionId.description)
@encodedExample(annotations.connectionId.example)
connectionId: String
connectionId: UUID
)

object CreateIssueCredentialRecordRequest {
Expand Down Expand Up @@ -112,10 +112,10 @@ object CreateIssueCredentialRecordRequest {
)

object connectionId
extends Annotation[String](
extends Annotation[UUID](
description =
"The unique identifier of a DIDComm connection that already exists between the issuer and the holder, and that will be used to execute the issue credential protocol.",
example = "null"
example = UUID.fromString("d9569cec-c81e-4779-aa86-0d5994d82676")
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PresentProofControllerImpl(
pairwiseVerifierDID = didIdPair.myDID,
pairwiseProverDID = didIdPair.theirDid,
thid = DidCommID(),
connectionId = Some(request.connectionId),
connectionId = Some(request.connectionId.toString),
proofTypes = request.proofs.map { e =>
ProofType(
schema = e.schemaId, // TODO rename field to schemaId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object PresentProofEndpoints {
)
)
.out(jsonBody[PresentationStatus])
.errorOut(basicFailuresAndForbidden)
.errorOut(basicFailureAndNotFoundAndForbidden)

val getAllPresentations: Endpoint[
ApiKeyCredentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import sttp.tapir.{Schema, Validator}
import sttp.tapir.Schema.annotations.{description, encodedExample}
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}

import java.util.UUID

final case class RequestPresentationInput(
@description(annotations.connectionId.description)
@encodedExample(annotations.connectionId.example)
connectionId: String,
connectionId: UUID,
@description(annotations.options.description)
@encodedExample(annotations.options.example)
options: Option[Options] = None,
Expand All @@ -24,9 +26,9 @@ final case class RequestPresentationInput(
object RequestPresentationInput {
object annotations {
object connectionId
extends Annotation[String](
extends Annotation[UUID](
description = "The unique identifier of an established connection between the verifier and the prover.",
example = "bc528dc8-69f1-4c5a-a508-5f8019047900"
example = UUID.fromString("bc528dc8-69f1-4c5a-a508-5f8019047900")
)
object options
extends Annotation[Option[Options]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import zio.json.ast.Json
import zio.json.ast.Json.*
import zio.test.*

import java.util.UUID

trait IssueControllerTestTools extends PostgresTestContainerSupport {
self: ZIOSpecDefault =>

Expand Down Expand Up @@ -143,7 +145,7 @@ trait IssueGen {
val gValidityPeriod: Gen[Any, Double] = Gen.double
val gAutomaticIssuance: Gen[Any, Boolean] = Gen.boolean
val gIssuingDID: Gen[Any, String] = Gen.alphaNumericStringBounded(5, 20) // TODO Make a DID generator
val gConnectionId: Gen[Any, String] = Gen.alphaNumericStringBounded(5, 20)
val gConnectionId: Gen[Any, UUID] = Gen.uuid

val claims = Json.Obj(
"key1" -> Json.Str("value1"),
Expand Down

0 comments on commit d36533f

Please sign in to comment.