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

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

16 Feb 2024 02:56PM UTC coverage: 31.695% (+0.1%) from 31.59%
7932317734

Pull #795

shotexa
Merge branch 'main' into epic/ATL-4095-revocation-for-jwt-creds
Pull Request #795: Epic - Revocation for JWT credentials (tmp title)

124 of 410 new or added lines in 25 files covered. (30.24%)

428 existing lines in 108 files now uncovered.

4199 of 13248 relevant lines covered (31.7%)

0.32 hits per line

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

52.0
/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/schema/CredentialDefinition.scala
1
package io.iohk.atala.pollux.core.model.schema
2

3
import io.iohk.atala.pollux.core.model.error.CredentialSchemaError
4
import io.iohk.atala.pollux.core.model.error.CredentialSchemaError.*
5
import zio.*
6
import zio.json.*
7

8
import java.time.OffsetDateTime
9
import java.time.ZoneOffset
10
import java.util.UUID
11

12
type Definition = zio.json.ast.Json
13
type CorrectnessProof = zio.json.ast.Json
14

15
/** @param guid
16
  *   Globally unique identifier of the CredentialDefinition object. It's calculated as a UUID from a string that
17
  *   contains the following fields: author, id, and version.
18
  * @param id
19
  *   Locally unique identifier of the CredentialDefinition. It is a UUID. When the version of the credential definition
20
  *   changes, this `id` keeps the same value.
21
  * @param name
22
  *   Human-readable name of the CredentialDefinition.
23
  * @param description
24
  *   Human-readable description of the CredentialDefinition.
25
  * @param version
26
  *   Version of the CredentialDefinition.
27
  * @param author
28
  *   DID of the CredentialDefinition's author.
29
  * @param authored
30
  *   Datetime stamp of the schema creation.
31
  * @param tags
32
  *   Tags of the CredentialDefinition, used for convenient lookup.
33
  * @param schemaId
34
  *   Schema ID that identifies the schema associated with this definition.
35
  * @param definition
36
  *   Definition object that represents the actual definition of the credential.
37
  * @param keyCorrectnessProof
38
  *   A proof that validates the correctness of the key within the context of the credential definition.
39
  * @param signatureType
40
  *   Signature type used in the CredentialDefinition.
41
  * @param supportRevocation
42
  *   Boolean flag indicating whether revocation is supported for this CredentialDefinition.
43
  */
44
case class CredentialDefinition(
45
    guid: UUID,
46
    id: UUID,
47
    name: String,
48
    description: String,
49
    version: String,
50
    author: String,
51
    authored: OffsetDateTime,
52
    tag: String,
53
    schemaId: String,
54
    definitionJsonSchemaId: String,
55
    definition: Definition,
56
    keyCorrectnessProofJsonSchemaId: String,
57
    keyCorrectnessProof: CorrectnessProof,
58
    signatureType: String,
59
    supportRevocation: Boolean
60
) {
1✔
61
  def longId = CredentialDefinition.makeLongId(author, id, version)
62
}
63

64
object CredentialDefinition {
65

1✔
66
  def makeLongId(author: String, id: UUID, version: String) =
1✔
67
    s"$author/${id.toString}?version=${version}"
68

1✔
69
  def makeGUID(author: String, id: UUID, version: String) =
1✔
70
    UUID.nameUUIDFromBytes(makeLongId(author, id, version).getBytes)
71

1✔
72
  def make(
73
      in: Input,
74
      definitionSchemaId: String,
75
      definition: Definition,
76
      proofSchemaId: String,
77
      proof: CorrectnessProof
78
  ): ZIO[Any, Nothing, CredentialDefinition] = {
1✔
79
    for {
×
80
      id <- zio.Random.nextUUID
1✔
81
      cs <- make(id, in, definitionSchemaId, definition, proofSchemaId, proof)
82
    } yield cs
83
  }
84

1✔
85
  def make(
86
      id: UUID,
87
      in: Input,
88
      definitionSchemaId: String,
89
      definition: Definition,
90
      keyCorrectnessProofSchemaId: String,
91
      keyCorrectnessProof: CorrectnessProof
92
  ): ZIO[Any, Nothing, CredentialDefinition] = {
×
93
    for {
×
94
      ts <- zio.Clock.currentDateTime.map(
×
95
        _.atZoneSameInstant(ZoneOffset.UTC).toOffsetDateTime
96
      )
×
97
      guid = makeGUID(in.author, id, in.version)
98
    } yield CredentialDefinition(
99
      guid = guid,
100
      id = id,
101
      name = in.name,
102
      description = in.description,
103
      version = in.version,
104
      schemaId = in.schemaId,
UNCOV
105
      author = in.author,
×
106
      authored = in.authored.map(_.atZoneSameInstant(ZoneOffset.UTC).toOffsetDateTime).getOrElse(ts),
107
      tag = in.tag,
1✔
108
      definitionJsonSchemaId = definitionSchemaId,
1✔
109
      definition = definition,
1✔
110
      keyCorrectnessProofJsonSchemaId = keyCorrectnessProofSchemaId,
1✔
111
      keyCorrectnessProof = keyCorrectnessProof,
112
      signatureType = in.signatureType,
113
      supportRevocation = in.supportRevocation
114
    )
115
  }
116

117
  val defaultAgentDid = "did:prism:agent"
118

119
  case class Input(
120
      name: String,
121
      description: String,
122
      version: String,
123
      authored: Option[OffsetDateTime],
124
      tag: String,
125
      author: String = defaultAgentDid,
126
      schemaId: String,
127
      signatureType: String,
128
      supportRevocation: Boolean
129
  )
130

UNCOV
131
  case class Filter(
×
UNCOV
132
      author: Option[String] = None,
×
UNCOV
133
      name: Option[String] = None,
×
UNCOV
134
      version: Option[String] = None,
×
135
      tag: Option[String] = None
136
  )
137

138
  case class FilteredEntries(entries: Seq[CredentialDefinition], count: Long, totalCount: Long)
139

×
140
  given JsonEncoder[CredentialDefinition] = DeriveJsonEncoder.gen[CredentialDefinition]
141

×
142
  given JsonDecoder[CredentialDefinition] = DeriveJsonDecoder.gen[CredentialDefinition]
143
}
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