Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prism-agent): return relevant errors on offer creation #754

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
): 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
Loading