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

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

29 Mar 2024 08:58AM UTC coverage: 31.807% (+0.4%) from 31.453%
8479182462

Pull #952

web-flow
Update docs/decisions/20240116-use-zio-failures-and-defects-effectively.md

Co-authored-by: Pete Vielhaber <peter.vielhaber@iohk.io>
Signed-off-by: bvoiturier <benjamin.voiturier@iohk.io>
Pull Request #952: docs(adr): ATL-6599 update ADR based on first implementation experience

4515 of 14195 relevant lines covered (31.81%)

0.32 hits per line

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

77.78
/pollux/lib/vc-jwt/src/main/scala/io/iohk/atala/pollux/vc/jwt/MultiBaseString.scala
1
package io.iohk.atala.pollux.vc.jwt
2

3
import io.circe.*
4
import io.iohk.atala.shared.utils.Base64Utils
5
import scodec.bits.ByteVector
6

7
case class MultiBaseString(header: MultiBaseString.Header, data: String) {
1✔
8
  def toMultiBaseString: String = s"${header.value}$data"
9

1✔
10
  def getBytes: Either[String, Array[Byte]] = header match {
1✔
11
    case MultiBaseString.Header.Base64Url => Right(Base64Utils.decodeURL(data))
1✔
12
    case MultiBaseString.Header.Base58Btc =>
1✔
13
      ByteVector.fromBase58(data).map(_.toArray).toRight(s"Invalid base58 string: $data")
14
  }
15
}
16

17
object MultiBaseString {
18
  enum Header(val value: Char) {
19
    case Base64Url extends Header('u')
20
    case Base58Btc extends Header('z')
21
  }
22

1✔
23
  def fromString(str: String): Either[String, MultiBaseString] = {
1✔
24
    val header = Header.fromValue(str.head)
25
    header match {
1✔
26
      case Some(value) => Right(MultiBaseString(value, str.tail))
×
27
      case None        => Left(s"$str - is not a multi base string")
28
    }
29
  }
30

31
  object Header {
1✔
32
    def fromValue(value: Char): Option[Header] = value match {
1✔
33
      case 'u' => Some(Header.Base64Url)
1✔
34
      case 'z' => Some(Header.Base58Btc)
×
35
      case _   => None
36
    }
37
  }
38

39
  given multiBaseStringEncoder: Encoder[MultiBaseString] = (multiBaseString: MultiBaseString) =>
1✔
40
    Json.fromString(multiBaseString.toMultiBaseString)
41

42
  given multiBaseStringDecoder: Decoder[MultiBaseString] = (c: HCursor) =>
×
43
    Decoder.decodeString(c).flatMap { str =>
1✔
44
      val header = MultiBaseString.Header.fromValue(str.head)
45
      header match {
1✔
46
        case Some(value) => Right(MultiBaseString(value, str.tail))
×
47
        case None        => Left(DecodingFailure(s"no enum value matched for $str", List(CursorOp.Field(str))))
48
      }
49
    }
50
}
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