• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8645457575

11 Apr 2024 10:44AM UTC coverage: 31.344% (-0.1%) from 31.453%
8645457575

push

web-flow
docs(adr): ATL-6599 update ADR based on first implementation experience (#952)

Signed-off-by: Benjamin Voiturier <benjamin.voiturier@iohk.io>
Signed-off-by: bvoiturier <benjamin.voiturier@iohk.io>
Co-authored-by: Pete Vielhaber <peter.vielhaber@iohk.io>

4465 of 14245 relevant lines covered (31.34%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.47
/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationServiceNotifier.scala
1
package io.iohk.atala.pollux.core.service
2

3
import io.iohk.atala.event.notification.{Event, EventNotificationService}
4
import io.iohk.atala.mercury.model.DidId
5
import io.iohk.atala.mercury.protocol.presentproof.{Presentation, ProofType, ProposePresentation, RequestPresentation}
6
import io.iohk.atala.pollux.anoncreds.AnoncredPresentation
7
import io.iohk.atala.pollux.core.model.error.PresentationError
8
import io.iohk.atala.pollux.core.model.presentation.Options
9
import io.iohk.atala.pollux.core.model.{DidCommID, PresentationRecord}
10
import io.iohk.atala.pollux.core.service.serdes.{AnoncredCredentialProofsV1, AnoncredPresentationRequestV1}
11
import io.iohk.atala.pollux.vc.jwt.{Issuer, PresentationPayload, W3cCredentialPayload}
12
import io.iohk.atala.shared.models.WalletAccessContext
13
import zio.{IO, URLayer, ZIO, ZLayer}
14

15
import java.time.Instant
16
import java.util.UUID
17

18
class PresentationServiceNotifier(
19
    svc: PresentationService,
20
    eventNotificationService: EventNotificationService
21
) extends PresentationService {
22

23
  private val presentationUpdatedEvent = "PresentationUpdated"
24

1✔
25
  override def createJwtPresentationRecord(
26
      pairwiseVerifierDID: DidId,
27
      pairwiseProverDID: DidId,
28
      thid: DidCommID,
29
      connectionId: Option[String],
30
      proofTypes: Seq[ProofType],
31
      options: Option[Options],
32
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
33
    notifyOnSuccess(
1✔
34
      svc.createJwtPresentationRecord(
35
        pairwiseVerifierDID,
36
        pairwiseProverDID,
37
        thid,
38
        connectionId,
39
        proofTypes,
40
        options
41
      )
42
    )
43

×
44
  def createAnoncredPresentationRecord(
45
      pairwiseVerifierDID: DidId,
46
      pairwiseProverDID: DidId,
47
      thid: DidCommID,
48
      connectionId: Option[String],
49
      presentationRequest: AnoncredPresentationRequestV1
50
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
51
    notifyOnSuccess(
×
52
      svc.createAnoncredPresentationRecord(
53
        pairwiseVerifierDID,
54
        pairwiseProverDID,
55
        thid,
56
        connectionId,
57
        presentationRequest
58
      )
59
    )
60

1✔
61
  override def markRequestPresentationSent(
62
      recordId: DidCommID
63
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
64
    notifyOnSuccess(svc.markRequestPresentationSent(recordId))
65

1✔
66
  override def receiveRequestPresentation(
67
      connectionId: Option[String],
68
      request: RequestPresentation
69
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
70
    notifyOnSuccess(svc.receiveRequestPresentation(connectionId, request))
71

×
72
  override def markRequestPresentationRejected(
73
      recordId: DidCommID
74
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
75
    notifyOnSuccess(svc.markRequestPresentationRejected(recordId))
76

1✔
77
  override def acceptRequestPresentation(
78
      recordId: DidCommID,
79
      credentialsToUse: Seq[String]
80
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
81
    notifyOnSuccess(svc.acceptRequestPresentation(recordId, credentialsToUse))
82

×
83
  override def acceptAnoncredRequestPresentation(
84
      recordId: DidCommID,
85
      credentialsToUse: AnoncredCredentialProofsV1
×
86
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] = notifyOnSuccess(
×
87
    svc.acceptAnoncredRequestPresentation(recordId, credentialsToUse)
88
  )
89

1✔
90
  override def rejectRequestPresentation(
91
      recordId: DidCommID
92
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
93
    notifyOnSuccess(svc.rejectRequestPresentation(recordId))
94

1✔
95
  override def markPresentationGenerated(
96
      recordId: DidCommID,
97
      presentation: Presentation
98
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
99
    notifyOnSuccess(svc.markPresentationGenerated(recordId, presentation))
100

1✔
101
  override def markPresentationSent(
102
      recordId: DidCommID
103
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
104
    notifyOnSuccess(svc.markPresentationSent(recordId))
105

1✔
106
  override def receivePresentation(
107
      presentation: Presentation
108
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
109
    notifyOnSuccess(svc.receivePresentation(presentation))
110

1✔
111
  override def markPresentationVerified(
112
      recordId: DidCommID
113
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
114
    notifyOnSuccess(svc.markPresentationVerified(recordId))
115

1✔
116
  override def markPresentationVerificationFailed(
117
      recordId: DidCommID
118
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
119
    notifyOnSuccess(svc.markPresentationVerificationFailed(recordId))
120

×
121
  override def verifyAnoncredPresentation(
122
      presentation: Presentation,
123
      requestPresentation: RequestPresentation,
124
      recordId: DidCommID
125
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
126
    notifyOnSuccess(
×
127
      svc.verifyAnoncredPresentation(presentation, requestPresentation, recordId)
128
    )
129

1✔
130
  override def acceptPresentation(
131
      recordId: DidCommID
132
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
133
    notifyOnSuccess(svc.acceptPresentation(recordId))
134

1✔
135
  override def rejectPresentation(
136
      recordId: DidCommID
137
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
1✔
138
    notifyOnSuccess(svc.rejectPresentation(recordId))
139

1✔
140
  private[this] def notifyOnSuccess[R](effect: ZIO[R, PresentationError, PresentationRecord]) =
1✔
141
    for {
142
      record <- effect
×
143
      _ <- notify(record)
144
    } yield record
145

1✔
146
  private[this] def notify(record: PresentationRecord) = {
1✔
147
    val result = for {
×
148
      walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId)
×
149
      producer <- eventNotificationService.producer[PresentationRecord]("Presentation")
×
150
      _ <- producer.send(Event(presentationUpdatedEvent, record, walletId))
151
    } yield ()
×
152
    result.catchAll(e => ZIO.logError(s"Notification service error: $e"))
153
  }
154

×
155
  override def extractIdFromCredential(credential: W3cCredentialPayload): Option[UUID] =
×
156
    svc.extractIdFromCredential(credential)
157

×
158
  override def getPresentationRecords(
159
      ignoreWithZeroRetries: Boolean
160
  ): ZIO[WalletAccessContext, PresentationError, Seq[PresentationRecord]] =
×
161
    svc.getPresentationRecords(ignoreWithZeroRetries)
162

×
163
  override def createJwtPresentationPayloadFromRecord(
164
      record: DidCommID,
165
      issuer: Issuer,
166
      issuanceDate: Instant
167
  ): ZIO[WalletAccessContext, PresentationError, PresentationPayload] =
×
168
    svc.createJwtPresentationPayloadFromRecord(record, issuer, issuanceDate)
169

×
170
  override def createAnoncredPresentationPayloadFromRecord(
171
      record: DidCommID,
172
      anoncredCredentialProof: AnoncredCredentialProofsV1,
173
      issuanceDate: Instant
174
  ): ZIO[WalletAccessContext, PresentationError, AnoncredPresentation] =
×
175
    svc.createAnoncredPresentationPayloadFromRecord(record, anoncredCredentialProof, issuanceDate)
176

×
177
  override def createAnoncredPresentation(
178
      requestPresentation: RequestPresentation,
179
      recordId: DidCommID,
180
      anoncredCredentialProof: AnoncredCredentialProofsV1,
181
      issuanceDate: Instant
182
  ): ZIO[WalletAccessContext, PresentationError, Presentation] =
×
183
    svc.createAnoncredPresentation(requestPresentation, recordId, anoncredCredentialProof, issuanceDate)
184

×
185
  override def getPresentationRecordsByStates(
186
      ignoreWithZeroRetries: Boolean,
187
      limit: Int,
188
      state: PresentationRecord.ProtocolState*
189
  ): ZIO[WalletAccessContext, PresentationError, Seq[PresentationRecord]] =
×
190
    svc.getPresentationRecordsByStates(ignoreWithZeroRetries, limit, state: _*)
191

×
192
  override def getPresentationRecordsByStatesForAllWallets(
193
      ignoreWithZeroRetries: Boolean,
194
      limit: Int,
195
      state: PresentationRecord.ProtocolState*
196
  ): IO[PresentationError, Seq[PresentationRecord]] =
×
197
    svc.getPresentationRecordsByStatesForAllWallets(ignoreWithZeroRetries, limit, state: _*)
198

×
199
  override def getPresentationRecord(
200
      recordId: DidCommID
201
  ): ZIO[WalletAccessContext, PresentationError, Option[PresentationRecord]] =
×
202
    svc.getPresentationRecord(recordId)
203

×
204
  override def getPresentationRecordByThreadId(
205
      thid: DidCommID
206
  ): ZIO[WalletAccessContext, PresentationError, Option[PresentationRecord]] =
×
207
    svc.getPresentationRecordByThreadId(thid)
208

×
209
  override def receiveProposePresentation(
210
      request: ProposePresentation
211
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
212
    svc.receiveProposePresentation((request))
213

×
214
  override def acceptProposePresentation(
215
      recordId: DidCommID
216
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
217
    svc.acceptPresentation(recordId)
218

×
219
  override def markProposePresentationSent(
220
      recordId: DidCommID
221
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
222
    svc.markProposePresentationSent(recordId)
223

×
224
  override def markPresentationAccepted(
225
      recordId: DidCommID
226
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
227
    svc.markPresentationAccepted(recordId)
228

×
229
  override def markPresentationRejected(
230
      recordId: DidCommID
231
  ): ZIO[WalletAccessContext, PresentationError, PresentationRecord] =
×
232
    svc.markPresentationRejected(recordId)
233

×
234
  override def reportProcessingFailure(
235
      recordId: DidCommID,
236
      failReason: Option[_root_.java.lang.String]
×
237
  ): ZIO[WalletAccessContext, PresentationError, Unit] = svc.reportProcessingFailure(recordId, failReason)
238
}
239

240
object PresentationServiceNotifier {
241
  val layer: URLayer[EventNotificationService & PresentationService, PresentationService] =
1✔
242
    ZLayer.fromFunction(PresentationServiceNotifier(_, _))
243
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc