Skip to content

Commit

Permalink
More code
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioPinheiro committed May 7, 2024
1 parent 581deee commit 356d295
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class IssueControllerImpl(
issuingDID = issuingDID.asCanonical
)
} yield record
case SDJWT => // FIXME
case SDJWT =>
for {
issuingDID <- ZIO
.fromOption(request.issuingDID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,22 @@ class PresentProofControllerImpl(
},
options = request.options.map(x => Options(x.challenge, x.domain))
)
case CredentialFormat.SDJWT => ??? // TODO
case CredentialFormat.SDJWT =>
presentationService
.createSDJWTPresentationRecord(
pairwiseVerifierDID = didIdPair.myDID,
pairwiseProverDID = didIdPair.theirDid,
thid = DidCommID(),
connectionId = Some(request.connectionId.toString),
proofTypes = request.proofs.map { e =>
ProofType(
schema = e.schemaId,
requiredFields = None,
trustIssuers = Some(e.trustIssuers.map(DidId(_)))
)
},
options = request.options.map(x => Options(x.challenge, x.domain))
)
case CredentialFormat.AnonCreds =>
request.anoncredPresentationRequest match {
case Some(presentationRequest) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private class CredentialServiceImpl(
attachment: AttachmentDescriptor
) = for {
_ <- credentialFormat match
case CredentialFormat.JWT =>
case CredentialFormat.JWT | CredentialFormat.SDJWT =>
attachment.data match
case JsonData(json) =>
ZIO
Expand All @@ -409,12 +409,16 @@ private class CredentialServiceImpl(
CredentialServiceError
.UnexpectedError(s"Unexpected error parsing credential offer attachment: ${e.toString}")
)
case Base64(base64) => // TODO
ZIO.fail(
CredentialServiceError
.UnexpectedError(s"A Base64 attachment it's not yet implemented for credential offer")
)
case _ =>
ZIO.fail(
CredentialServiceError
.UnexpectedError(s"A JSON attachment is expected in the credential offer")
)
case CredentialFormat.SDJWT => ??? // FIXME
case CredentialFormat.AnonCreds =>
attachment.data match
case Base64(value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ object MockPresentationService extends Mock[PresentationService] {
PresentationError,
PresentationRecord
]
object CreateSDJWTPresentationRecord
extends Effect[
(DidId, DidId, DidCommID, Option[String], Seq[ProofType], Option[Options]),
PresentationError,
PresentationRecord
]

object CreateAnoncredPresentationRecord
extends Effect[
Expand Down Expand Up @@ -90,6 +96,19 @@ object MockPresentationService extends Mock[PresentationService] {
(pairwiseVerifierDID, pairwiseProverDID, thid, connectionId, proofTypes, options)
)

override def createSDJWTPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options],
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
proxy(
CreateSDJWTPresentationRecord,
(pairwiseVerifierDID, pairwiseProverDID, thid, connectionId, proofTypes, options)
)

override def createAnoncredPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ trait PresentationService {
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options],
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def createSDJWTPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options],
): ZIO[WalletAccessContext, PresentationError, PresentationRecord]

def createAnoncredPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private class PresentationServiceImpl(
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
maybeOptions: Option[org.hyperledger.identus.pollux.core.model.presentation.Options]
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options]
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] = {
createPresentationRecord(
pairwiseVerifierDID,
Expand All @@ -239,7 +239,26 @@ private class PresentationServiceImpl(
connectionId,
CredentialFormat.JWT,
proofTypes,
maybeOptions.map(options => Seq(toJWTAttachment(options))).getOrElse(Seq.empty)
options.map(o => Seq(toJWTAttachment(o))).getOrElse(Seq.empty)
)
}

override def createSDJWTPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options],
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] = {
createPresentationRecord(
pairwiseVerifierDID,
pairwiseProverDID,
thid,
connectionId,
CredentialFormat.SDJWT,
proofTypes,
options.map(o => Seq(toSDJWTAttachment(o))).getOrElse(Seq.empty)
)
}

Expand Down Expand Up @@ -1002,6 +1021,13 @@ private class PresentationServiceImpl(
)
}

private[this] def toSDJWTAttachment(options: Options): AttachmentDescriptor = {
AttachmentDescriptor.buildJsonAttachment(
payload = PresentationAttachment.build(Some(options)),
format = Some(PresentCredentialRequestFormat.SDJWT.name)
)
}

private[this] def toAnoncredAttachment(
presentationRequest: AnoncredPresentationRequestV1
): AttachmentDescriptor = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ class PresentationServiceNotifier(
)
)

override def createSDJWTPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
options: Option[org.hyperledger.identus.pollux.core.model.presentation.Options],
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
notifyOnSuccess(
svc.createSDJWTPresentationRecord(
pairwiseVerifierDID,
pairwiseProverDID,
thid,
connectionId,
proofTypes,
options
)
)

def createAnoncredPresentationRecord(
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
Expand Down

0 comments on commit 356d295

Please sign in to comment.